Afficheur 7 segments 4 digits

bonjour tout le monde,
je suis novice avec arduino et je bute sur un truc.

je souhaite faire un compteur avec 4 digits.
le câblage est bon mais lors de l’exécution du code les 4 digits restent allumés.

je vois que cela incrémente bien mais les chiffres se voient à peine.

je m’explique : les chiffres s’allume complètement, on voit un 8 avec point décimal.
lors du comptage le chiffre change mais je vois toujours le 8 affiché. un faible scintillement apparaît.

j’ai essayé de changer la valeur de " setBrightness " mais cela change rien .

quelqu’un pourrait me donner une idée ???

voici mon code :slight_smile:

#include “SevSeg.h”

SevSeg sevseg;

int pinA = 9;
int pinB = 8;
int pinC = 7;
int pinD = 6;
int pinE = 5;
int pinF = 4;
int pinG = 3;
int pinDP = 2;

int DIG1 = 13;
int DIG2 = 12;
int DIG3 = 11;
int DIG4 = 10;

void setup()
{
byte numDigits = 4; // Nombre de digits
byte digitPins[] = {13,12,11,10}; // digit de 1 a 4
byte segmentPins[] = {2, 3, 4, 5, 6, 7, 8, 9}; // Branchements des Pins

sevseg.begin(COMMON_ANODE, numDigits, digitPins, segmentPins);
sevseg.setBrightness(20);

pinMode(DIG1, OUTPUT); // pin 13
pinMode(DIG2, OUTPUT); // pin 12
pinMode(DIG3, OUTPUT); // pin 11
pinMode(DIG4, OUTPUT); // pin 10

pinMode(pinA, OUTPUT); // pin 9
pinMode(pinB, OUTPUT); // pin 8
pinMode(pinC, OUTPUT); // pin 7
pinMode(pinD, OUTPUT); // pin 6
pinMode(pinE, OUTPUT); // pin 5
pinMode(pinF, OUTPUT); // pin 4
pinMode(pinG, OUTPUT); // pin 3
pinMode(pinDP, OUTPUT); // pin 2

}

void loop()
{
// digitalWrite(DIG1, 0);
// digitalWrite(DIG2, 0);
// digitalWrite(DIG3, 0);
// digitalWrite(DIG4, 0);

static unsigned long timer = millis();
static int deciSeconds = 0;

if (millis() >= timer) {
deciSeconds++; // 100 milliSeconds = 1 seconde
timer += 100;
if (deciSeconds == 10000) { // Reset apres 1000 seconds
deciSeconds=0;
}
sevseg.setNumber(deciSeconds, 1);
}

sevseg.refreshDisplay();
}

You look to have a logic error. You are changing the display value every 100 milliseconds which will appear as a blur on the display

if (deciSeconds == 10000) { // Reset apres 1000 seconds
    deciSeconds=0;
}
sevseg.setNumber(deciSeconds, 1);

}

likely wants to be

if (deciSeconds == 100) { // Reset apres 1000 seconds
    deciSeconds=0;
    sevseg.setNumber(deciSeconds, 1);
}

}

which will display the time change once a second and thus be visible as a change rather than the blur you see with the 100 msec update. The 1000 second number will only change the time after about 15 minutes which is a little long for testing.

Peter

merci Peter,

j’ai essayé votre modification, mais cela ne change pas grand chose.
je vois un peu mieux le défilement des chiffres.

je vois les chiffres 1.2.3… mais je vois également le chiffre 8 et le point décimal qui s’affiche en même temps.
référence afficheur ----> SH5461AS

DIGIT 1 connecteur K1 branché sur pin 13
DIGIT 2 connecteur K2 branché sur pin 12
DIGIT 3 connecteur K3 branché sur pin 11
DIGIT 4 connecteur K4 branché sur pin 10

A branché sur pin 9
B branché sur pin 8
C branché sur pin 7
D branché sur pin 6
E branché sur pin 5
F branché sur pin 4
G branché sur pin 3
DP branché sur pin 2

OK, so we both look to be missing something here :slight_smile: . Lets try a test of just the hardware:

change

static int deciSeconds = 0;

to

static int deciSeconds = 1234; // display digits 1234

 // if (millis() >= timer) {
 //    deciSeconds++; // 100 milliSeconds = 1 seconde
 //     timer += 100;
 //     if (deciSeconds == 10000) { // Reset apres 1000 seconds
//         deciSeconds=0;
//      }
 
//  }

sevseg.setNumber(deciSeconds, 1);
sevseg.refreshDisplay();

}

So all that happens is that the library should display 1.234 (or 123.4, I’m not sure where it puts the decimal point :-)) on the display. If that doesn’t work then there is likely something wrong in the hardware setup and you should post the Fritzing sketch of your circuit (7th icon from the left on the reply tool bar) and I’ll see if I can see anything there. If that does work correctly then there is something wrong in the time calculation that we are both missing. The last seems perhaps the most likely if you are seeing digits, we just haven’t slowed it down enough yet for some reason.

Peter

Peter

j’ai modifié static int deciSeconds = 1234;
cela affiche que des 8 avec point décimal

je suis en train de faire le schéma sur FritzingSH5461AS.fzz (21.4 KB)

désolé j’avais oublié de mettre les résistances sur les sorties SH5461AS.fzz (21.6 KB)

Ah, your hardware isn’t quite correct. As it currently stands the brightness of the segments will change depending on how many of them are on at a time. You need to change to something like this:

with transistors driving the 4 digit selectors and current limiting resistors in each segment line. The transistor sinks current for however many segments are on at any one time (which your micro pin will have trouble doing) and the current limiting resistors in each segment line will limit the current (so you don’t burn out the segment with too much current as will happen if the segment connects directly to the transistor without the 470 ohm resistor to limit the current). I expect this will work better.

Peter

ok merci Peter pour votre aide.

je vais essayer ce câblage et la résistance de 470 ohms ainsi que des transistors.

je dois partir quelques jours en vacances je vous tiendrais au courant.

merci beaucoup
François.

bonjour Peter,
je viens de refaire le cablage avec les transistors et les résistances de 470ohms et 4.7 k ohms

cela n’a rien changé

Does just trying to write 1234 to the display (a couple of posts back) work correctly? The problem in a case like this is that either the hardware or the software could be wrong, so we want to verify one or the other (and hardware is usually easier). I’d next try using digital writes to the output pins to verify the hardware connections.

(all your port setup stuff)
digital_write(13,1)  // enable digit 1
void loop() { 
             digital_write(9,1)  // light segment A of the first digit)
}

This should light segment A of digit 1 (and nothing else). If that works try the other segments one at a time by changing the segment pin number from 8 to 2 one at a time to make sure only one (and the one you expect!) segment on one digit lights at a time (and correct any problems you find). Once the segments all work correctly go back to segment A (or just stay on the last segment) and change the digit pin to 12, 11, and 10 and make sure the next digit along lights (the segments are common so you don’t need to test them again). Once that all works you are sure the hardware is correct and that means there is something wrong with the software still or you will have found a hardware mistake that needs correcting and then things may work.

edit: the above is incomplete. You in fact need to set all the other
segment pins to 0 as in

digital_write(9,1)
digital_write(8,0)
digital_write(7,0)
digital_write(6,0)
digital_write(5,0)
digital_write(4,0)
digital_write(3,0)
digital_write(2,0)

and then change the one to a zero to move to the next segment. You may also need to change the parameters to the library because of the transistors being added.

Peter

1 Like

si je mes : static int deciSeconds = 1234
cela affiche que des 8

j’ai essayé autre chose.
j’ai fait une fonction pour déclarer tous les chiffres.

j’ai eteint les 3 DIGITS de droite, je laisse llumé le DIGIT de gauche

j’appelle la fonction avec un chiffre ( 4) cela affiche 4 sur le DIGIT 1

#include “SevSeg.h”

SevSeg sevseg;

int pinA = 2;
int pinB = 3;
int pinC = 4;
int pinD = 5;
int pinE = 6;
int pinF = 7;
int pinG = 8;
//int pinDP = 2;

int DIG1 = 12;
int DIG2 = 11;
int DIG3 = 10;
int DIG4 = 9;

void choix_numero(char number)

{
switch (number)

{
default:
// par défaut le 0 s’affiche
digitalWrite(pinA, HIGH);
digitalWrite(pinB, HIGH);
digitalWrite(pinC, HIGH);
digitalWrite(pinD, HIGH);
digitalWrite(pinE, HIGH);
digitalWrite(pinF, HIGH);
digitalWrite(pinG, LOW);
break;

case 1:

  digitalWrite(pinA, LOW);
  digitalWrite(pinB, HIGH);
  digitalWrite(pinC, HIGH);
  digitalWrite(pinD, LOW);
  digitalWrite(pinE, LOW);
  digitalWrite(pinF, LOW);
  digitalWrite(pinG, LOW);
  break;


case 2:
  digitalWrite(pinA, HIGH);
  digitalWrite(pinB, HIGH);
  digitalWrite(pinC, LOW);
  digitalWrite(pinD, HIGH);
  digitalWrite(pinE, HIGH);
  digitalWrite(pinF, LOW);
  digitalWrite(pinG, HIGH);
 break;

case 3:
  digitalWrite(pinA, HIGH);
  digitalWrite(pinB, HIGH);
  digitalWrite(pinC, HIGH);
  digitalWrite(pinD, HIGH);
  digitalWrite(pinE, LOW);
  digitalWrite(pinF, LOW);
  digitalWrite(pinG, HIGH);
  break;

case 4:
  digitalWrite(pinA, LOW);
  digitalWrite(pinB, HIGH);
  digitalWrite(pinC, HIGH);
  digitalWrite(pinD, LOW);
  digitalWrite(pinE, LOW);
  digitalWrite(pinF, HIGH);
  digitalWrite(pinG, HIGH);
  break;

case 5:
  digitalWrite(pinA, HIGH);
  digitalWrite(pinB, LOW);
  digitalWrite(pinC, HIGH);
  digitalWrite(pinD, HIGH);
  digitalWrite(pinE, LOW);
  digitalWrite(pinF, HIGH);
  digitalWrite(pinG, HIGH);
  break;

case 6:
  digitalWrite(pinA, HIGH);
  digitalWrite(pinB, LOW);
  digitalWrite(pinC, HIGH);
  digitalWrite(pinD, HIGH);
  digitalWrite(pinE, HIGH);
  digitalWrite(pinF, HIGH);
  digitalWrite(pinG, HIGH);
  break;

case 7:
  digitalWrite(pinA, HIGH);
  digitalWrite(pinB, HIGH);
  digitalWrite(pinC, HIGH);
  digitalWrite(pinD, LOW);
  digitalWrite(pinE, LOW);
  digitalWrite(pinF, LOW);
  digitalWrite(pinG, LOW);
 break;

case 8:
  digitalWrite(pinA, HIGH);
  digitalWrite(pinB, HIGH);
  digitalWrite(pinC, HIGH);
  digitalWrite(pinD, HIGH);
  digitalWrite(pinE, HIGH);
  digitalWrite(pinF, HIGH);
  digitalWrite(pinG, HIGH);
  break;

case 9:
  digitalWrite(pinA, HIGH);
  digitalWrite(pinB, HIGH);
  digitalWrite(pinC, HIGH);
  digitalWrite(pinD, LOW);
  digitalWrite(pinE, LOW);
  digitalWrite(pinF, HIGH);
  digitalWrite(pinG, HIGH);
  break;

case 0:
  digitalWrite(pinA, HIGH);
  digitalWrite(pinB, HIGH);
  digitalWrite(pinC, HIGH);
  digitalWrite(pinD, HIGH);
  digitalWrite(pinE, HIGH);
  digitalWrite(pinF, HIGH);
  digitalWrite(pinG, LOW);
  break;

}
}

void setup()
{
Serial.begin(9600);

byte numDigits = 4; // Nombre de digits
byte digitPins[] = {12,11,10,9}; // digit de 1 a 4
byte segmentPins[] = {2,3,4,5,6,7,8}; // Branchements des Pins

sevseg.begin(COMMON_ANODE, numDigits, digitPins, segmentPins);
sevseg.setBrightness(90);

pinMode(DIG1, OUTPUT); // pin 12
pinMode(DIG2, OUTPUT); // pin 11
pinMode(DIG3, OUTPUT); // pin 10
pinMode(DIG4, OUTPUT); // pin 9

pinMode(pinA, OUTPUT); // pin 2
pinMode(pinB, OUTPUT); // pin 3
pinMode(pinC, OUTPUT); // pin 4
pinMode(pinD, OUTPUT); // pin 5
pinMode(pinE, OUTPUT); // pin 6
pinMode(pinF, OUTPUT); // pin 7
pinMode(pinG, OUTPUT); // pin 8
//pinMode(pinDP, OUTPUT); // pin 2

}

void loop()
{
digitalWrite(DIG1, 1);
digitalWrite(DIG2, 0);
digitalWrite(DIG3, 0);
digitalWrite(DIG4, 0);

choix_numero(4);
//choix_numero(2);

//digitalWrite(9,1);
//digitalWrite(8,0);
//digitalWrite(7,0);
//digitalWrite(6,0);
//digitalWrite(5,0);
//digitalWrite(4,0);
//digitalWrite(3,0);
//digitalWrite(2,0);

static unsigned long timer = millis();
static int deciSeconds = 1234;

// if (millis() >= timer) {
// deciSeconds++; // 100 milliSeconds is equal to 1 deciSecond
// timer += 10;
// if (deciSeconds == 100) { // Reset to 0 after counting for 1000 seconds.
// deciSeconds=0;
/// }
sevseg.setNumber(deciSeconds, 1);
// }

sevseg.refreshDisplay();
}

You may need to change the

sevseg.begin(COMMON_ANODE, numDigits, digitPins, segmentPins);

COMMON_ANODE to N_TRANSISTORS to tell the library that you have transistors driving the digits (as the transistor adds an inversion so the library needs to set the pin to 1 rather than zero to enable the digit). It sounds like your hardware is wired correctly the problem is describing it to the library correctly (and the documentation I found isn’t that clear :slight_smile: ).

Peter