SevSegShift library

I'm trying to learn to use the SevSegShift library.

I currently have a single digit 7seg display (5161BS) connected to an Uno via a 74HC595 shift register. (I've had the display working properly without using the library.)
I can't figure out what values to put in the digitPins[] array.

The values in the example on github are ...

  byte digitPins[] = {8+2, 8+5, 8+6, 2};      // of ShiftRegister(s) | 8+x (2nd Register)

... for a 4 digit display and 2 shift registers.
I've tried values from 1-16 (the 595 has 16 pins) and none result in anything meaningful being displayed on the 7-seg.
Does that make sense?

Is this library capable of outputting to a single display, and if so, what value(s) should digitPins[] hold?

FWIW I currently have the segmentPins[] array ppopulated as follows ...

byte segmentPins[] = {15, 1, 2, 3, 4, 5, 6, 7};

... which, as I understand it, means 15 = segment A and 1-6 = B to G and DP on pin 7.

Additionally, can this library be used to drive multiple 7-seg displays, each with their own respective 595?

You have made 62 posts on the forum now. You know how to post code fragments. You know how to post links. That's great. But now you really need to read the forum guide, understand and follow the other advice written there. There's no way we can help you from the above. That's why the forum guide was written. Not to humiliate you or anyone, just to give people a chance of helping you.

My grovelling apoligies. I take your point entirely.
Considering the nature my the question, and the code involved, I honestly don't think posting more of it will be any help whatsoever, unless someone has explicit knowledge of the library. But WTF do I know?!
I hoped someone on the LED board could offer some useful insight based on experience of the library.

(I hope this isn't too much code.)

#include "SevSegShift.h"

#define SHIFT_PIN_DS   10 /* Data input PIN */
#define SHIFT_PIN_STCP 11 /* Shift Register Storage PIN */
#define SHIFT_PIN_SHCP 12 /* Shift Register Shift PIN */

SevSegShift sevseg(SHIFT_PIN_DS, SHIFT_PIN_SHCP, SHIFT_PIN_STCP); //Instantiate a seven segment controller object (with Shift Register functionality)

void setup() {
  byte numDigits = 1;
  byte digitPins[] = {8+2, 8+5, 8+6, 2}; // of ShiftRegister(s) | 8+x (2nd Register)
  byte segmentPins[] = {15, 1, 2, 3, 4, 5, 6, 7}; // of Shiftregister(s) | 8+x (2nd Register)
  bool resistorsOnSegments = true; // '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 = true; // Use 'true' if your decimal point doesn't exist or isn't connected. Then, you only need to specify 7 segmentPins[]

  sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments,
  updateWithDelays, leadingZeros, disableDecPoint);
}

void loop() 
{
  sevseg.setChars("a");
}

Less than 20 lines of code? Of course it's not too long. Where is your schematic?

Thanks for your patience.

Thanks for posting that.

You are missing a 0.1uF bypass cap for the shift register. Also the OE pin is floating and should be grounded.

Data sheet for the display.

The forward voltage of the segments is 1.8V, so there will be 3.2V across your current limiting resistors, so the current flowing through them all be 3.2/330 = 9.7mA. With 7 segments lit (DP not connected) that will be 67mA total and the limit for 74hc595 is 70mA. So well done, that's fine.

I can't figure out what values to put in the digitPins[] array.

You don't have any pins connected to digits, only segments. Your digit common anode pin is connected to 5V. So there are no values to put in the array. The question then is, will the library cope with that? Its not clear from the GitHub readme if it can accept that. The library is probably intended to drive multi-digit displays by multiplexing them. You have only a single digit. So try leaving the array empty. If that does not work, try putting a single dummy value in the array (for example 7 because you are not using the Q7 pin on the SR).

I've tried values from 1-16 (the 595 has 16 pins)

The numbers you put in the arrays don't correspond to the physical pin numbers of the '595 chip. They should be 0 to 7 corresponding to the Q0 to Q7 output pins.

Yeah, I'd already worked most of that out, and already tried what you suggested (with the exception of the cap and OE). But thanks for tyring to help.

You got these swapped around:

#define SHIFT_PIN_STCP 12 /* Shift Register Storage PIN */
#define SHIFT_PIN_SHCP 11 /* Shift Register Shift PIN */

Its working for me. Here is the code:

#include "SevSegShift.h"

#define SHIFT_PIN_DS   10 /* Data input PIN */
#define SHIFT_PIN_STCP 12 /* Shift Register Storage PIN */
#define SHIFT_PIN_SHCP 11 /* Shift Register Shift PIN */

SevSegShift sevseg(SHIFT_PIN_DS, SHIFT_PIN_SHCP, SHIFT_PIN_STCP); //Instantiate a seven segment controller object (with Shift Register functionality)

void setup() {
  byte numDigits = 1;
  byte digitPins[] = {7}; // of ShiftRegister(s) | 8+x (2nd Register)
  byte segmentPins[] = {4, 5, 6, 1, 0, 3, 2}; // of Shiftregister(s) | 8+x (2nd Register)
  bool resistorsOnSegments = true; // '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 = true; // Use 'true' if your decimal point doesn't exist or isn't connected. Then, you only need to specify 7 segmentPins[]

  sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments, updateWithDelays, leadingZeros, disableDecPoint);
}

void loop()
{
  sevseg.setChars("0");
  sevSegDelay(500);
  sevseg.setChars("1");
  sevSegDelay(500);
  sevseg.setChars("2");
  sevSegDelay(500);
  sevseg.setChars("3");
  sevSegDelay(500);
  sevseg.setChars("4");
  sevSegDelay(500);
  sevseg.setChars("5");
  sevSegDelay(500);
  sevseg.setChars("6");
  sevSegDelay(500);
  sevseg.setChars("7");
  sevSegDelay(500);
  sevseg.setChars("8");
  sevSegDelay(500);
  sevseg.setChars("9");
  sevSegDelay(500);
}

void sevSegDelay(unsigned long period) {
  unsigned long startTime = millis();
  while (millis() - startTime < period) sevseg.refreshDisplay();
}

NOTE: I've changed the segment pins to make connection easier on my breadboard. Also, it does work with an empty digit array.

idrisdraig:
can this library be used to drive multiple 7-seg displays, each with their own respective 595?

No, I'm pretty sure not. If driving multiple digits, it expects to multiplex them. If you do that, you will need to increase the value of the series resistors to avoid exceeding the 35mA per pin limit of the '595. Or add a pnp transistor (e.g. bc327 with 1K base resistor) to drive each digit's common anode.

Looks like the STCP and SHCP were indeed the wrong way around. (Don't I feel like a ******! :astonished: )
Thanks for your help and patience.

So is it working for you now?

Yes thanks.
The problem was compounded by one dodgy wire between the shift register and the 7-seg, which was difficult to spot when the 7-seg elements were giberish, but it's all sorted now.