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!
2 Answers 2
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– Duncan C2019年11月17日 15:51:48 +00:00Commented Nov 17, 2019 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.Casey Gibson– Casey Gibson2019年11月17日 20:27:52 +00:00Commented Nov 17, 2019 at 20:27
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– the busybee2019年11月17日 21:14:44 +00:00Commented Nov 17, 2019 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.Casey Gibson– Casey Gibson2019年11月17日 21:19:35 +00:00Commented Nov 17, 2019 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.Casey Gibson– Casey Gibson2019年11月17日 21:21:35 +00:00Commented Nov 17, 2019 at 21:21
setup()
call tolc.setIntensity(0, 0)
turns the display intensity to zero, try setting it to 15.for (int a = 8; a >= 0; a--){
-- Why do you start with 8 and not with 7. The forward version go to 7a < 8;
. BTW: I enjoyed the question, because of the video. Cool Idea. ;-)