Digital Display goes Crazy

MrChips

Joined Oct 2, 2009
34,824
Let's leave the wiring as is.

For the moment we will use PD7-PD2 as connected to F, E, D, C, B, A segments. Ignore segment G for now.
Connect DIGIT1 cathode (pin-12) to GND.
What value series resistor are you using now?

Here is the test code.
Code:
void setup()
{
  pinMode(ledPin, OUTPUT);
  DDRD = 0xFC;
}

void loop()
{
  digitalWrite(ledPin, HIGH);
  PORTD = 0xFC;
  delay(500);
  digitalWrite(ledPin, LOW);
  PORTD = 0;
  delay(500);
}
Leave this running overnight. See if it is still running in the morning.
See you tomorrow.
 

Thread Starter

Lawrence H

Joined May 6, 2019
98
BTW, I have two on/off switches on my connections. One is for the power line from the USB, and one if from the external power source.

This means that I can keep the USB connected with using only external power for the Arduino, but I can still upload data since that connection is not severed by the on/off switch. It is pretty handy.

I am now blinking the a reverse C image on the display's digit 1 every 100ms, and it seems to be running alright. I can't blink it faster or keep it on, since then I wouldn't see if it wuold get out of control. When I tried to run this accidentally through the Arduino power only, it became erratic almost immediately. The external power seems to give it a lot more time to break.
 

Thread Starter

Lawrence H

Joined May 6, 2019
98
I assumed ledPin was 13, so I made it so.

The reverse C, which is the first 4 segments of the display are blinking with the LED.
 

djsfantasi

Joined Apr 11, 2010
9,237
Connect DIGIT1 cathode (pin-12) to GND.
What value series resistor are you using now?
For only six segments as proposed, any resistor 470Ω or less will damage the Arduino and will give 7ma per segment (for all seven segments, the resistor should be greater than 570Ω. 680Ω is the next standard size and will give each segment only 1.5ma ).

I assumed ledPin was 13, so I made it so
That is the pin for the built-in on board LED.
 
Last edited:

Thread Starter

Lawrence H

Joined May 6, 2019
98
I feel like this saga has come to an end now. Thanks for all your patience and help!

I had to craft some extra wires that I could stick to the breadboard and meanwhile this program was running constantly. I also did other things in between starting the program and now. It took me a good hour at least I think.


Here you can see the display running nicely with numbers as a test.

I used 230 Ohm resistors on all the segments, and 10K resistors on the digits. I wanted the display dim due to having worked with LEDs before and getting sore eyes as I mentioned in some random post through this whole thing.

I will still leave it on for the rest of the time I am awake to see if anything goes wrong in that time.

I will also add the solution to the first post. I'm glad of all your help and I learned a whole lot while doing this, which I think is a good main objective in anything. So long as you don't lose any fingers etc.

I'm sure you will be seeing more of me here, though next time I will understand what you are saying more from the very get go. Thanks again! Have a good one!
 

Thread Starter

Lawrence H

Joined May 6, 2019
98
And here I am again....

After a while, I noticed the led was blinking erratically, and what do you know, it is broken again.

Clearly the resistors do SOMETHING, but what it is I don't know.
 

djsfantasi

Joined Apr 11, 2010
9,237
And here I am again....

After a while, I noticed the led was blinking erratically, and what do you know, it is broken again.

Clearly the resistors do SOMETHING, but what it is I don't know.
You need to use the proper resistors )I gave you the values) and NOT use the 10k resistors. You may need to use a transistor on the digit select line if the display is too dim. Without a transistor, the resistors cannot be less than 680 ohms.

If you cannot try this, I can’t help.
 

Thread Starter

Lawrence H

Joined May 6, 2019
98
You need to use the proper resistors )I gave you the values) and NOT use the 10k resistors. You may need to use a transistor on the digit select line if the display is too dim. Without a transistor, the resistors cannot be less than 680 ohms.

If you cannot try this, I can’t help.
I have only 230, 1K and 10K available at the moment, and a limited amount of those. I did change the 10K resistors to 1K resistors.
 

Thread Starter

Lawrence H

Joined May 6, 2019
98
You jumped ahead of the tests I suggested.

Have you been running the code I gave you?
I ran the blinking code yes, and it works. I did not leave it on all night though, but it was there for some hours. I can leave it on tonight later though to test it more.
 

MrChips

Joined Oct 2, 2009
34,824
Something tells me that there is something wrong in your code but I can't spot it.

I intended to move on to the next step and that is to display digits 0-9 on a single display.
You have segments A-G spanning across two ports. If you can avoid using the RX, TX UART pins, let us put all segments and DP (decimal point) on one port, PORTD.

If you wish we can retain the wiring for segments A-F as you have it. If for whatever reason you would like to change the pin assignments we can do that. For now, move G and DP so that we have the following:

segment = Arduino pin#
DP = 0
G = 1
A = 2
B = 3
C = 4
D = 5
E = 6
F = 7

Next, make a table of the state of all segments in order to display 0-9

== F E D C B A G DP
# = 7 6 5 4 3 2 1 0 = PORTD bits
0 = 1 1 1 1 1 1 0 0
1 = 0 0 0 1 1 0 0 0
2 = 0 1 1 0 1 1 1 0
3 = 0 0 1 1 1 1 1 0
4 = 1 0 0 1 1 0 1 0
5 = 1 0 1 1 0 1 1 0
6 = 1 1 1 1 0 0 1 0
7 = 0 0 0 1 1 1 0 0
8 = 1 1 1 1 1 1 1 0
9 = 1 0 0 1 1 1 1 0

Since we are not using DP you can ignore that for now.
 

MrChips

Joined Oct 2, 2009
34,824
Here is your hardware setup for this test.
Use 1kΩ series resistors to the seven segments. Leave the DP unconnected.
Remove all connections to the four digit select pins.
Connect only one digit select pin (common cathode) to GND.

Here is the test code:
Code:
byte segments[] = {0b11111100, 0b00011000, 0b01101110, 0b00111110, 0b10011010, 0b10110110, 0b11110010, 0b00011100, 0b11111110, 0b10011110};
byte i = 0;

void setup()
{
  DDRD =   0xFE;
}

void loop()
{
  PORTD = segments[i];
  delay(1000);
  i = ++i % 10;
}
 

MrChips

Joined Oct 2, 2009
34,824
If you still want to see the 1-sec test LED, use this code:
Code:
const int ledPin =  LED_BUILTIN;  // the number of the LED pin
byte segments[] = {0b11111100, 0b00011000, 0b01101110, 0b00111110, 0b10011010, 0b10110110, 0b11110010, 0b00011100, 0b11111110, 0b10011110};
byte i = 0;

void setup()
{
  pinMode(ledPin, OUTPUT);
  DDRD = 0xFE;
}

void loop()
{
  digitalWrite(ledPin, HIGH);
  PORTD = segments[i];
  delay(500);
  digitalWrite(ledPin, LOW);
  delay(500);
  i = ++i % 10;
}
 

djsfantasi

Joined Apr 11, 2010
9,237
segment = Arduino pin#
DP = 0
G = 1…
I admitted I made a mistake with pins 2-3. But these pin assignments ARE likely to cause an issue is a USB cable is attached for any reason. The serial monitor would be identified as used and data on pins 0-1 will be corrupted. I avoid PORTD for that reason. Using ports in a multiplexing solution has several advantages, but you have to be very familiar with the Arduino spec in order to create a working system with operable code.

So if you are powering the Arduino through Vin and ground or the barrel jack and not USB, this is a preferable solution. After loading the sketch, the USB cable should be removed and the Arduino reset.
 

Thread Starter

Lawrence H

Joined May 6, 2019
98
I admitted I made a mistake with pins 2-3. But these pin assignments ARE likely to cause an issue is a USB cable is attached for any reason. The serial monitor would be identified as used and data on pins 0-1 will be corrupted. I avoid PORTD for that reason. Using ports in a multiplexing solution has several advantages, but you have to be very familiar with the Arduino spec in order to create a working system with operable code.

So if you are powering the Arduino through Vin and ground or the barrel jack and not USB, this is a preferable solution. After loading the sketch, the USB cable should be removed and the Arduino reset.
I will get back to this project later today I think. I'll update you on how things are going. I will start the blink test as soon as I am able as well.
 

djsfantasi

Joined Apr 11, 2010
9,237
I did a little additional research. Here are the definition of the ports on an Arduino Uno.

“In summary:

port B: digital pins 8..13
port C: analog pins A0..A5
port D: digital pins 0..7 (note pins 0 and 1 are the serial connections, leaving only 6 pins free for general use).”

Note that each port only has 6 useable bits. So you’ll only be able to use port manipulation for six bits and hence use a combination of port and pin manipulation.
 

MrChips

Joined Oct 2, 2009
34,824
I did a little additional research. Here are the definition of the ports on an Arduino Uno.

“In summary:

port B: digital pins 8..13
port C: analog pins A0..A5
port D: digital pins 0..7 (note pins 0 and 1 are the serial connections, leaving only 6 pins free for general use).”

Note that each port only has 6 useable bits. So you’ll only be able to use port manipulation for six bits and hence use a combination of port and pin manipulation.
That is easy enough to do. If TS wants to preserve PD0 and PD1 for serial communications we can assign segment-G to another pin. I will post my code to do that tomorrow. It is just one more line of code in the loop.
 

MrChips

Joined Oct 2, 2009
34,824
Currently the issue still persists.

I used 230 Ohm resistors on all the segments. I did not have any resistors on the segments and this was causing the erratic behavior. I have 10K resistors on the digits.
________________
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;
  }

  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!

EDIT:

I think I spotted it, I will return if it still persists, since I made that change to try to fix this bug, and it was OK before.

It still happens. Code is updated.
Please do not edit previous posts. This is going to throw the whole conversation out of whack!
If you made an error, say so, but don't change the text.
 

Thread Starter

Lawrence H

Joined May 6, 2019
98
Please do not edit previous posts. This is going to throw the whole conversation out of whack!
If you made an error, say so, but don't change the text.
This was the first post, and I edited it after the system worked for several hours so that if someone ended up on this thread they wouldn't have to read everything for a simple resistor fix. I then changed it back.
 
Top