8-Digit Red LED Display Module 7 Segment with Mega 256

I'm trying to use a 8-digit Red LED display module 7 segment with a Mega 256 (based up MAX7219). I have this test program. The LedControl library I got from the Arduino libray site.

#include "LedControl.h"

 const int DataIn = 10;
 const int Clk = 12;
 const int Load = 11;
 
LedControl lc = LedControl(DataIn, Clk, Load, 1);

unsigned long delaytime = 250;

void setup() {
  lc.shutdown(0,false);
  lc.setIntensity(0, 1);
  lc.clearDisplay(0);
}

void writeArduinoOn7Segment() {
  lc.setChar(0, 7, 'a', false);
  delay(delaytime);
  lc.setChar(0, 6, 'r', false);
  delay(delaytime);
  lc.setChar(0, 5, 'd', false);
  delay(delaytime);
  lc.setChar(0, 4, 'u', false);
  delay(delaytime);
  lc.setChar(0, 3, 'i', false);
  delay(delaytime);
  lc.setChar(0, 2, 'n', false);
  delay(delaytime);
  lc.setChar(0, 1, 'o', false);
  delay(delaytime);
  
  lc.clearDisplay(0);
  delay(delaytime);
} 

void loop()
{
  writeArduinoOn7Segment();
}

It constantly displays 'Arduino' on the display. When I connect the display module to a Uno and upload this program, it works fine. It continually displays 'Arduino' for as long as I keep the program running as expected.

However, if I compile and upload this program for a Mega 256, after a few seconds one or more letters doesn't display (just shows nothing in that position) and then after a few more seconds the whole display goes blank. If I power-off the Mega and power on again the same situation repeats.

On the Mega, I've tried changing the pins used (22 for 10, 23 for 11 and 24 for 12) but this has made no difference. Can any kind person advise why this is having problem on the Mega but works fine on the Uno.

The problem might just be mechanical. I used that playground stuff first on a Mega and then moved to Uno, and I'm sure there was no change in wiring or procedure.

Make sure you have a .1uf capacitor form pin 19 to pin 4 on the 7219.

The modules I'm using come pre-built with two 4 digit 7-segment displays and the 7219 chip all on a small circuit board with .1" spaced pins for connections. There appears to be a resistor R1, a capacitor c1, a diode d1 and a largish capacitor. The external connections are Vcc, gnd, din, cs and clk.

These modules work fine when connected to my Uno. But on my Mega (both powered by USB and external 7.5v power) they only stay lit for a few seconds before first one of the digits goes blank and then they all go blank. Powering off/on the Mega brings back the display but again for only a few seconds. On the Mega I also have an LCD display and RTC connected. When I run my usual program on the Mega (rather than the test one in my post #1) I get the same issue with the 7 segment display but the LCD display and the program continues to function as expected when the 7-segment display goes blank.

I'm tearing my hair out here trying to get this to work with my mega. I've used different 7-segment modules, I've tried different pins on the Mega, I've tried a different cable from the 7-segement display module but all to no avail. =(

Hi 2kaud

You could try simplifying your test program further. For example, remove the function call from loop(), so loop() is empty, and put just the following at the end of setup().

  lc.setChar(0, 7, 'a', false);
  delay(delaytime);
  lc.setChar(0, 6, 'r', false);
  delay(delaytime);
  lc.setChar(0, 5, 'd', false);
  delay(delaytime);
  lc.setChar(0, 4, 'u', false);
  delay(delaytime);
  lc.setChar(0, 3, 'i', false);
  delay(delaytime);
  lc.setChar(0, 2, 'n', false);
  delay(delaytime);
  lc.setChar(0, 1, 'o', false);
  delay(delaytime);

This should write the seven letters at 250ms intervals and then do nothing else. So it would be interesting to see if the characters stay on the display or if they still disappear after a while.

By the way, when the digits go blank, do they switch off instantly, or do they dim at all as they go off?

Regards

Ray

When the digits go blank, they switch off instantly. They don't dim. However, what I don't know but will now investigate is whether rewriting to the display is the problem or simply displaying what has been sent. When I write to the display I clear it first before writing the digits. So the issue may be that the new data isn't being displayed properly.

Is the Mega faster than the Uno and could this be a timing issue? The libray uses the following code to send data to the display module

void LedControl::spiTransfer(int addr, volatile byte opcode, volatile byte data) {
    //Create an array with the data to shift out
    int offset = addr * 2;
    int maxbytes = maxDevices * 2;

    for(int i = 0; i < maxbytes; i++)
	spidata[i] = (byte)0;
    //put our device data into the array
    spidata[offset + 1] = opcode;
    spidata[offset] = data;
    //enable the line 
    digitalWrite(SPI_CS, LOW);
    //Now shift out the data 
    for (int i = maxbytes; i > 0; i--)
 	shiftOut(SPI_MOSI, SPI_CLK,MSBFIRST, spidata[i - 1]);
    //latch the data onto the display
    digitalWrite(SPI_CS, HIGH);
}

I do not believe it!!!!!!!!!!! :astonished:

I've made up a new cable harness to go from the display module using single core solid cable rather than multi-core ribbon cable that was being used before. It now works on the Mega!!!!!! I don't understand. I've checked the old ribbon cable and there are no shorts between the wires and there is continuity between both ends of each of the wires. I've swapped back to the old cable and the problem re-appears on the Mega - using the new cable and it's fine! The old one still works fine on the Uno!

Any explanations please anyone????

2kaud:
and there is continuity between both ends of each of the wires.

As I said, the problem sounded mechanical, now even more so with a mechanical solution, but continuity can be a relative term. There could be a number of little marginal things adding up, just, on the Mega, that don't quite add up on the Uno.