MAX7219 7-segment displays/Mega 2560

Hi - sorry, from what I can see, this is a well-trodden topic. I've read what I can to find out if I'm doing this right on both this and the arduino forums, but I'm running out of ideas. Basically the displays are completely unreliable, and drop out or show garbage regularly. Some displays are better that others, but others will only work for 30 seconds before going blank.

In my current setup, I'm trying to run a homemade Boeing 737 autopilot panel. "Behind the scenes" this is 2 arduino (Mega 2560) boards running a number of switches and LEDs (all switches just route an arduino pin to ground, and LEDs each run through 100ohm resistors and then to ground), as well as 4 x Max7219 blue 7-seg display boards. I must have bought over 20 of these max7219 boards from various suppliers on ebay and amazon, but I cannot get anything to stay reliable and I'm tearing my hair out. I have a reasonable if not great electronics background, and I'm a software developer by trade so I know my way around the arduino software side.

On the software side, this is supposed to be using "Mobiflight" which handles flight-sim interaction and code on the arduino to interact with the displays, but I've tried swapping out for my own code in the arduino editor with no real change, so I think this is hardware/electronics related.

Firstly I'm limiting this to a discussion about one of the arduinos for simpilicity as I've taken the other and it's associated bits entirely out of this and still have the problem. I've also removed the switches/LEDs so this is really entirely a 7-segment display related query.

The 7segment displays are all powered in parallel from a 6v, 2.1amp mains DC supply (I tried various 5v supplies, but up'd to 6v to see if that helped with any voltage drops). The ground from that also goes to the arduino ground (i.e. yes, I've read the forums). As these were never reliable, I've barely ever attempted to daisy chain these, so at the moment all 4 7-seg displays have their data lines (DIN, CS and CLK) fed directly from dedicated arduino pins.

Here's my wiring diagram: https://i.ibb.co/ydT3SqY/Blank-diagram.jpg

I tried writing some simple arduino code which initialises the boards and then sends '11111111', '22222222','33333333' etc to each display every second. I then swapped in and out lots of the displays (like I say, I have a pile of them...) to see if I could get a reliable set. Even with what I thought was a reasonably beefy DC supply, you can see a drop in reliability if I add displays (going from 1 up to 4). I don't think its the voltage of the arduino data lines as I set up another arduino as a primitive oscilloscope and the voltages looked good (and I even managed to decode the wire format and check it was sending the right signals - go me!).

I would write this method of running displays off as totally unreliable, but I can't help thinking that many people seem to have built things with these boards, so I'm still assuming it will work, but I'm clearly missing something. 4 x 7-segment displays can't be beyond the wit of man surely?!

This is my quick arduino sketch for testing the displays, though I'm not sure if it helps:


#include <DS3231.h>           // import library from rinkydink.com

// define pins attached to MAX7219 (and also see notes above)

// Heading
//#define MAX7219_DIN           29
//#define MAX7219_CS            27
//#define MAX7219_CLK           25

// Altitude
#define MAX7219_DIN           41
#define MAX7219_CS            39
#define MAX7219_CLK           37

//                 DIN  CS  CLK    
int altitude  [] = {  41, 39,  37 };
int heading   [] = {  29, 27,  25 };
int crs_mach  [] = {  31, 33,  35 };
int vertspeed [] = {  47, 45,  43 };

//#define MAX7219_DIN           11
//#define MAX7219_CS            12
//#define MAX7219_CLK           13

// enumerate the MAX7219 registers
// See MAX7219 Datasheet, Table 2, page 7
enum {  MAX7219_REG_DECODE    = 0x09,  
        MAX7219_REG_INTENSITY = 0x0A,
        MAX7219_REG_SCANLIMIT = 0x0B,
        MAX7219_REG_SHUTDOWN  = 0x0C,
        MAX7219_REG_DISPTEST  = 0x0F };

// enumerate the SHUTDOWN modes
// See MAX7219 Datasheet, Table 3, page 7
enum  { OFF = 0,  
        ON  = 1 };

const byte DP = 0b10000000;  
const byte C  = 0b01001110;  
const byte F  = 0b01000111;


// create an instance of the DS3231 called 'rtc', 
// and specify the hardware interface PINS

// ... setup code here, to run once
void setup()  
{
    // initialize the serial port:
    Serial.begin(115200);           // initialize serial communication
    Serial.println("max7219_7segment_date_time_temp");

    // define type of pin
    setupDisplay(altitude);
    setupDisplay(heading);
    setupDisplay(crs_mach);
    setupDisplay(vertspeed);

    // reset the MAX2719 display
    resetDisplay(altitude);                 
    resetDisplay(heading);     
    resetDisplay(crs_mach);
    resetDisplay(vertspeed);
}

void setupDisplay(int device[]) {
    pinMode(device[0], OUTPUT);   // serial data-in
    pinMode(device[1], OUTPUT);    // chip-select, active low    
    pinMode(device[2], OUTPUT);   // serial clock
    digitalWrite(device[1], HIGH); 
}

void loop()  
{
    displayString(altitude,  "11111111");
    displayString(heading,   "22222222");
    displayString(crs_mach,  "33333333");
    displayString(vertspeed, "44444444");
    delay(1000);
    displayString(altitude,  "22222222");
    displayString(heading,   "33333333");
    displayString(crs_mach,  "44444444");
    displayString(vertspeed, "11111111");
    delay(1000);
    displayString(altitude,  "33333333");
    displayString(heading,   "44444444");
    displayString(crs_mach,  "11111111");
    displayString(vertspeed, "22222222");
    delay(1000);
    displayString(altitude,  "44444444");
    displayString(heading,   "11111111");
    displayString(crs_mach,  "22222222");
    displayString(vertspeed, "33333333");
    delay(1000);
}


// ... write a value into a max7219 register 
// See MAX7219 Datasheet, Table 1, page 6
void set_register(int device[], byte reg, byte value)  
{
    digitalWrite(device[1], LOW);
    shiftOut(device[0], device[2], MSBFIRST, reg);
    shiftOut(device[0], device[2], MSBFIRST, value);
    digitalWrite(device[1], HIGH);
}


// ... reset the max7219 chip
void resetDisplay(int device[])  
{
    set_register(device, MAX7219_REG_SHUTDOWN, OFF);   // turn off display
    set_register(device, MAX7219_REG_DISPTEST, OFF);   // turn off test mode
    set_register(device, MAX7219_REG_INTENSITY, 0x0D); // display intensity
}


// ... display the DATE on the 7-segment display
void displayString(int device[], String dateString)  
{
    set_register(device, MAX7219_REG_SHUTDOWN, OFF);  // turn off display
    set_register(device, MAX7219_REG_SCANLIMIT, 7);   // scan limit 8 digits
    set_register(device, MAX7219_REG_DECODE, 0b11111111); // decode all digits

    set_register(device, 1, dateString.charAt(7) | DP);
    set_register(device, 2, dateString.charAt(6) | DP);
    set_register(device, 3, dateString.charAt(5) | DP);
    set_register(device, 4, dateString.charAt(4) | DP);
    set_register(device, 5, dateString.charAt(3) | DP); // plus decimal point
    set_register(device, 6, dateString.charAt(2) | DP);
    set_register(device, 7, dateString.charAt(1) | DP);
    set_register(device, 8, dateString.charAt(0) | DP);

    set_register(device, MAX7219_REG_SHUTDOWN, ON);   // Turn on display
}

Hi, @pmasters
Welcome to the forum.
Thanks for using code tags. :+1: :+1:
Your schematic.

Thanks.. Tom.. :smiley: :+1: :coffee: :australia: :santa:

1 Like

I have about 15 different MAX7219 displays in different configuration, all most probably with faked/counterfeit ICs, all are working as intended.

When I daisy chain them, I just don't use the "VCC out" from one module to the next "VCC in", as the powerline has an protection/reverse diode and the voltage drop of 0,7 is to much for the next display.

you could try to use HW-SPI and put the modules on different CS pins. If you need a HW SPI library, you could check my Noiasca LedControl.

If you have problems with your wiring - please show real pictures of your wiring, not just a schematic ...

Thanks noiasca,

As I said, I'm not daisy chaining because I'm struggling to make them reliable regardless. I'm aware of the voltage drop from the diode (which was another reason I thought I'd try with a 6v DC input to see if I could compensate for that).

It's interesting/confirming what you say about being able to run lots of them with no issues. I know people are doing this, so it's just a bit maddening that I can't get these working. Like I say, I bought quite a few now from different places, and this feels like its not necessarily the boards.

Whilst I know enough to be dangerous about electronics, the subtleties are what get me, and this feels like a bit of that. I don't know if I'm dealing with interference or some kind of grounding issue here? I'm still using dupont connectors at the moment (which I know is not ideal), but I'm reticent to move to soldered connections on something which isn't vaguely reliable as that just makes it harder to prove/swap things. If anyone has any ideas on how to simplify this setup to it's bare minimums and help me prove out a working setup, I'm all ears!

Thanks, Pete

Yeah, I'm not sure how I can easily get you a picture of the wiring because its mixed into with a load of other bits. I appreciate that that of course may be the issue too of course.

Here's a photo of what I have but it won't do much good for you guys I know - in wiring terms I know its pretty bad to look at :blush:, but most of it is the switch + led wires (which at least work fine). I'm clearly not proud of the wiring, but just to point out a few things - the grey wires are some of the 3x data lines running to the 7-segs, and there's a random DC plug in the middle of the picture as my latest attempt to try and push clear power to the displays

To that end, if I get time over the next few days, I'm going to try building a second copy of this setup which is just breadboards and an arduino that isn't tied into this wiring mess, because it'll be easier to debug. Anyway, I've included a photo below to show you what I mean. I've also linked a video I made showing what the 7seg displays are doing.

Video showing the intermittent displays

Thanks everyone for the support too by the way, I really appreciate it!

IMG_3086

to the other question (which I missed just now, sorry!) - I've not tried HW SPI yet. I guess the main thing here is that I'd ultimately like to go back to mobiflight, so I'm not really looking to develop my own code for this. I've been assuming this is a hardware issue as I said, but if I get some time over the next few days (Christmas and all that) then I'll see if that changes anything.

Do I have to note that there is a big difference between a "switch connects to ground" and bus lines?

If I were you I would try the modules on a spare controller using short wires and check if either the modules or the sketch are buggy.

Thanks Noiasca,

I've managed to track down the problem now actually. I spent about 3hrs this morning taking the whole thing to bits, and gradually adding displays and wires back in. The first test was using the arduino power (5v) and the 3 data lines (i.e. all 5 lines run to the arduino, which is fine for a single display and was my simplest test), which worked. I used this to test each display by swapping them over. I found a few bad ones, so that was worth doing. I then switched to external power, which allowed me to add more displays (as I said before, all power is in parallel, with a 0v line running to the arduino gnd line as per schematic).

The main problem seems to be that 6v DC supply. I swapped that for a 12v one running direct into a 5v regulator (the regulator needs >7V) and then checked it with the multimeter to verify. It seems the displays are very power-sensitive and 6v is too much. I had tried the 5v regulator before, but I think I'd missed it's input requirements so maybe it didn't have enough current when under load (the displays definitely need their current according to a number of forums I've read). Anyway, I set this up with 5v and things started to work. I built it up gradually and found a "data cable" (triple cable I'd made up which goes to the arduino as I treat power as a separate set of wires) which didn't work properly, so I don't think that was helping.

Anyway, long story short, I think we're all good now. Thank you very much everyone for your help, I really appreciate it. I had seen problems before and thought that by providing a touch more power it might help - I'd read that the diode was known to drop the voltage and thought see if compensating for that helped. Ah well, all is well that ends well :).

Have a great Christmas y'all and thanks again for your help.

Peter

If anyone finds this post in the future, these are the things I know help with these displays:-

  • If you daisy chain these, do NOT daisy chain the power lines, run those in parallel (though its fine if you did this with the ground line, but the positives need to run in parallel to each board). As the power passes through each board, the onboard diode drops the voltage, so if you chain the power, it drops each time.
  • The boards need a reasonable current provided to them - check other forum posts, but don't try to run these off the arduino itself or some low ampage supply like the old 5v 0.5A usb chargers.
  • these boards are cheap - expect a few duff ones

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.