Digital Display goes Crazy

MrChips

Joined Oct 2, 2009
34,816
Let us see if we can analyze this more carefully.
You say the display goes crazy.
What does that mean?
Is the code still running?
Does it mean that sequence of multiplexed digit is incorrect?
Or does it mean the data displayed is incorrect?

In your code you have
digit++

What is the initial and final value of digit?
Are there any limits to the value of digit?

D1-D4 are assigned values 11-14.
What are the consequences of testing for (digit == D1), for example?

Your code construct is poorly written.
Code:
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); 
  }
Can you think of better ways of coding this?
 

Thread Starter

Lawrence H

Joined May 6, 2019
98
Let us see if we can analyze this more carefully.
You say the display goes crazy.
What does that mean?
Is the code still running?
Does it mean that sequence of multiplexed digit is incorrect?
Or does it mean the data displayed is incorrect?

In your code you have
digit++

What is the initial and final value of digit?
Are there any limits to the value of digit?

D1-D4 are assigned values 11-14.
What are the consequences of testing for (digit == D1), for example?

Your code construct is poorly written.
Code:
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);
  }
Can you think of better ways of coding this?
You check which digit pin is currently being tested. The initial value is 10, which is the first pin to power a digit. So if digit == D1, it means that the first digit is being tested and so on, until digit reached 15, which is out of bounds, and the variable is set back to D1, which is pin #10. The code is simply a test where I opened up for loops to see where the problem was.

It looks as if the delays are no longer being read, however after removing the delays myself the display showed nothing, whereas now it does seem to loop through all the positions in the display, but it does so rapidly, or, then it just randomly displays positions in no particular order, but it loops through all of them.
 

MrChips

Joined Oct 2, 2009
34,816
If you had chosen your four interface bits to be D3-D0, you could have simply started with 00001000.
Shift right one bit. Reset when 00000000 is reached.

digit = 8
repeat
output digit
shift right digit
while digit is non-zero
 

Thread Starter

Lawrence H

Joined May 6, 2019
98
If you had chosen your four interface bits to be D3-D0, you could have simply started with 00001000.
Shift right one bit. Reset when 00000000 is reached.

digit = 8
repeat
output digit
shift right digit
while digit is non-zero
It does the same thing. At the start of the code it checks whether digit is higher than the last pin. And besides, this is not the code I made for the display, nor is this a code problem. This code was made to see every step of the program in order to find where the problem was. However, the problem is random, so it doesn't matter how you program it, the result is the same, so long as the code runs.
 

MrChips

Joined Oct 2, 2009
34,816
Try not doing any multiplexing.
Display on the same digit while stepping though values 0-9 with a delay of 1 second between increments.
 

Thread Starter

Lawrence H

Joined May 6, 2019
98
I put the code in it's original form, except that I will not loop through the digits, I have only the digit I am testing plugged in and in use, and there is a counter for how many loops there have been. When the system goes crazy, it still prints the loop into the serial, but the difference there is either instant, or ~50ns. However, if I restart the Arduino, the serial will not print anything unless I close and reopen the serial window. Also, the loop counter will not run, until I open the serial, so basically the variable does not work unless I observe it. This might be some memory saving procedure since the variable is only called on the serial, but it wouldn't make any sense since sometimes you might not have the serial window open, but still need to log data.

Code:
//Digital Display
/*
INFO:
LOW on Digit pins means they are on, HIGH on partition is ON
*/

byte pinA = 2; //11 on display
byte pinB = 3; //7 on display
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 i = 0;

byte pinD1 = 10; //12 + 10k resistor
byte pinD2 = 11; //9 + 10k resistor
byte pinD3 = 12; //8 + 10k resistor
byte pinD4 = 13; //6 + 10k resistor

unsigned int wait = 100;

unsigned int loops = 0;

byte digit = 10; //Set the variable to start from first digit pin. Used to loop through the 4 digit pins
void setup() {
  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(pinD1,OUTPUT);
 
  /*
  pinMode(pinD2,OUTPUT);
  pinMode(pinD3,OUTPUT);
  pinMode(pinD4,OUTPUT);
  */
}

void loop() {
  digitalWrite(pinD1,LOW);
  /*
  digitalWrite(pinD2,HIGH); 
  digitalWrite(pinD3,HIGH); 
  digitalWrite(pinD4,HIGH);
  */
 
  for (i = 2; i < 10; i ++) //i = first pin in use for phase A; i < last pin in use + 1; add 1 to i
  {
    digitalWrite(i, HIGH); //Turn on part A in display
    delay(wait); //Wait
    digitalWrite(i,LOW); //Turn off part A in display
    delay(wait);
  }
  loops ++;
  Serial.print("Succesful Loops: ");
  Serial.println (loops);
  delay(1000);
}
The first digit alone goes crazy after five loops when it is the only digit plugged in and looping the test sequence in the for loop.

Second digit went nuts at loop 18.

Digit 3 on loop 7.

Digit 4 at loop 7.

So to reiterate: Everything is plugged in, except for 3 out of the 4 digit pins. I would shut down the arduino, manually change the used digit in the code from form example pinD1 to pinD2, then restart it and upload the code. Then I would repeat this process but remove the wiring from all but the second digit pin and update the code so that the test will loop on the second pin, until I got to digit pin 4.

EDIT: Forgot to add the code that had the second at the end of the loop. Works the same, although the loop in which the erratic behavior might change.
 

Thread Starter

Lawrence H

Joined May 6, 2019
98
I think the display is just crap to be honest . This whole thing worked with LEDs. I will test that again now to make sure, but I would imagine they sent me a borked component.
 

MrChips

Joined Oct 2, 2009
34,816
I think the display is just crap to be honest . This whole thing worked with LEDs. I will test that again now to make sure, but I would imagine they sent me a borked component.
It is difficult to see how the display can be causing a problem, especially if you are using 10kΩ resistors in series with each LED segment.
 

Thread Starter

Lawrence H

Joined May 6, 2019
98
It is difficult to see how the display can be causing a problem, especially if you are using 10kΩ resistors in series with each LED segment.
Right. Any other hunches on what might cause it? If it's a pin on the arduino, it is on of the pins from A to DP.

I got my LEDs set up now, so I will run that for a while and see what happens. I'll give it a good 200 loops, and then I will go back to the display and remove a partition or part of a digit form the code and wiring one at a time.
 

djsfantasi

Joined Apr 11, 2010
9,237
I haven’t seen anywhere in your code where you are writing to the displays a-g.

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
Are you using the serial monitor at all?

Personally, I avoid using pins 2-3 because they are assigned by default to the USB connection. And if there’s any data being passed to/from the PC/Arduino, it will “mess up” any other use of pins 2-3. It’s just easier not to use them.

Disconnect them from the display and run a test, knowing that the a & b segments should not show anything.
 

Thread Starter

Lawrence H

Joined May 6, 2019
98
I haven’t seen anywhere in your code where you are writing to the displays a-g.



Are you using the serial monitor at all?

Personally, I avoid using pins 2-3 because they are assigned by default to the USB connection. And if there’s any data being passed to/from the PC/Arduino, it will “mess up” any other use of pins 2-3. It’s just easier not to use them.

Disconnect them from the display and run a test, knowing that the a & b segments should not show anything.
I'll try that, and yes the serial monitor is running, and Arduino is writing something into the monitor at the end of each loop but otherwise it stays dormant.

I'll be right back.
 

Thread Starter

Lawrence H

Joined May 6, 2019
98
The LED's also go crazy, but it happened after loop 176. I let it run for a while to make sure, which was a good thing. So we can rule out that it's a problem with the display. I will use the LEDs to test this from now on.
 

ericgibbs

Joined Jan 29, 2010
21,442
hi Lawrence,
If you cannot post a circuit diagram, can you at least post a good quality photo of the project so that we can check for other possible problems.?

Also, what is the power supply.?
E
 

Thread Starter

Lawrence H

Joined May 6, 2019
98
Do you have another Arduino board you can test?
Unfortunately no. I ordered a few nanos about a week ago and one more UNO board yesterday as to have backups. However, I removed the serial monitor from the code and am now running the LEDs. It seems to be working ok, at least for now. I think I tested this without the prints to the serial monitor, but I left the port open. Now I didn't even open pr begin the monitor process.

So it would seem that all the pins work fine, at least by themself. Once more pins on the board are being used it might derp out.

I was scared I broke it and since I am now very excited about it it would suck to have broken it so early. I will come back in a about 20 minutes. If the code is still running successfully after that, then it was almost definitely about opening the serial port while using a lot of the pins either at the same time, or just having a lot of them being active.
 

Thread Starter

Lawrence H

Joined May 6, 2019
98
hi Lawrence,
If you cannot post a circuit diagram, can you at least post a good quality photo of the project so that we can check for other possible problems.?

Also, what is the power supply.?
E
I did one better. Here is a short video of the program running using LEDs, and it is still working. This would hint at the problem being with not only printing values to the serial port, but simply having the port open.


The yellow LEDs simulate the current digit that is being powered, in this case when the yellow LED is off, that means that the corresponding digit is powered.

Then the blue and red digits represent the phases of a single digit. There is no color schematic with the blue and red LEDs, I used the ones I had available. The LEDs are also in order.
 

Thread Starter

Lawrence H

Joined May 6, 2019
98
I had the LED loop running for the longest time, and it was fine. I now changed to the display, and it goes crazy again. I am at a loss. The only differences between the display setting and the LED setting is, that with the LEDs there is a ground wire, and it is possible that some faulty wire is not used. However, it went crazy with the LEDs as well, and it stopped after I stopped using the serial monitor.

I am at a loss now, but definitely not ready to give up. I want to find this issue so I know I can avoid it in the future.
 
Top