2

I want to use 2 "displays" with 4 digits. The displays are common cathodes with cathode transistors connected to the digits, as the figure: enter image description here The segments of both displays are connected together on the digital pins. The problem is that I tried to use some libraries for 7 segment displays and they worked with only one 4 digit display, but when I connected the second display, did not display the numbers correctly. The numbers that will be written are integers and I'm using mega 2560 R3.

Here are my attempts:

#include "SevSeg.h"
byte digitPins_1[] = {29, 30, 31, 33};//Digits pins
byte digitPins_2[] = {25, 26, 27, 28};
byte segmentPins[] = {38, 39, 40, 41, 42, 43, 44, 46}; //segment pins
SevSeg disp1;
SevSeg disp2;

void setup() {
disp1.begin(P_TRANSISTORS, 4, digitPins_1, segmentPins);
disp2.begin(P_TRANSISTORS, 4, digitPins_2, segmentPins);
disp1.setBrightness(20);
disp2.setBrightness(20);
}

void loop() { 
disp1.setNumber(8888, 0);
disp1.refreshDisplay();
disp2.setNumber(1111, 0);
disp2.refreshDisplay();
}

or using another lib:

#include <SevenSeg.h>
SevenSeg disp1(38,39,40,41,42,43,44);//segment pins
SevenSeg disp2(38,39,40,41,42,43,44);
int digitPins1[4]={29,30,31,33};//digitpins
int digitPins2[4]={25,26,27,28};

void setup() {
disp1.setDigitPins(4,digitPins1);
disp2.setDigitPins(4,digitPins2);
disp1.setDigitDelay(1600);//time delay 
disp2.setDigitDelay(1600);
disp2.setActivePinState(HIGH,HIGH);//seg active HIGH, digit active HIGH
disp1.setActivePinState(HIGH,HIGH);
}

void loop() { 
disp1.write(8888);
disp1.clearDisp();
disp2.write(1111);
disp2.clearDisp();
}
  • Check the library code for what would happen if you use the same segments pins. Also add a short delay between write-clearDisp. – Mikael Patel Jan 7 '17 at 1:04
  • How are your segment lines driven? If driven directly by ATmega pins instead of through a transistor, 8 segments at about 8 mA each is way too much; 4 at 8 mA might have worked ok, without 8 such working – James Waldby - jwpat7 Jan 7 '17 at 1:39
  • Why are you making two instances of the class when one instance "Supports arbitrary number of digits and multiple displays"? See: Arduino SevenSeg v1.2 – Nick Gammon Jan 7 '17 at 3:31
  • Because on every 4-digit display I would like to write a different variable at different times in my program. The segment lines are connected directly to the Arduino, only with a 220 ohm resistor, I'm going to change that. – Alecrim Jan 7 '17 at 9:46
2

The code instantiates two instances of the SevSeg class. This may or may not work. Really depends on if the class uses any resources are not meant to be shared between multiple instances of that class. For instance, it is unlikely that one hardware timer can be used for more than one purpose at a time.

But the code continues on to use the same (anode) pin resources for both instances of the class. This is likely not going to work.

Apologies for being vague using qualifier like "unlikely" instead of simply stating that it will not work. Truth is, one might be able to write a class that can deal with multiple instances of its self. But it would be very difficult and a far more complex programming task than to simply use one instance for all 8 digits.

In case there is a question as to the maximum number of digits supported for one instance of the SevSeg class, this line is in the one of the SevSeg header files:

#define MAXNUMDIGITS 8 // Can be increased, but the max number is 2^31
1

Why do you feel you need to multiplex two displays? What is wrong with just having one display of 8 digits? They don't have to be physically together, and it's entirely up to you what you display on each character of the display.

  • I think it would not make any difference for me to use an 8-digit display, initially it just seemed easier to use 2 different ones. – Alecrim Jan 7 '17 at 11:10
1

As the answers suggested, it is better to make a single display with 8 digits. But if anyone needs 2, here is my solution:

As suggested, I checked if the library supported, and the solution was to only increase the delay on each digit.

#include <SevenSeg.h>
SevenSeg disp1(38,39,40,41,42,43,44);//segment pins
SevenSeg disp2(38,39,40,41,42,43,44);
int digitPins1[4]={29,30,31,33};//digitpins
int digitPins2[4]={25,26,27,28};

void setup() {
disp1.setDigitPins(4,digitPins1);
disp2.setDigitPins(4,digitPins2);
disp1.setDigitDelay(4000);//time delay 
disp2.setDigitDelay(4000);
disp1.setDutyCycle(10);//decrease the duty cycle
disp2.setDutyCycle(10);
disp2.setActivePinState(HIGH,HIGH);//seg active HIGH, digit active HIGH
disp1.setActivePinState(HIGH,HIGH);
}

void loop() { 
disp1.write(8888);
disp1.clearDisp();
delay(1);// don't need
disp2.write(1111);
disp2.clearDisp();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.