I’m wanting to control an array of 64 LEDs using a MAX7221. I used this Arduino tutorial page as a starting point: https://playground.arduino.cc/Main/MAX72XXHardware
I’m using Python code running on a Raspberry Pi Zero to communicate with the 7221 using the Pi’s SPI connections.
I’ve started with two LEDs to test. I have successfully managed to switch these LEDs on and off, but I’ve found a couple of things that are either problems or are me misunderstanding something!
First of all, when I power up the 7221, any LEDs that were switched on when the chip was last powered down, will still be set to be on. Reading the data sheet, it says “On initial power-up, all control registers are reset, the display is blanked, and the MAX7219/MAX7221 enters shutdown mode”. My initial understanding of that is that all LED registers would be reset, so when taking the chip out of reset everything should still be off, but now I think I'm wrong. Anyone know which is correct?
Secondly, I'm using the spidev python module: https://pypi.python.org/pypi/spidev for interfacing with SPI devices.
I’ve tried to combine addressing both LEDs using a single spi.xfer command, to make the code more compact, but it hasn’t worked properly. I can switch off two LEDs (addressed as 0x01,0x00 and 0x02,0x00) one at a time like so:
However if I try and do it like this:
Code: Select all
off1 = [0x01,0x00] #First LED address to switch off spi.xfer2(off1) # Transfer this over SPI time.sleep(0.1) off2 = [0x02,0x00] #Second LED address to switch off spi.xfer2(off2)# Transfer this over SPI time.sleep(0.1)
Only one LED (0x01,0x00) actually switches off. Can anyone explain why that doesn't work?
Code: Select all
alloff = [0x02,0x00,0x01,0x00] spi.xfer2(alloff)
Thanks in advance for any help!
p.s. I'm using some 7221's I bought off ebay from China, at a fraction the price of a regular store. I have seen people on other forums saying there are conterfeit/dodgy batches floating about that can cause glitches, but I don't think I have that problem...probably