Pirate Audio: SPI puzzle: Multiple SPI devices possible on a Pi?

Hello gurus,
I’m building my little one a mini boombox with a Pirate Audio at the center of it. It’s still a heap of wires (and the case needs design updates as I learn), yet it’s moving along well. I’m able to successfully test all of the components of this project separately like playing audio (super fun as a Spotify device yet not project goal), draw to the screen with Python PIL, scan RFID “cartridges” that will be used to trigger sound and read a volume value from a potentiometer via a connected ADC. Super fun!

I could use an extra brain as I figure out SPI surrounding the Pirate Audio display and my RFID reader (RFID-RC522). They are trying to use the same pins and I’m not sure if they can co-exist in the way or not as I catch up on SPI. If I activate the display, my RFID reader no longer reads, so I know so far that they are conflicting. As an alternative to SPI, I learned that the RFID-RC522 can also use I2C, which would pair well with my volume readings, yet enabling this is rather odd (not ideal as I ponder a tutorial for others and future memory).

Would you have ideas on how to get these two devices to play nice with each other? Here’s the RFID library I’m using that has a few options for switching things around. I was able to remove one pin already to avoid conflicting with the Pirate Audio Y button (I’m just reading uids and was able to skip this) and move another pin to not conflict with the amp enable pin:
st7789-python/examples/shapes.py at master · pimoroni/st7789-python (github.com)

Also because I’m a visual person, here’s a pretty chart that describes potential conflicts and where I’m connected now. This based on a Pirate Audio pinout chart I found here:

Here are the settings I’m currently using when enabling the display:

self.st7789 = ST7789(
    rotation=self.rotation,  # Display the right way up on Pirate Audio
    port=0,       # SPI port
    cs=1,         # SPI port Chip-select channel
    dc=9,         # BCM pin used for data/command
    backlight=13,
    spi_speed_hz=self.spi_speed_mhz * 1000 * 1000
)

Here’s what enabling the RFID reader currently looks like (disable IRQ, BCM pin mode enabled in init as it’s enabled in main script, moved RST pin, see README here):

rdr = RFID(pin_irq=None, pin_mode=GPIO.BCM, pin_rst=37)

Thanks a ton for helping me untangle my mind in advance. I truly appreciate the feedback. ❤️

You can have multiple devices on an SPI bus, as long as each device uses a different Chip Select Pin.
SPI at Raspberry Pi GPIO Pinout

This is my crib sheet for SPI on a Pi

SPI0
GPIO 7, Pin 26, CE1
GPIO 8, Pin 24, CE0
GPIO 9, Pin 21, MISO
GPIO 10, Pin 19, MOSI
GPIO 11, Pin 23, SCLK

SPI1
GPIO 16, Pin 36, CE2
GPIO 17, Pin 11, CE1
GPIO 18, Pin 12, CE0
GPIO 19, Pin 35, MISO
GPIO 20, Pin 38, MOSI
GPIO 21, Pin 40, SCLK

/boot/config.txt

dtparam=spi=on

dtoverlay=spi1-1cs #1 chip select
dtoverlay=spi1-2cs #2 chip select
dtoverlay=spi1-3cs #3 chip select

SCLK - Serial ClocK
CE - Chip Enable (often called Chip Select)
MOSI - Master Out Slave In
MISO - Master In Slave Out
MOMI - Master Out Master In

1 Like

I think you have the display config wrong, port=1 is SPI 1. I’m pretty sure it uses SPI 0.

import ST7789

SPI_SPEED_MHZ = 80


st7789 = ST7789(
    port=0,
    cs=1,
    dc=9,
    backlight=13,
    rotation=90,
    spi_speed_hz=SPI_SPEED_MHZ * 1000 * 1000
)
1 Like

You’re right @alphanumeric . That was some last-minute thrashing before I decided help was needed (will correct post).

Nice! 🤩 Thanks for this feedback @alphanumeric . This helps a TON. I’ll give this a shot today and let you know how it goes!

1 Like

It seems like SP1 may interfere with Pirate Audio I2S audio signals. It’s good to know it’s an option though (brain grows)! I’ll dig a bit more and also look into RFID hardware alternatives (including that I2C conversion of RFID reader, also advertises UART). More updates soon.

update: one alternative I’m looking into:
gassajor000/pn532pi: Python interface for ndef communication using PN532 chip on raspberry pi (github.com)

I think the core problem is that Pimoroni misuses the MISO-pin for LCD Data/Command. The RFID does data-transfer from device to host and needs this pin. The Pi has hardware-SPI and I think there is no way to move this pin to some other place.

I stumbled across this problem already a while ago when I tried to attach the Pirate-Audio hat to a Pico. The LCD and I2S work fine, but I could not add a SD-card to the SPI-bus for the same reason.

Usually the hardware from Pimoroni is of high quality, but here I just don’t understand why they used a reserved pin instead of choosing one of the many other free pins that the Pi has.

Yeah, it’s GPIO 19, Pin 35, MISO. It’s also use by the Pirate Audio for i2s. Bummer. :(
Pirate Audio Line Out at Raspberry Pi GPIO Pinout

I2S is only possible on GPIO18/GPIO19. And that is multiplexed with SPI1. That is just how it is. I haven’t seen a HAT that actually uses SPI1. So you usually have it for yourself, well, unless you also need I2S.

1 Like

Thanks for the feedback @alphanumeric and @bablokb . At the moment I’m playing with this reader (arrived much faster than expected!). It seems straight forward and I’m able to detect the I2C address so far. After running into errors when running the examples, I found this (may or may not be related):

The Raspberry Pi 3.3v regulator does not provide enough current to drive the PN532 chip. If you try to run the PN532 off your Raspberry Pi it will reset randomly and may not respond to commands. Instead you will need another power source (3.3v) to power the PN532. Some people have been able to run the PN532 off of the 5V rail of the raspberry pi but this is not the recommended way of powering it.

Hmm… I wonder if I’ll need a 5V → 3.3V converter from the battery power for this. I’m starting to cram a lot into this little boombox. I’ll give it a break and resume tomorrow. :)

You could use the TLV62569 (Adafruit 4711, fixed 3V3 output) or a MINI-360 based on a MP2307 (variable output voltage, with a fiddly screw, very small and very cheap).