2

I have a question regarding the use of SevSegShift library. I followed the example properly and tested it to see if it works. It was able to power up the seven segments and light up the whole LEDs (even the decimal) but it's not showing the output I want to show.

Based on the code below, I want to show the number 500 but it does not. Even tried sevsegshift.setChars("abcd"), no change.

This is my code:

#include <SevSegShift.h>

#define SHIFT_PIN_SHCP 6
#define SHIFT_PIN_STCP 5
#define SHIFT_PIN_DS   4

SevSegShift sevseg(SHIFT_PIN_DS, SHIFT_PIN_SHCP, SHIFT_PIN_STCP, 1, true);

void setup() {
  byte numDigits = 4;
  byte digitPins[] = {9, 10, 11, 12}; // These are the PINS of the ** Arduino **
  byte segmentPins[] = {0, 1, 2, 3, 4, 5, 6, 7}; // these are the PINs of the ** Shift register **
  bool resistorsOnSegments = false; // 'false' means resistors are on digit pins
  byte hardwareConfig = COMMON_CATHODE; // See README.md for options
  bool updateWithDelays = false; // Default 'false' is Recommended
  bool leadingZeros = false; // Use 'true' if you'd like to keep the leading zeros
  bool disableDecPoint = true; // Use 'true' if your decimal point doesn't exist or isn't connected
  
  sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments, updateWithDelays, leadingZeros, disableDecPoint);
  sevseg.setBrightness(10);
}

void loop() {
  sevseg.setNumber(500);
  //delay(1000);
  sevseg.refreshDisplay(); // Must run repeatedly; don't use blocking code (ex: delay()) in the loop() function or this won't work right
}

This is my breadboard schematic down below.

Breadboard

(220 ohm resistors on the digit pins and the segment pins are connected to the shift register)

12
  • 2
    See the comment of the last statement. It says, don't use blocking code in the for loop e.g. delay() and one line above you use delay(). Hmmm, possibly ?! The shift register must be update very fast i guess. – Peter Paul Kiefer Nov 30 '20 at 11:12
  • @PeterPaulKiefer Thank you, that was an oversight on my part. Took out the delay() and still the same output :( – fireblazer10 Nov 30 '20 at 11:21
  • Did you connect +5V and Ground to the breadboard? Your schematic doesn’t show them. – StarCat Nov 30 '20 at 11:31
  • 1
    OK, for me this was the most obvious possibillity of failure. But there are more. A brightness of 10 seems very low to me (max is 100). If you have COMMON_ANODE LED-Bars but you have configured COMMON_CATHODEs this would invert the brightness. Dark is Bright and Bright is Dark. Take this together and i might result in your observations. And probably the wiring is not correct. If you add a picture to the post we could check it. Btw. pin 12 can not provide PWM output (no ~ symbol), so it can not be used to regulate the brighness of the connected digit. – Peter Paul Kiefer Nov 30 '20 at 11:45
  • 1
    swap the digit selection pins – Juraj Nov 30 '20 at 11:57
3

Finally able to fix it with the help of @PeterPaulKiefer, I was able to find the problem. The problem is in the code itself (schematic is alright. No changes there) and this is the updated code.

#include <SevSegShift.h>

#define SHIFT_PIN_SHCP 6
#define SHIFT_PIN_STCP 5
#define SHIFT_PIN_DS   4

SevSegShift sevseg(SHIFT_PIN_DS, SHIFT_PIN_SHCP, SHIFT_PIN_STCP, 1, true);

void setup() {
  byte numDigits = 4;
  byte digitPins[] = {12, 11, 10, 9}; // These are the PINS of the ** Arduino **
  byte segmentPins[] = {0, 1, 2, 3, 4, 5, 6, 7}; // these are the PINs of the ** Shift register **
  bool resistorsOnSegments = false; // 'false' means resistors are on digit pins
  byte hardwareConfig = COMMON_ANODE; // See README.md for options
  bool updateWithDelays = false; // Default 'false' is Recommended
  bool leadingZeros = false; // Use 'true' if you'd like to keep the leading zeros
  bool disableDecPoint = false; // Use 'true' if your decimal point doesn't exist or isn't connected
  
  sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments, updateWithDelays, leadingZeros, disableDecPoint);
  sevseg.setBrightness(100);
}

void loop() {
  sevseg.setNumber(500);
  sevseg.refreshDisplay(); // Must run repeatedly; don't use blocking code (ex: delay()) in the loop() function or this won't work right
}

What changed:

  1. Turns out my 7-segment is COMMON_ANODE so I changed my hardwareConfig
  2. Set brightness to 100 (At this point, it shows the number in reverse but with a decimal point in each digit)
  3. Set disableDecPoint to false (At this point, the display is showing but in reverse but no more decimal point) reverse
  4. To fix this, I set the digitPins[] in reverse and it now shows the proper format Correct Output

Thank you so much Peter for helping me figure out what's wrong!

Also the LED Bar I use is 4-Digit 0.36" LED, 7-segments display, common-anode. (The link is to the shop I got it from)

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.