Question about using 3 shift registers

Hello,

I want to light any sequence of 24 LEDs. I've connected 3 SN74HC595N shift registers and am able to light which ever LEDs I desire by setting my variable "leds" to the corresponding binary number (0B000000001111111100000000 will light up the middle 8 LEDs).

My issue is the last 8 LEDs light up (half as bright) when the first register's LEDs are on(0b111111110000000000000000), the second register's LEDs are on (0B000000001111111100000000) or both 1st and 2nd register's LEDs are on (0B111000001111100000000).

I don't understand why and how to prevent this.

Thank you,

Michael

/*
  74hc595
  1 Q2
  2 Q3
  3 Q4
  4 Q5
  5 Q6
  6 Q7
  7 Q8
  8 GND
  9 DAISY CHAIN TO NEXT 14
  10 +5v
  11 CLOCK
  12 LATCH
  13 GND
  14 DATA
  15 Q1
  16 +5
*/
#include <stdio.h>

int latchPin = 8; 
int clockPin = 13; 
int dataPin = 11;
unsigned long leds = 0;    // Variable to hold the pattern of which LEDs are currently turned on or off

int Hr = 0;
int Min = 0;
int Hleds = 0;
int Mleds = 0;

void setup()
{
  // Set all the pins of 74HC595 as OUTPUT
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  Serial.begin(9600);
}

void loop()
{
    leds = 0B111111110000000000000000;
  updateShiftRegister();
}


void updateShiftRegister() // Since only 3 registers, need only 24 bytes
{
  unsigned int leds16 = int(leds);
  unsigned int leds32 = int(leds >> 8);
  byte low16LED = lowByte(leds16);
  byte high16LED = highByte(leds16);
  byte low32LED = lowByte(leds32);
  byte high32LED = highByte(leds32);
  digitalWrite(latchPin, LOW); 
  shiftOut(dataPin, clockPin, LSBFIRST, low16LED); // 3rd register
  shiftOut(dataPin, clockPin, LSBFIRST, high16LED);// 2nd register
  shiftOut(dataPin, clockPin, LSBFIRST, high32LED);// 1st register
  digitalWrite(latchPin, HIGH);
}

Could you draw a schematic ?
The SN74HC595N might not be capable to drive the leds. The TPIC6B595 is made for leds: https://www.adafruit.com/product/457

Could you show a photo ?
Breadboards have often bad contacts and jumper wires can be broken.

Please don't include stdio.h.
Which Arduino board do you use ?
The binary notation for the C language is 0b111111110000000000000000.
There are variable types for a specific number of bits. I suggest to use "uint32_t" for 32 bits.
The shifting together with the bytes and lowByte() and highByte() are confusing.

The shiftOut shifts a byte. I think this code shows better what it does:

  shiftOut(dataPin, clockPin, LSBFIRST, (byte) (leds >> 0)); // 3rd register
  shiftOut(dataPin, clockPin, LSBFIRST, (byte) (leds >> 8)); // 2nd register
  shiftOut(dataPin, clockPin, LSBFIRST, (byte) (leds >> 16)); // 1st register

Do you know Wokwi ? https://wokwi.com/
You could make your project in Wokwi to verify that the code and the circuit should work.

I think that this shift register lacks proper GND or Vcc connection. Take your DMM and check that.

I think

unsigned int leds32 = int(leds >> 8);

should be

unsigned int leds32 = int(leds >> 16);

and

shiftOut(dataPin, clockPin, LSBFIRST, high32LED);// 1st register

should be

shiftOut(dataPin, clockPin, LSBFIRST, low32LED);// 1st register

Thank you, Koepel!

I had never heard of Wokwi . Will check it out.

Thanks for this suggestion:
shiftOut(dataPin, clockPin, LSBFIRST, (byte) (leds >> 0)); // 3rd register
shiftOut(dataPin, clockPin, LSBFIRST, (byte) (leds >> 8)); // 2nd register
shiftOut(dataPin, clockPin, LSBFIRST, (byte) (leds >> 16)); // 1st register

So far, I've not solved the last LEDs flickering when not turned on.

Michael

Thank you, DrDiettrich!

I've checked my connections and even replaced the IC with another, but still get the flickering. The appropriate LEDs light up as called for in the problem so I really don't suspect it to be a wiring issue.

My guess is it is something in the program that I just haven't found what stupid thing I'm doing that is wrong.

Thank you for your help.

Michael

Thank you, PaulRB.

I got the appropriate LEDs to light up as needed. Still need to figure out why the 3rd register's LEDs flicker when they are suppose to be turned off.

I appreciate your help.

Michael

Please describe your wiring, or provide a photo. The most likely answers for poor visibility at the end of a string are:

  1. you're not always writing to all 3 registers, so one isn't receiving the same data as frequently as the others
  2. your power wiring (+5 and GND) to the '595's is high resistance, resulting in low voltage at the end of the run.

To test these possibilities, reverse the data wire only, such that the third register is first in line for data but still last in line for power. Did the problem move to the other register or not? You've got a data problem if it did, a power problem if it didnt.

Problem solved!

Who would have thunk you need to connect the LATCH pin to register 3?? I checked my wiring 3 or 4 times.

TOLD YOU ALL IT WAS SOMETHING STUPID I WAS (OR WAS NOT) DOING!!

Thanks again to everyone!

Michael

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.