Digital Display goes Crazy

Thread Starter

Lawrence H

Joined May 6, 2019
98
Hey!

I have set up a 4-digit display on a simple testing loop with an Arduino Uno, and it randomly goes crazy and goes through the loop super fast.

Here is my code:

Code:
byte pinA = 2; //11
byte pinB = 3; //7
byte pinC = 4; //4
byte pinD = 5; //2
byte pinE = 6; //1
byte pinF = 7; //10
byte pinG = 8; //5
byte pinDP = 9; //3

byte D1 = 10; //12
byte D2 = 11; //9
byte D3 = 12; //8
byte D4 = 13; //6

byte pinsLetters = 8;

int wait = 250;

byte digit = 10;
void setup() {
  // put your setup code here, to run once:

  Serial.begin(9600);

  pinMode(pinA,OUTPUT);
  pinMode(pinB,OUTPUT);
  pinMode(pinC,OUTPUT);
  pinMode(pinD,OUTPUT);
  pinMode(pinE,OUTPUT);
  pinMode(pinF,OUTPUT);
  pinMode(pinG,OUTPUT);
  pinMode(pinDP,OUTPUT); //DOT
 
  pinMode(D1,OUTPUT);
  pinMode(D2,OUTPUT);
  pinMode(D3,OUTPUT);
  pinMode(D4,OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:

  delay(wait);

  if (digit > D4)
  {
  digit = D1;
  digitalWrite(D1,LOW); 
  digitalWrite(D2,HIGH); 
  digitalWrite(D3,HIGH); 
  digitalWrite(D4,HIGH);
  delay(wait);
  }
 
  if (digit == D1)
  {
  digit ++;
  digitalWrite(D1,LOW); 
  digitalWrite(D2,HIGH); 
  digitalWrite(D3,HIGH); 
  digitalWrite(D4,HIGH);
  delay(wait);
  }

  else if (digit == D2)
  {
  digit ++;
  digitalWrite(D1,HIGH); 
  digitalWrite(D2,LOW); 
  digitalWrite(D3,HIGH); 
  digitalWrite(D4,HIGH);
  delay(wait);
  }
  else if (digit == D3)
  {
  digit ++;
  digitalWrite(D1,HIGH); 
  digitalWrite(D2,HIGH); 
  digitalWrite(D3,LOW); 
  digitalWrite(D4,HIGH);
  delay(wait);
  }
  else if (digit == D4)
  {
  digit ++;
  digitalWrite(D1,HIGH); 
  digitalWrite(D2,HIGH); 
  digitalWrite(D3,HIGH); 
  digitalWrite(D4,LOW);
  delay(wait);
  }
  else
  {
  digitalWrite(D1,LOW); 
  digitalWrite(D2,LOW); 
  digitalWrite(D3,LOW); 
  digitalWrite(D4,LOW);
  delay(wait);
  }

  digitalWrite(pinA, HIGH);
  delay(wait);
  digitalWrite(pinA,LOW);
  delay(wait);

  digitalWrite(pinB, HIGH);
  delay(wait);
  digitalWrite(pinB,LOW);
  delay(wait);

  digitalWrite(pinC, HIGH);
  delay(wait);
  digitalWrite(pinC,LOW);
  delay(wait);

  digitalWrite(pinD, HIGH);
  delay(wait);
  digitalWrite(pinD,LOW);
  delay(wait);

  digitalWrite(pinE, HIGH);
  delay(wait);
  digitalWrite(pinE,LOW);
  delay(wait);

  digitalWrite(pinF, HIGH);
  delay(wait);
  digitalWrite(pinF,LOW);
  delay(wait);

  digitalWrite(pinG, HIGH);
  delay(wait);
  digitalWrite(pinG,LOW);
  delay(wait);

  digitalWrite(pinDP, HIGH);
  delay(wait);
  digitalWrite(pinDP,LOW);
  delay(wait);

  Serial.println(digit);
  delay(1000);
}
I made the code as simple as possible to try and be able to see every step of it and see where things might go wrong. The thing is, the break seems to be at a random time.

I have gone through the wiring and it seems OK. I added resistors so that the brightness would go down as much as possible, but even before that this loop would begin. Can you see a problem with the code that I just missed?

Thanks!
 

Thread Starter

Lawrence H

Joined May 6, 2019
98
Do tell us the make and model of the display. Post photos and datasheet of the display,
5461AS is the model
Do tell us the make and model of the display. Post photos and datasheet of the display,
https://www.google.com/url?sa=t&sou...YQFnoECAMQAQ&usg=AOvVaw31HfcV84V9XVFtfcQ-jg4h

Here, mine also says -1 at the end of the model ID

Can't post photos right now but it is the same and all the wifing is correct, since it loops a few times before going competely nuts.
 

MrChips

Joined Oct 2, 2009
31,079
Ok. Thanks for that.
The problem is not in the display. The problems lies in your MCU and program.
The next thing you have to tell us is what is the power supply voltage and current capability.
It sounds like noise on the power supply is adversely affecting the operation of the MCU.

Can you show us a circuit diagram of how the display is connected to the Arduino?
 

Thread Starter

Lawrence H

Joined May 6, 2019
98
Ok. Thanks for that.
The problem is not in the display. The problems lies in your MCU and program.
The next thing you have to tell us is what is the power supply voltage and current capability.
It sounds like noise on the power supply is adversely affecting the operation of the MCU.

Can you show us a circuit diagram of how the display is connected to the Arduino?
You can where the pins are set from the code I think, the comment after the pin in the beginning is the origin pin. So as an example, "pinA = 2 // 11" means that pinA is in pin 2 of the arduino, and pin 11 on the display.

I have a 10K resistor on each of the digit pins. You can also see where they are wired from the comments. There is no separate ground or power in this display which I wondered about. Can you tell me why that is?

So in short, each of the pins are in the comments, and the digit pins go into 10K resistors, and then to the board into their pins.

EDIT:

I put a led in each pin from 1 to 13, with a resistor on each, and ran this program. It seems to be running normally, lighting up the LEDs as expected, and turning the LEDs low and high in order. There is no craziness going on with this, it's been running for a while. I put all the LEDS on separate transistors and in the GRN of the Arduino.
 
Last edited:

MrChips

Joined Oct 2, 2009
31,079
There is no power or ground required for these displays because they are multiplexed.
This means that the anode and cathode of each segment must be actively switched for it to be lit.
The MCU pin to the anode must source current through a current limiting resistor.
The MCU pin to the cathode must sink current.

In your case, this is a common cathode display. This means that the cathode of seven segments plus the decimal point are all tied to a common point. This is used in order to multiplex the four digits.

10kΩ series resistor seems too high. This would allow only 5V/10kΩ = 0.5mA per segment while the datasheet calls for 10mA.
But that is a different issue. The display must be very dim and this would alleviate the consequences of drawing too much current.

What you can do is test the code in stages.
Disconnect the display and use a single LED to monitor the correct operation of the program.
Then add one digit at a time.
 

Thread Starter

Lawrence H

Joined May 6, 2019
98
There is no power or ground required for these displays because they are multiplexed.
This means that the anode and cathode of each segment must be actively switched for it to be lit.
The MCU pin to the anode must source current through a current limiting resistor.
The MCU pin to the cathode must sink current.

In your case, this is a common cathode display. This means that the cathode of seven segments plus the decimal point are all tied to a common point. This is used in order to multiplex the four digits.

10kΩ series resistor seems too high. This would allow only 5V/10kΩ = 0.5mA per segment while the datasheet calls for 10mA.
But that is a different issue. The display must be very dim and this would alleviate the consequences of drawing too much current.

What you can do is test the code in stages.
Disconnect the display and use a single LED to monitor the correct operation of the program.
Then add one digit at a time.
I added an edit to the previous post so as to not spam this thread, where I added a single led to each of the pins. It seems that pin 1 is dimly lit, while the other's are lit alright. The program runs in it's entirety though without issue.

The display is indeed dim, but I have worked with LEDs before, and the brightness goes right behind my eyes and I fear I will begin suffering form migraines. I am wearing two pairs of sunglasses while using the LEDs.
 

MrChips

Joined Oct 2, 2009
31,079
EDIT:

I put a led in each pin from 1 to 13, with a resistor on each, and ran this program. It seems to be running normally, lighting up the LEDs as expected, and turning the LEDs low and high in order. There is no craziness going on with this, it's been running for a while. I put all the LEDS on separate transistors and in the GRN of the Arduino.
I don't see a problem with spamming. I think you should have put this into a new post. This keeps it in proper sequence.

Now you need to post a circuit diagram to show us what you are actually doing.
 

John P

Joined Oct 14, 2008
2,027
In a construction like this
Code:
  if (digit > D4)
  {
  digit = D1;
  }
 
  if (digit == D1)
  {
  digit ++;
  digitalWrite(D1,LOW); 
  digitalWrite(D2,HIGH); 
  digitalWrite(D3,HIGH); 
  digitalWrite(D4,HIGH);
  delay(wait);
  }
are D1, D2 etc numeric quantities, or are they pins of the device? Because you seem to be treating them as both, or either. It's so confusing that I'm not sure if it'll work or not, or what it would be likely to do. Doesn't it confuse you too?
 

Thread Starter

Lawrence H

Joined May 6, 2019
98
I'll try to do it like this, I hope you can make out the wiring and what I am trying to do. I can't take a pic and I can't really draw diagrams. But here is everything you should need. Let me know if I am unclear on somethings.

As a test, I wanted to blink each position on each digit once, in a loop, just to see that everything is wired correctly, and that everything works. So first, D1 is LOW (which means it's on), and all the other D pins are high to keep them off. It then blinks PinA, PinB ..... until pinDP. Then, it turns D1 off, and turns D2 on, and repeats the loop. After all digit pins and all positions have been tested, the loop is reset to D1, and it should begin over again.

This works for about 3 loops, until the digital display begins to pretty much ignore the delays, and loop everything all at once, or then it displays everything at once, but the lights do flash so it is sort of looping but super fast. it is possible it is looping through each position if the speed is around 60 MHz.

I have a PC - USB - Arduino connection to power the arduino.

Pin A = Pin 2 -> Display pin 11
Pin B = Pin 3 -> Display pin 7
Pin C = Pin 4 -> Display pin 4
Pin D = Pin 5 -> Display pin 2
Pin E = Pin 6 -> Display pin 1
Pin F = Pin 7 -> Display pin 10
Pin G = Pin 8 -> Display pin 5
Pin DP = Pin 9 -> Display pin 3

I am unsure of where the resistors were exactly since I used them to create my LED test, but I think this was the configuration. In any case, they dimmed the display accurately, and were only on the digit pins.

D1 = Pin 10 -> Resistor -> Display Pin 12
D1 = Pin 11-> Resistor -> Display Pin 9
D1 = Pin 12 -> Resistor -> Display Pin 8
D1 = Pin 13 -> Resistor -> Display Pin 6

I will post the code here again so you don't have to scroll up and down.

Code:
byte pinA = 2; //11
byte pinB = 3; //7
byte pinC = 4; //4
byte pinD = 5; //2
byte pinE = 6; //1
byte pinF = 7; //10
byte pinG = 8; //5
byte pinDP = 9; //3

byte D1 = 10; //12
byte D2 = 11; //9
byte D3 = 12; //8
byte D4 = 13; //6

byte pinsLetters = 8;

int wait = 250;

byte digit = 10;
void setup() {
  // put your setup code here, to run once:

  Serial.begin(9600);

  pinMode(pinA,OUTPUT);
  pinMode(pinB,OUTPUT);
  pinMode(pinC,OUTPUT);
  pinMode(pinD,OUTPUT);
  pinMode(pinE,OUTPUT);
  pinMode(pinF,OUTPUT);
  pinMode(pinG,OUTPUT);
  pinMode(pinDP,OUTPUT); //DOT
 
  pinMode(D1,OUTPUT);
  pinMode(D2,OUTPUT);
  pinMode(D3,OUTPUT);
  pinMode(D4,OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:

  delay(wait);

  if (digit > D4)
  {
  digit = D1;
  }
 
  if (digit == D1)
  {
  digitalWrite(D1,LOW); 
  digitalWrite(D2,HIGH); 
  digitalWrite(D3,HIGH); 
  digitalWrite(D4,HIGH);
  delay(wait);
  }

  else if (digit == D2)
  {
  digitalWrite(D1,HIGH); 
  digitalWrite(D2,LOW); 
  digitalWrite(D3,HIGH); 
  digitalWrite(D4,HIGH);
  delay(wait);
  }
  else if (digit == D3)
  {
  digitalWrite(D1,HIGH); 
  digitalWrite(D2,HIGH); 
  digitalWrite(D3,LOW); 
  digitalWrite(D4,HIGH);
  delay(wait);
  }
  else if (digit == D4)
  {
  digitalWrite(D1,HIGH); 
  digitalWrite(D2,HIGH); 
  digitalWrite(D3,HIGH); 
  digitalWrite(D4,LOW);
  delay(wait);
  }
  else
  {
  digitalWrite(D1,LOW); 
  digitalWrite(D2,LOW); 
  digitalWrite(D3,LOW); 
  digitalWrite(D4,LOW);
  delay(wait);
  }

  digitalWrite(pinA, HIGH);
  delay(wait);
  digitalWrite(pinA,LOW);
  delay(wait);

  digitalWrite(pinB, HIGH);
  delay(wait);
  digitalWrite(pinB,LOW);
  delay(wait);

  digitalWrite(pinC, HIGH);
  delay(wait);
  digitalWrite(pinC,LOW);
  delay(wait);

  digitalWrite(pinD, HIGH);
  delay(wait);
  digitalWrite(pinD,LOW);
  delay(wait);

  digitalWrite(pinE, HIGH);
  delay(wait);
  digitalWrite(pinE,LOW);
  delay(wait);

  digitalWrite(pinF, HIGH);
  delay(wait);
  digitalWrite(pinF,LOW);
  delay(wait);

  digitalWrite(pinG, HIGH);
  delay(wait);
  digitalWrite(pinG,LOW);
  delay(wait);

  digitalWrite(pinDP, HIGH);
  delay(wait);
  digitalWrite(pinDP,LOW);
  delay(wait);

  Serial.println(digit);
  digit ++;
  delay(wait);
}
Then I turn on the Arduino Uno, upload the code, and it loops for ~3 loops + and at some point it begins looping it very fast without the delays.

I hope this is enough, but if not, I can add more info.
 

Thread Starter

Lawrence H

Joined May 6, 2019
98
In a construction like this
Code:
  if (digit > D4)
  {
  digit = D1;
  }

  if (digit == D1)
  {
  digit ++;
  digitalWrite(D1,LOW);
  digitalWrite(D2,HIGH);
  digitalWrite(D3,HIGH);
  digitalWrite(D4,HIGH);
  delay(wait);
  }
are D1, D2 etc numeric quantities, or are they pins of the device? Because you seem to be treating them as both, or either. It's so confusing that I'm not sure if it'll work or not, or what it would be likely to do. Doesn't it confuse you too?
I forgot to add pinD1, and since it was just a test for myself I left them as D1, D2. These are the common pins on the display that light up the individual digits.

The pins variables aren't being used as anything else except references. If D1 == something, then do this, never D1 = something, except when I set the pins in the beginning.

I took everything out of a for loop because it did the same thing, and I wrote the code so that I can check every single step of it and see where the issue begins. However the issue seems to occur randomly, so that's not the issue.
 

MrChips

Joined Oct 2, 2009
31,079
A picture is worth a thousand words. A circuit schematic is the language of electronics in order to convey electrical/electronic designs efficiently. Please draw a circuit diagram.
 

Thread Starter

Lawrence H

Joined May 6, 2019
98
But
if (digit > D4)
...
and then
digitalWrite(D4,HIGH);

I can't make any sense of this.
I don't know how to explain that any better. If the current digit is the same as pinD4, then your set pinD4 to high, which turns it off in this case. The pins from PinA to pinDP get turned on by setting the current high. EDIT: Oh and if the current digit is greater than D4 which is the last digit pin, then you revert back to D1, and light digit 1 again. It is a limiter on the variable "digit".

https://crcit.net/c/19a913fe7c4f412a8ce589577de61a53

Here is a diagram of it. Since I couldn't fit the resistors into it, you can see them as the pins that go inside the drawn display. The display pins go from bottom left to right as 1 to 6, then from top right to left as 7 to 12.
 

Thread Starter

Lawrence H

Joined May 6, 2019
98
I tried this again now, and it loops around for about 20 times before going crazy. I don't touch it, I don't even breathe on it.
 

djsfantasi

Joined Apr 11, 2010
9,186
UPDATED: See notes at the end.

Sounds like you have a memory overflow problem. Are you sure your code is identical to the library examples?

You may be missing a reset that frees up memory for example. That’s happened to me. Or you’re using a brute force method of clearing the display instead of using the appropriate library function.

I couldn’t find the library you are using with a quick skim of your posts.

NOTES: I forgot that you weren’t using an LCD display. Still, the behavior you describe sounds like a memory overflow issue. Perhaps your array indices aren’t properly limited.
 

Thread Starter

Lawrence H

Joined May 6, 2019
98
UPDATED: See notes at the end.

Sounds like you have a memory overflow problem. Are you sure your code is identical to the library examples?

You may be missing a reset that frees up memory for example. That’s happened to me. Or you’re using a brute force method of clearing the display instead of using the appropriate library function.

I couldn’t find the library you are using with a quick skim of your posts.

NOTES: I forgot that you weren’t using an LCD display. Still, the behavior you describe sounds like a memory overflow issue. Perhaps your array indices aren’t properly limited.
The code is the same, and there shouldn't be any memory issues if I understand them, since the only variable that is increasing is the digit variable and that is reset once it is one over the last digit pin, which is 14 I think.

I'm not clearing anything etc since I'm not sure it is needed here but do let me know if that's something you need to do with arduino.
 
Top