McKendrigo
Posts: 2
Joined: Sun Mar 11, 2018 3:25 pm

MAX7221 LED array driver - teething problems!

Sun Mar 11, 2018 4:48 pm

Hi,

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:

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)
However if I try and do it like this:

Code: Select all

alloff = [0x02,0x00,0x01,0x00]
spi.xfer2(alloff)
Only one LED (0x01,0x00) actually switches off. Can anyone explain why that doesn't work?

Thanks in advance for any help! :D

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 :roll:

User avatar
FTrevorGowen
Forum Moderator
Forum Moderator
Posts: 4562
Joined: Mon Mar 04, 2013 6:12 pm
Location: Bristol, U.K.
Contact: Website

Re: MAX7221 LED array driver - teething problems!

Mon Mar 12, 2018 7:28 pm

McKendrigo wrote:
Sun Mar 11, 2018 4:48 pm
...
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?
...
I haven't played with the 7221 but have some experience of the 7219. Recently I've been re-visiting my 'C' demo code for cascaded/daisy-chained 7219 driven 8x8 matrix displays: http://www.cpmspectrepi.uk/raspberry_pi ... odule.html
My displays are normally** powered from 5V with level-shifters on the associated SPI GPIO's:
http://www.cpmspectrepi.uk/raspberry_pi ... sembly_Etc.
I don't recall what happened in my previous tests (c2014) but, AFAICT they start up (as the Pi etc. is switched on) with all leds off but, as the Pi completes it's boot sequence, there appears to be some "SPI activity" that leads to spurious "full-on" matrix displays. The 8x8x2 display is driven by SPI0 whereas the 8x8x8 is driven by SPI1 with different "spurious" behaviour. Given that the 7219 (not sure about the 7221) doesn't handle the SPI /CE correctly (it's treated as a simple /LoaD) that may be part of the "problem". So by "On initial power-up" do you power up the display circuit separately from the Pi (after the Pi has booted) or, like me, power everything up together (in which case you may just be seeing a "variant" of what I've observed)?
Trev.
** The 8x8x2 module, originally designed for the early Pi's with the 26w GPIO header, may be running off 3.3V. It's also "cascaded right-to-left" cf. "left-to-right" for the 8x8x4 module.
Still running Raspbian Jessie on some older Pi's (an A, B1, B2, B+, P2B, 3xP0, P0W) but Stretch on my P3B+, P3B, B+, A+ and a B2. See: https://www.cpmspectrepi.uk/raspberry_pi/raspiidx.htm

McKendrigo
Posts: 2
Joined: Sun Mar 11, 2018 3:25 pm

Re: MAX7221 LED array driver - teething problems!

Tue Mar 13, 2018 5:04 pm

Hi Trev,

Thanks a lot for your response.
by "On initial power-up" do you power up the display circuit separately from the Pi (after the Pi has booted) or, like me, power everything up together (in which case you may just be seeing a "variant" of what I've observed)?
I have done both. Usually I power everything up at the same time, but I have also tried completely disconnecting the 7221 from the Pi, and reconnecting without rebooting the Pi. In both cases, the 7221 registers that control the Digit/Segment pins seem to retain their "memory", suggesting that they are not reset when the 7221 powers up.

Based on that, I would guess that it's not a problem of "spurious" SPI activity as the Pi boots up, though I hadn't really thought about that as a possible banana skin so it's good you mention it in case it causes some other problems!

I'm going to do some more digging over the coming week, will post back here if I learn anything.

User avatar
FTrevorGowen
Forum Moderator
Forum Moderator
Posts: 4562
Joined: Mon Mar 04, 2013 6:12 pm
Location: Bristol, U.K.
Contact: Website

Re: MAX7221 LED array driver - teething problems!

Tue Mar 13, 2018 7:48 pm

I've just had a quick re-read of the datasheet - one of the differences between the 7221 and the 7219 is that the 7221 does handle the SPI /CE signal correctly ie. no data is clocked in if /CE is high. In which case any "spurious" SPI behaviour on boot-up may well be different to my recent observations: For my cascaded displays that on SPI0 starts with both matrices on, subsequently the second one blanks, meanwhile that with 4 matrices on SPI1 starts off blank eventually ending up with all 4 matrices on, this happens after the SPI0 "events".
Trev.
Still running Raspbian Jessie on some older Pi's (an A, B1, B2, B+, P2B, 3xP0, P0W) but Stretch on my P3B+, P3B, B+, A+ and a B2. See: https://www.cpmspectrepi.uk/raspberry_pi/raspiidx.htm

Return to “Other projects”

Who is online

Users browsing this forum: No registered users and 9 guests