Max7219 LED Control

Discussion about Z-Uno product. Visit http://z-uno.z-wave.me for more details.
Post Reply
andyd
Posts: 8
Joined: 24 Mar 2018 07:24

Max7219 LED Control

Post by andyd »

Has anyone used a MAX7219-based LED 7 segment display? I have one that works with Arduino, but I can't get it to work with Z-Uno.

I first tried including the LEDControl library, but it fails on compilation saying it can't find LEDControl.h (along the lines of "missing file"). I do have the library installed, but it doesn't seem to work for the Z-Uno board. It also wants things like avr/pgmspace.h which doesn't appear to be available for Z-Uno.

I then tried copying all the relevant code directly into the sketch, including looking up things like ShiftOut. It seems to happily initialise the display, but as soon as it gets to writing figures on the display I either get "8.8.8.8.8.8.8.8." or gibberish or nothing. Even when I try to write to just one digit it doesn't seem happy.

I did see somewhere that it was used to working with 5V on the data channels, so that might be the issue.

Any help welcome, even pointers where to start looking. If it definitely doesn't work, that would also be nice to know!
User avatar
PoltoS
Posts: 7565
Joined: 26 Jan 2011 19:36

Re: Max7219 LED Control

Post by PoltoS »

First of all, according to the datasheet MAX7219 requires 3.5 V minimum on the input a s high voltage. Z-Uno maximum is 3.3 V. You need a transistor to drive it from Z-Uno with 5 V input.

Then you need to make sure that your code was correctly ported to Z-Uno chip. The timing is in range of nanoseconds, so switching pins is not fast enough. You need to use same approach as we use for WS2812 LEDs - we use SPI to drive it at the speed they require. Or if the the datagram is small enough (<1ms), you can still use Z-Uno FastPins.
andyd
Posts: 8
Joined: 24 Mar 2018 07:24

Re: Max7219 LED Control

Post by andyd »

Thanks -the library does use SPI, so it is most likely the voltage. I haven't got time to do much more at this point, but will try it with transistors once I get some time.
andyd
Posts: 8
Joined: 24 Mar 2018 07:24

Re: Max7219 LED Control

Post by andyd »

It does work with transistors. I have had some problems with reliability, but I suspect that's something to do with my breadboard rather than the display.

The transistors I used (because they were available) were TIP31CG. I used the standard Z-Uno CLK (#0) and MOSI pins (#2) plus pin 9 as the CS. All three went through transistors: the Z-Uno pin to the Base, the 5V signal to the Collector, and the Emitter going to the display.

I basically cut and pasted the LEDControl library in, then fiddled it a little (whenever the compiler failed!). The compiler didn't like using Progmem, and didn't like that the initial character table array didn't have its size declared. It should be possible to turn this into a library for anyone willing to.

The attached zipfile contains the sketch - it is pretty simple, it just sets each digit to "8", then turns on the decimal point, then backtracks. I've also tweaked the number printing function to print numbers in the millions, should you need to - I changed the printnumber function to take a long rather than int, so you may need type conversion.

Note that the vast majority of this is based on the work of Eberhard Fahle and his LedControl library - thanks!
Attachments
LEDCheck.zip
(3.63 KiB) Downloaded 233 times
andyd
Posts: 8
Joined: 24 Mar 2018 07:24

Re: Max7219 LED Control

Post by andyd »

Spoke too soon. Works perfectly when plugged in to the USB port of my PC. Produces random gibberish when plugged into any other USB power supply, or even a 5V power supply connected directly to the 5V pin. No idea why - any ideas?
User avatar
PoltoS
Posts: 7565
Joined: 26 Jan 2011 19:36

Re: Max7219 LED Control

Post by PoltoS »

Please have a look on this post: https://forum.z-wave.me/viewtopic.php?f ... =10#p73147

Don't power it from a PC or "smart" power supply. You can also remove data cables from the USB cable as a workaround.
andyd
Posts: 8
Joined: 24 Mar 2018 07:24

Re: Max7219 LED Control

Post by andyd »

Haven't been able to work on this for some time, trying to get back into it. I think you misunderstood what happened. It works perfectly if plugged into a PC using a data cable, but NOT on a normal power supply, no matter how I supply power (USB or direct to one of the pins). That seems to be the opposite to the post you referred me to.
Post Reply