Circuitpython Raspberry pi pico w SPI Invalid pins

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
CR34T0R
 
Posts: 24
Joined: Wed Aug 31, 2022 8:58 am

Circuitpython Raspberry pi pico w SPI Invalid pins

Post by CR34T0R »

Hello,

I've been trying to setup a Pimoroni Pico Inky Pack using a Pico W and Circuitpython because I want to display temperature and humidity from an SHT40.

When I do:

Code: Select all

spi = busio.SPI(board.GP19, MISO=board.GP16)
I get:
ValueError: Invalid pins
As far as I know these are the correct pins for SPI, I checked it so many times, can someone help?

Thanks.

User avatar
mikeysklar
 
Posts: 13484
Joined: Mon Aug 01, 2016 8:10 pm

Re: Circuitpython Raspberry pi pico w SPI Invalid pins

Post by mikeysklar »

The SHT40 would be an I2C device. I think you know this, but your post reads either way.

viewtopic.php?p=951678#p951678

Your code should probably look like this for the SHT40 i2c:

Code: Select all

i2c = busio.I2C(scl=board.GP1, sda=board.GP0)
The Pico W has two default SPIs, but one is taken by the wireless chip. Try this one for SPI display:

Code: Select all

spi = busio.SPI(clock=board.GP2, MOSI=board.GP3, MISO=board.GP4)

User avatar
CR34T0R
 
Posts: 24
Joined: Wed Aug 31, 2022 8:58 am

Re: Circuitpython Raspberry pi pico w SPI Invalid pins

Post by CR34T0R »

I don't have any issue with the SHT40, I can make it work no problem.

My problem is trying to make the pimoroni inky pack work on circuitpython:
https://shop.pimoroni.com/products/pico ... 4626051155

The pins use by this product are:
Pin 16: Button A
Pin 17: Button B
Pin 18: Ground (can be shared)
Pin 19: Button C
Pin 21: MISO (Microcontroller In, Sensor Out) (SPI interface)
Pin 22: Inky CS (e-ink display control)
Pin 24: SCLK (SPI clock) (SPI interface)
Pin 25: MOSI (Microcontroller Out, Sensor In) (SPI interface)
Pin 26: Inky D/C (e-ink display control)
Pin 27: Inky Res (e-ink display control)
Pin 30: Reset
Pin 31: Inky Busy (e-ink display control)
Pin 36: 3v3 (3.3v power supply)
So my code looks like this:

Code: Select all

spi = busio.SPI(board.GP19, MISO=board.GP16)
epd_cs = board.GP17
epd_dc = board.GP20
epd_reset = board.GP21
epd_busy = board.GP26

Reading my post, I guess I should have been more clear about that, sorry for the confusion.

User avatar
mikeysklar
 
Posts: 13484
Joined: Mon Aug 01, 2016 8:10 pm

Re: Circuitpython Raspberry pi pico w SPI Invalid pins

Post by mikeysklar »

You can add the clock argument too. Might as well define each pin.

Code: Select all

spi = busio.SPI(clock=board.GP18, MOSI=board.GP19, MISO=board.GP16) 
Can you post a photo of your connections to the Pico W? The GP numbers are different than the pin numbers so it is possible to mix up the physical connections.

User avatar
CR34T0R
 
Posts: 24
Joined: Wed Aug 31, 2022 8:58 am

Re: Circuitpython Raspberry pi pico w SPI Invalid pins

Post by CR34T0R »

mikeysklar wrote: Sun Dec 11, 2022 9:48 pm You can add the clock argument too. Might as well define each pin.

Code: Select all

spi = busio.SPI(clock=board.GP18, MOSI=board.GP19, MISO=board.GP16) 
Can you post a photo of your connections to the Pico W? The GP numbers are different than the pin numbers so it is possible to mix up the physical connections.
OMG just pasted your code and it worked, you have no idea how long I've been stuck on that :)

It is weird to me that the guides I've read don't mention adding clock and I believe I skimmed through adafruit circuipython SPI articles too... Weird that just doing that worked, isn't it?

Thank you!

Edit: it seems like something isn't working properly, will try revisiting the rest of the code and trying a few stuff then I'll come here and post pictures and the full code, brb

Edit 2: Fault was on my code. Just following this article:
https://learn.adafruit.com/adafruit-ein ... ython-code
But with:

Code: Select all

adafruit_uc8151d.UC8151D
And your SPI line worked on the pimoroni pico inky pack.

Thank you again!

User avatar
mikeysklar
 
Posts: 13484
Joined: Mon Aug 01, 2016 8:10 pm

Re: Circuitpython Raspberry pi pico w SPI Invalid pins

Post by mikeysklar »

Can you paste you working example code in? It might be helpful to others.

User avatar
CR34T0R
 
Posts: 24
Joined: Wed Aug 31, 2022 8:58 am

Re: Circuitpython Raspberry pi pico w SPI Invalid pins

Post by CR34T0R »

mikeysklar wrote: Mon Dec 12, 2022 8:41 pm Can you paste you working example code in? It might be helpful to others.
Sure, here you go!

Code: Select all

from time import sleep
import busio
import board
import adafruit_sht4x
i2c = busio.I2C(board.GP27, board.GP26)
sht = adafruit_sht4x.SHT4x(i2c)
print("Found SHT4x with serial number", hex(sht.serial_number))
sht.mode = adafruit_sht4x.Mode.NOHEAT_HIGHPRECISION
print("Current mode is: ", adafruit_sht4x.Mode.string[sht.mode])

import displayio
import terminalio
from adafruit_display_text import label
import adafruit_uc8151d

displayio.release_displays()

# inky
spi = busio.SPI(clock=board.GP18, MOSI=board.GP19, MISO=board.GP16)
epd_cs = board.GP17
epd_dc = board.GP20
epd_reset = board.GP21
epd_busy = board.GP26

# Create the displayio connection to the display pins
display_bus = displayio.FourWire(
    spi, command=epd_dc, chip_select=epd_cs, reset=epd_reset, baudrate=1000000
)
sleep(1)  # Wait a bit

display = adafruit_uc8151d.UC8151D(
    display_bus,
    width=296,
    height=128,
    rotation=270,
    black_bits_inverted=False,
    color_bits_inverted=False,
    grayscale=True,
    refresh_time=1,
)

# Create a display group for our screen objects
g = displayio.Group()

BLACK = 0x000000
WHITE = 0xFFFFFF
RED = 0xFF0000
FOREGROUND_COLOR = RED
BACKGROUND_COLOR = WHITE

# Set a background
background_bitmap = displayio.Bitmap(296, 128, 1)
# Map colors in a palette
palette = displayio.Palette(1)
palette[0] = BACKGROUND_COLOR

# Create a Tilegrid with the background and put in the displayio group
t = displayio.TileGrid(background_bitmap, pixel_shader=palette)
g.append(t)

# Draw simple text using the built-in font into a displayio group
temperature_group = displayio.Group(scale=2, x=20, y=40)
temperature_label = label.Label(terminalio.FONT, text="%", color=FOREGROUND_COLOR)
temperature_group.append(temperature_label)  # Add this text to the text group
g.append(temperature_group)

humidity_group = displayio.Group(scale=2, x=20, y=80)
humidity_label = label.Label(terminalio.FONT, text="C", color=FOREGROUND_COLOR)
humidity_group.append(humidity_label)  # Add this text to the text group
g.append(humidity_group)

while True:
    temperature, relative_humidity = sht.measurements
    temperature_label.text = f"{temperature:0.1f}C"
    humidity_label.text = f"{relative_humidity:0.1f}%"
    display.show(g)
    display.refresh()
    print('refreshed')
    sleep(180)

User avatar
mikeysklar
 
Posts: 13484
Joined: Mon Aug 01, 2016 8:10 pm

Re: Circuitpython Raspberry pi pico w SPI Invalid pins

Post by mikeysklar »

thank you.

Locked
Please be positive and constructive with your questions and comments.

Return to “General Project help”