Digital Display goes Crazy

MrChips

Joined Oct 2, 2009
34,817
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.
No. That is not how AAC forums work.
Posts are made in chronological order. If you make a significant edit then it make all the subsequent helpers look like fools for posting wrong information.

Again, I repeat, do not change the content of your posts except for minor spelling errors.
If you made a mistake then admit it and move on.
If you want to make a correction or addendum then make it at the bottom of the post with the heading Edit:.
 

Thread Starter

Lawrence H

Joined May 6, 2019
98
I don't think it matters if some people wrongly think that wrong suggestions are from fools when I think everyone with half a brain knows that it takes time to reach a solution. There are 7 pages worth of data here now, and if the solution would have been as easy as "Add this resistor here", then it is only sensible to have the solution in the first post to save everyone some time. I also didn't change anything in the posts, I added to the front of the post the solution that worked for hours.

Here is what I am doing now.

I have six LEDs attached to the Arduino. Each have a 10K resistor so they won't blind me. They all go to a common ground on the Arduino. They use pins from 3 to 8. The Arduino is disconnected from the PC and is using an external 12V power supply. I uploaded the code, unplugged the device from the PC, and then hit the reset button to reset the Arduino. The code blinks all the LEDs in two different loops and is running right now.

Here is the code:

Code:
///Six Led Stress Test

byte pinA = 3;
byte pinB = 4;
byte pinC = 5;
byte pinD = 6;
byte pinE = 7;
byte pinF = 8;

byte pinMax = pinA + 6;

unsigned int stepCount = 0;

unsigned int i = pinA;

byte wait = 150;

void loop1()
{
 
  for(i = pinA; i < pinMax; i ++) //Set Everything to low
  {
   digitalWrite(i, LOW);
   stepCount ++; //Add this to the end of all for loops
  }
  for (i = pinA; i < pinMax; i ++)
  {
    digitalWrite(i, HIGH);
    delay(wait);
    stepCount ++;
  }
  for (i = pinA; i < pinMax; i ++)
  {
    digitalWrite(i, LOW);
    delay(wait);
    stepCount ++;
  }
}

void loop2()
{
 
  for(i = pinA; i < pinMax; i ++) //Set Everything to low
  {
   digitalWrite(i, LOW);
   stepCount ++; //Add this to the end of all for loops
  }
  for (i = 0; i < pinMax; i ++)
  {
    digitalWrite(pinA, HIGH);
    digitalWrite(pinB, HIGH);
    digitalWrite(pinC, HIGH);
    digitalWrite(pinD, HIGH);
    digitalWrite(pinE, HIGH);
    digitalWrite(pinF, HIGH);
    delay(wait);
    digitalWrite(pinA,LOW);
    digitalWrite(pinB,LOW);
    digitalWrite(pinC,LOW);
    digitalWrite(pinD,LOW);
    digitalWrite(pinE,LOW);
    digitalWrite(pinF,LOW);
    delay(wait);
  }
}

void setup() {
  pinMode(pinA, OUTPUT);
  pinMode(pinB, OUTPUT);
  pinMode(pinC, OUTPUT);
  pinMode(pinD, OUTPUT);
  pinMode(pinE, OUTPUT);
  pinMode(pinF, OUTPUT);
}

void loop() {
  //loop1();
  loop1();
  loop2();

  ///Finalize
  stepCount = 0; //For debugging, reset here for now
}
This code has a couple of loops that it goes through to use all the LEDs. I will be back once it goes nuts.
 

Thread Starter

Lawrence H

Joined May 6, 2019
98
It's been 5 hours and it seems to be going strong. Should I still keep it running for the day? I don't think I need to go anywhere too far from home tonight.

I think it went crazy just as I was starting it off when I was still plugged in with the USB cable. Before I had the USB plugged in but I controlled the power but not the data flowing into the Arduino. This would mean that at least one reason for this issue is having any connection to the PC.
 

MrChips

Joined Oct 2, 2009
34,817
As promised, here is the new test code for displaying 0-9 on a single digit, with RXD and TXD (PD0 and PD1) reserved for serial communications. Output to segment G has been moved to Arduino Uno pin-8 (PB0). Use 1k-5kΩ series resistor on each of the seven segments.

In my next example I will show how to multiplex the four digits.

Code:
const int ledPin =  LED_BUILTIN;  // the number of the LED pin
const int segG_Pin =  8;

byte segments[] = {0b11111100, 0b00011000, 0b01101100, 0b00111100, 0b10011000, 0b10110100, 0b11110000, 0b00011100, 0b11111100, 0b10011100};
byte segmentG[] = { 0, 0, 1, 1, 1, 1, 1, 0, 1, 1};
byte i = 0;

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

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