3 digit 7 segment display

Hello.

I have to make a counter which counts from 0 to 999 on a 3 digit multiplexed 7 segment display.
I did the necessary connections on the breadboard and arduino board, I wrote the code and it's working but only one problem... While it counts the 3 digits are flickering very fast but it's noticeable.. I don't know how to solve this .. I've changed the void loop() many times I put delay functions but it's not working..I need to solve this today... what can I do for that ...

I've attached the code I'm using.

Thank you!

Counter_7_segment.ino (1.42 KB)

functions.ino (292 Bytes)

Hi,

Can you post that code in a your message rather than as an attachment? Many like me will be reading on smartphone or tablet, not at pc, and be unable to open the attachments. Use code tags so it looks like......this

Also can you give a schematic, or a link to one you are following? There are several ways to make the connections.

Paul

Sure.. Sorry ..

#define ontime 3000
#define A 2
#define B 3
#define C 4
#define D 5
#define E 6
#define f 7
#define G 8
#define DP 9

#define CC1 10
#define CC2 11
#define CC3 12



#define numbersegments { \
  {1,1,1,1,1,1,0,0},\
  {0,1,1,0,0,0,0,0},\
  {1,1,0,1,1,0,1,0},\
  {1,1,1,1,0,0,1,0},\
  {0,1,1,0,0,1,1,0},\
  {1,0,1,1,0,1,1,0},\
  {1,0,1,1,1,1,1,0},\
  {1,1,1,0,0,0,0,0},\
  {1,1,1,1,1,1,1,0},\
  {1,1,1,0,0,1,1,0}\
}


byte numbers[10][8] = numbersegments;

const int segments[8] = { A, B, C, D, E, f, G, DP };

void setup() {
  Serial.begin(9600);
  pinMode(A, OUTPUT);
  digitalWrite(A,LOW);
  pinMode(B, OUTPUT);
  digitalWrite(B,LOW);
  pinMode(C, OUTPUT);
  digitalWrite(C,LOW);
  pinMode(D, OUTPUT);
  digitalWrite(D,LOW);
  pinMode(E, OUTPUT);
  digitalWrite(E,LOW);
  pinMode(f, OUTPUT);
  digitalWrite(f,LOW);
  pinMode(G, OUTPUT);
  digitalWrite(G,LOW);
  pinMode(DP, OUTPUT);
  digitalWrite(DP,LOW);

  pinMode(CC1, OUTPUT);
  digitalWrite(CC1,HIGH);
  pinMode(CC2, OUTPUT);
  digitalWrite(CC2,HIGH);
  pinMode(CC3, OUTPUT);
  digitalWrite(CC3,HIGH);

  
}

void loop() {
  for (int digit1=0; digit1 < 10; digit1++) {
    for (int digit2=0; digit2 < 10; digit2++) {
      for (int digit3=0; digit3 < 10; digit3++){
       
          for(int t=0; t<20;t++){
            
            setsegments(digit1,CC1,ontime);
             setsegments(digit2,CC2,ontime);
             setsegments(digit3,CC3,ontime);
           
        }
      }
    }
  }
}

The function for "setsegments" is this:

void setsegments(int number, int digit,int time){
  for (int seg = 0; seg < 8; seg++){
    if (numbers[number][seg]==1) {digitalWrite(segments[seg],HIGH);}
    else {digitalWrite(segments[seg],LOW);}
  }
  digitalWrite(digit,LOW);
  delayMicroseconds (time);
  digitalWrite(digit,HIGH);

}

I don't know how to make the schematic but I made the connections between the breadboard and arduino exactly like the picture I've attached.. except I have a display with 3 digits so the pin 6 (common cathode for digit 4) connected to the 13 input of the arduino is out of the picture.

Hi, looks ok at first glance. What if you set ontime to 1000?

I've tried that... still the same ... I can change the ontime to value "1" and is still flickers...
It could be something wrong with the display?...

I've made a video to show how it flickers...

Ok, try this to see what happens. Change delayMicroseconds(1000) to delay(1000). This will slow down the multiplexing so much that each digit should stay on for a second each. Does each digit look steady for its one second? If so, reduce to 500, 250, 125, 64, 32, 16, 8, 4, 2. Does the flickering re-appear at some point?

I did that and yes... when I change delayMicroseconds to delay(1000) each digit stay lit for 1 second, and I've reduced the time to 500,250... until 1 and still the same flicker ...I can't tell if it's faster or slower than before but it's very noticeable like before.

This is strange. When you reduce the delay, at what point does the flickering appear?

I don't think I understand... the flicker that I have is because the delay between reading the segments is too big, so as long as I put a smaller delay the flicker gets faster and at some point it should be fast enough so the human eye cannot perceive it anymore, but in this case if I put the smallest delay possible (1 microsecond) it's still noticeable... when it shouldn't be.. so I don't understand the question.. it doesn't reaper at some point.. it just get's faster while I diminish the delay.

Right, ok. I can see some parts of the sketch could be a little more efficient, but I can't see anything that would cause flickering on that scale.

Try disconnecting 2 of the 3 cathode connections. Does the remaining digit still flicker?

Reconnect the cathodes and disconnect half the anodes. Any better?

(I'm just wondering if the Arduino is having to source/sink too much current.)

Maybe these old threads of mine will help in some way...

http://forum.arduino.cc/index.php?topic=188135.0

http://forum.arduino.cc/index.php?topic=263461.0

Ok, I'll try this soon... it's really wierd this is happening.. I saw many sketches of 7 segment display with transistors connected to the cathodes.. you think this will help?

bogdan3220:
I saw many sketches of 7 segment display with transistors connected to the cathodes.. you think this will help?

It might just be the clue - if overloading the outputs is causing odd behaviour inside the MCU.

PaulRB:
Right, ok. I can see some parts of the sketch could be a little more efficient, but I can't see anything that would cause flickering on that scale.

Try disconnecting 2 of the 3 cathode connections. Does the remaining digit still flicker?

Reconnect the cathodes and disconnect half the anodes. Any better?

(I'm just wondering if the Arduino is having to source/sink too much current.)

Yes, the remaining digit still flicker when I disconnect 2 cathodes... the same for half the anodes.

I connected the transistors and I don't have the flicker anymore but the code doesn't behave the same .. all the numbers are shown on each display simultaneously... how can I change the code?

A proper diagram - or perhaps more critically, a very clearly taken photo with perfect focus of your whole lash-up - would be in order at this point. And the new code.

I uploaded the scheme with the transistors... I'm using a 3 digit display but I couldn't find it in this program so I used a 4 digit display... the last 2 pins of the display from up and down are not used.

P.S. I forgot to connect the emitter of the transistors to the ground.... sorry

The code is this:

#define A 2
#define B 3
#define C 4
#define D 5
#define E 6
#define f 7
#define G 8
#define DP 9

#define CC1 10
#define CC2 11
#define CC3 12



#define numbersegments { \
  {1,1,1,1,1,1,0,0},\
  {0,1,1,0,0,0,0,0},\
  {1,1,0,1,1,0,1,0},\
  {1,1,1,1,0,0,1,0},\
  {0,1,1,0,0,1,1,0},\
  {1,0,1,1,0,1,1,0},\
  {0,0,1,1,1,1,1,0},\
  {1,1,1,0,0,0,0,0},\
  {1,1,1,1,1,1,1,0},\
  {1,1,1,0,0,1,1,0}\
}


byte numbers[10][8] = numbersegments;

const int segments[8] = { A, B, C, D, E, f, G, DP };

void setup() {
  Serial.begin(9600);
  pinMode(A, OUTPUT);
  digitalWrite(A,LOW);
  pinMode(B, OUTPUT);
  digitalWrite(B,LOW);
  pinMode(C, OUTPUT);
  digitalWrite(C,LOW);
  pinMode(D, OUTPUT);
  digitalWrite(D,LOW);
  pinMode(E, OUTPUT);
  digitalWrite(E,LOW);
  pinMode(f, OUTPUT);
  digitalWrite(f,LOW);
  pinMode(G, OUTPUT);
  digitalWrite(G,LOW);
  pinMode(DP, OUTPUT);
  digitalWrite(DP,LOW);

  pinMode(CC1, OUTPUT);
  digitalWrite(CC1,HIGH);
  pinMode(CC2, OUTPUT);
  digitalWrite(CC2,HIGH);
  pinMode(CC3, OUTPUT);
  digitalWrite(CC3,HIGH);

  
}

void loop() {
  for (int digit1=0; digit1 < 10; digit1++) {
    for (int digit2=0; digit2 < 10; digit2++) {
      for (int digit3=0; digit3 < 10; digit3++){
       
          for(int t=0; t<20;t++){
            
            setsegments(digit1,CC1,1);
             setsegments(digit2,CC2,1);
             setsegments(digit3,CC3,1);
           
        }
      }
    }
  }
}

with function of setsegments:

void setsegments(int number, int digit,int time){
  for (int seg = 0; seg < 8; seg++){
    if (numbers[number][seg]==1) {digitalWrite(segments[seg],HIGH);}
    else {digitalWrite(segments[seg],LOW);}
  }
  digitalWrite(digit,LOW);
  delayMicroseconds (1);
  digitalWrite(digit,HIGH);

}

What's happened is that the npn transistors have inverted the logic, compared to using the bare Arduino pins. Correct for this by making this change:

  digitalWrite(digit,HIGH);
  delayMicroseconds (1);
  digitalWrite(digit,LOW);

You should be able to increase the delay back to 1000 or 3000 without flicker now?

Indeed, making that change turned the counter back to normal ... it's counts like before putting the transistors but unfortunately with the same flicker ....

Hmmm... this is a knotty one!

Later this week if I get time I will try to mimic your circuit and run your sketch.

Have you actually posted the whole sketch? I noticed you posted it in two sections earlier. Is that the whole thing?