ThePiHut / rgbxmastree

Code examples for the RGB Xmas Tree
90 stars 38 forks source link

Hardware schematic to stack Rpi Hats #30

Open phcuriel opened 1 year ago

phcuriel commented 1 year ago

More of a request: Is there a hardware schematic documented to what pins are being used and what LED location to what pin?. To determine if can stack another shield/hat. I wanted to see if i could stack another Pi hat "PiFace-Digital2" that has two relays. That hat uses hardware SPI and wanted to use one of the Relays to control another xmas decoration while using the RGB xmas tree.

tommycusick commented 1 year ago

I was curious about the same thing, and it turns out that you can see the traces on the board itself if you look closely. Here's what I see for the GPIO pinout:

Those SPI pins are also referenced in tree.py's constructor for RGBXmasTree: https://github.com/ThePiHut/rgbxmastree/blob/24fe82ecc0f746bfd88944ebab1e3b3dee16fcf1/tree.py#L38-L40

Notably, I don't see a reference to a chip select pin for RGBXmasTree, so I'm not sure if it'll play nicely with other devices on the same bus. You may need to experiment further on that front, or else find a way for your other devices to use a different SPI bus.

phcuriel commented 1 year ago

Yeah, I had initially mistakenly assumed that the LEDS were controlled by different Rpi IO pins. Seems like the RGB LEDs have an embedded SPI chip and only use (Data, Clock, Power, Gnd). I remembered I had used a version of these before called Neopixel LEDs. Somehow they are still individually addressable but they don't use the full SPI implementation since they don't use the “select” or “miso” pin of SPI.

Looking at the GPIOZero library called in the initiation it said if pins are not defined they declare the default pin assignments. For MISO, SELECT this would conflict with the other piFace hat I wanted to stack that does have hardwired and make use of the “select” pin 8 https://gpiozero.readthedocs.io/en/stable/api_spi.html#

I replaced two lines of code on tree.py to declare MISO and SELECT to pins 23 and 24 even though it's not used by rgbxmastree just so it does not interfere with the other hat. So they are assigned but floating since not connected to anything. def __init__(self, pixels=25, brightness=0.5, mosi_pin=12, clock_pin=25, miso_pin=23, select_pin=24, *args, **kwargs): super(RGBXmasTree, self).__init__(mosi_pin=mosi_pin, clock_pin=clock_pin, miso_pin=miso_pin, select_pin=select_pin, *args, **kwargs)

After some trial and error I got the rgbxmastree and the piFace hat working . Reading GPIOZero documentation it seems that it can only run software or hardware implementation of SPI but not both at the same time. For my application it's not a big limitation. I'm running randomsparkles.py. and the other hat piFace drives another decoration with a chime that plays for 1 min every hour. While it's playing the rgbxmastree stops sparkling. After chime ends then rgbxmastree resumes sparkling.

The only thing I had to do on the piFace code was to make sure to de-initialize the SPI instance at the end of script so that when it ends randomandomsparkles.py continues.