Hello,
I recently reviewed our secret cupboard of Pico hardware and noticed a bunch of Pimoroni parts that need to be used again. I have:
I’m running into some problems with the Wireless Pack and LCD, as they both share GP18 and use SPI 0 by default. Is there a way to resolve this conflict without rewiring? I’m willing to lose the microSD functionality on the Wireless Pack but would like to retain WiFi capability. I know I could get a Pico W, but I’ prefer using the old Wireless Pack and fill up all the slots on the Breakout Garden and Omnibus Packs :-)
I implemented all components in CircuitPython using various Adafruit libraries.
Any suggestions would be greatly appreciated.
Regards,
Pawel
GP18 is the clock pin of SPI0. Sharing the SPI-bus is normal and no pin-conflict. But you must make sure that the non-SPI pins don’t conflict. Since the LCD does not plug directly into the Pico, you should be free to choose suitable pins. The defaults given on the shop-page won’t work though, since e.g. GP16 for DC (data/command) of the LCD is also used by SPI0-RX on the wireless pack.
@bablokb thank you for a prompt response. It makes sense. However, just these few lines of code below give me ValueError: GP18 in use
.
SD_CS_PIN = board.GP22
ESP32_CS = board.GP7
ESP32_READY = board.GP10
ESP32_RESET = board.GP11
SPI_SCK = board.GP18
SPI_MOSI = board.GP19
SPI_MISO = board.GP16
LED_PIN = board.LED
LCD_CS = board.GP17
LCD_DC = board.GP16
LCD_BL = board.GP20
# SPI and ESP Setup
# *** Crashes on the line below ***
spi = busio.SPI(SPI_SCK, MOSI=SPI_MOSI, MISO=SPI_MISO)
esp32_cs = DigitalInOut(ESP32_CS)
esp32_ready = DigitalInOut(ESP32_READY)
esp32_reset = DigitalInOut(ESP32_RESET)
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
# LCD Display (shared SPI bus)
displayio.release_displays()
tft_dc = DigitalInOut(LCD_DC)
tft_cs = DigitalInOut(LCD_CS)
tft_bl = DigitalInOut(LCD_BL)
tft_bl.direction = Direction.OUTPUT
tft_bl.value = True
If this is your complete code, the GP18 is in use from a previous run and you need a hard reset. All those lines before spi = ...
do not claim any of the GPs.
I also have these kind of errors. The reason is that at the end of a program (due to a failure, CTRL-C or whatever) the ressources are not freed. The solution to this is the atexit
module of CircuitPython. With that module, you can register a method that runs as the name implies during exiting the VM. Something like
def my_exit(spi):
""" release displays and free SPI-bus """
print("atexit: deinit ressources")
displayio.release_displays()
spi.deinit()
# --- main program ------
...
spi = ...
atexit.register(my_exit,spi)
...
Absolutely! Last night, I implemented a function to free the pins when rerunning the code without a hard reset, and just as you mentioned, the issue with GP18 has been resolved. The main challenge lies with GP16, which is necessary for getting both the LCD and the Wireless Pack to work together. I attempted to switch between the devices on shared SPI, but GP16 wasn’t being released properly by CircuitPython’s ESP_SPIcontrol
.
It seems my only option now is a hardware modification, which feels a bit excessive for what was intended to be a small, fun project. I examined the Wireless Pack board, and I could potentially cut GP16 off from the header and reroute it to GP12.
Please let me know if you think there is a software solution to share GP16. I can easily switch to MicroPython. C is also an option, but that would turn it into a much larger project rather than the fun little one I intended :-)
GP16 is SPI0-RX (old term MISO) and you cannot reroute it to GP12, which is SPI1-RX). GP0 or GP4 are alternatives for SPI0-RX. But you might have other conflicts with these pins, so check first.
Sharing in software would be a big mess: you would constantly have to setup and free the SPI-ressources for the LCD and the wifi-pack (including connecting again and so on). Sounds very complicated and error-prone.
I think I would just use wires for the LCD instead of the Breakout Garden. Not as neat, but it should work because you are free to route your connections.