0

I've been trying to follow a few tutorials on how to get the 7 segment to display simple output but none seem to work 100%.

It starts out fine. It increments the number across the screen and then writes 8s to all of them and then reverses. After a few loops however it starts to act weird. Here's a video link where it acts a bit weird (a few digits don't write correctly and fix themselves) and then at the end, it only displays half of the 8 digit display before it goes to 8s and crashes. https://youtu.be/LD_C7I_bGyc

Here's the code:

//We always have to include the library
#include "LedControl.h"

// pin 4 is connected to the DIN pin
// pin 2 is connected to the CLK pin
// pin 3 is connected to the CS pin
// 1 as we are only using 1 MAX7219
LedControl lc = LedControl(4, 2, 3, 1);

void setup(){
    // the zero refers to the MAX7219 number, it is zero for 1 chip
    lc.shutdown(0, false);// turn off power saving, enables display
    lc.setIntensity(0, 0);// sets brightness (0~15 possible values)
    lc.clearDisplay(0);// clear screen
}

void loop(){
    // numbers 7 to 0
    for (int a = 0; a < 8; a++){
        lc.setDigit(0, a, a, false);
        delay(100);
    }
    delay(1000);
    // display number 8 on all segments
    for (int a = 0; a < 8; a++){
        lc.setDigit(0, a, 8, false);
        delay(100);
    }
    delay(1000);

    for (int a = 8; a >= 0; a--){
        lc.setDigit(0, a, a, false);
        delay(100);
    }
}

Hardware: Arduino Uno: https://www.jaycar.com.au/duinotech-uno-r3-development-board/p/XC4410 8 digit display: https://www.jaycar.com.au/8-digit-7-segment-display-module/p/XC3714

At this stage it's hard to tell if it's a hardware issue or if it's setup related. If someone could please give me some insight or maybe run it if they have the same hardware that would be fantastic.

Thanks!

  • You should switch your display on. Your setup() call to lc.setIntensity(0, 0) turns the display intensity to zero, try setting it to 15. – Dougie Nov 17 '19 at 11:22
  • That's just the brightness. It was originally 15 during the day but at night I turned it down because it was too bright. – Kc Gibson Nov 17 '19 at 11:35
  • I wonder if you're timings are too fast. There's timing values in the datasheet at datasheets.maximintegrated.com/en/ds/MAX7219-MAX7221.pdf try slowing everything down a bit. – Dougie Nov 17 '19 at 11:46
  • for (int a = 8; a >= 0; a--){ -- Why do you start with 8 and not with 7. The forward version go to 7 a < 8;. BTW: I enjoyed the question, because of the video. Cool Idea. ;-) – Peter Paul Kiefer Nov 17 '19 at 13:29
  • @Dougie you were pretty close. I posted an answer to the fix as it was actually the ground wire not being stable. I had previously changed all the wires that control the 8 digit however I never thought to change the power and ground wires to the board. Not having a stable ground wire would have messed up the communication and affect the timings a lot. – Kc Gibson Nov 17 '19 at 20:44
2

This was an unexpected result. @Dougie was pretty on to it. I didn't know how to adjust the timings as I was pretty sure the library took care of it, so the only thing I could think of was to redo all the wiring again. That's when I noticed that the ground wire pin into the board was half sticking out.

In the video you can see the ground pin at the top right. So it was making a connection (otherwise the whole thing wouldn't work), but after replacing the wire it runs fine. So that would have messed up the timings if the connection was unstable.

  • Well, it might have changed the values recognized by the chip. If you lose ground (no pun intended) the reference level is lost. A "low" (bit value 0) might be read as "high" (bit value 1) or vice versa. The timing will not change because of a missing ground connection. – the busybee Nov 17 '19 at 21:14
  • I'm not an expert at this, but my guess was that the Arduino was sending the messages but since it wasn't grounding properly it was cutting out and therefore getting mixed messages during each timing round. – Kc Gibson Nov 17 '19 at 21:19
  • @the bussybee, I'll need to do some research as to how ground actually impacts it as I thought it just completed the circuit. – Kc Gibson Nov 17 '19 at 21:21
1

The last loop exceeds the limits of 8 Digits. You iterate 9 times (0-8).

   for (int a = 7; a >= 0; a--){
        lc.setDigit(0, a, a, false);
        delay(100);
    }
  • This is almost certainly the problem. (voted.) Array out-of-bounds problems cause lots of strange symptoms. – Duncan C Nov 17 '19 at 15:51
  • Annoyingly that didn't fix it. I'm guessing if it was then it would crash on the first main "loop" but it runs for a while before freaking out. – Kc Gibson Nov 17 '19 at 20:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.