4 shift registers

Hi

I want to control 32 LEDs using shift registers but the bits I send through the shift registers don't go further then the second shift register. Can somebody please take a look at my code? I tried changing the shiftOut function but that didn't help. I'm using 74HC595 8-bit shift registers. Here's my code:

int masterClear = 13;
int clockPin = 12;
int latchPin = 11;
int outputEnable = 6;
int dataPin = 5;

byte dataCA;
byte dataRED;
byte dataBLUE;
byte dataGREEN;
byte dataArrayCA[8];
byte dataArrayRED[8];
byte dataArrayBLUE[8];
byte dataArrayGREEN[8];

void setup() {
pinMode(masterClear, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(latchPin, OUTPUT);
pinMode(outputEnable, OUTPUT);
pinMode(dataPin, OUTPUT);

dataArrayCA[0] = 0xFF;
dataArrayCA[1] = 0xFF;
dataArrayCA[2] = 0xFF;
dataArrayCA[3] = 0xFF;
dataArrayCA[4] = 0xFF;
dataArrayCA[5] = 0xFF;
dataArrayCA[6] = 0xFF;
dataArrayCA[7] = 0xFF;

dataArrayRED[0] = 0x38;
dataArrayRED[1] = 0x1C;
dataArrayRED[2] = 0x0E;
dataArrayRED[3] = 0x07;
dataArrayRED[4] = 0x83;
dataArrayRED[5] = 0xC1;
dataArrayRED[6] = 0xE0;
dataArrayRED[7] = 0x70;

dataArrayBLUE[0] = 0xE3;
dataArrayBLUE[1] = 0xF1;
dataArrayBLUE[2] = 0xF8;
dataArrayBLUE[3] = 0x7C;
dataArrayBLUE[4] = 0x3E;
dataArrayBLUE[5] = 0x1F;
dataArrayBLUE[6] = 0x8F;
dataArrayBLUE[7] = 0xC7;

dataArrayGREEN[0] = 0x8E;
dataArrayGREEN[1] = 0x47;
dataArrayGREEN[2] = 0xA3;
dataArrayGREEN[3] = 0xD1;
dataArrayGREEN[4] = 0xE8;
dataArrayGREEN[5] = 0x74;
dataArrayGREEN[6] = 0x3A;
dataArrayGREEN[7] = 0x1D;
}

void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val)
{
uint8_t i;

for (i = 0; i < 8; i++) {
if (bitOrder == LSBFIRST)
digitalWrite(dataPin, !!(val & (1 << i)));
else
digitalWrite(dataPin, !!(val & (1 << (7 - i))));

digitalWrite(clockPin, HIGH);
digitalWrite(clockPin, LOW);
}
}

void loop(){
digitalWrite(masterClear, HIGH);
digitalWrite(outputEnable, LOW);

for (int j = 0; j < 8; j++) {
dataCA = dataArrayCA[j];
dataRED = dataArrayRED[j];
dataBLUE = dataArrayBLUE[j];
dataGREEN = dataArrayGREEN[j];
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, dataCA);
shiftOut(dataPin, clockPin, MSBFIRST, dataGREEN);
shiftOut(dataPin, clockPin, MSBFIRST, dataBLUE);
shiftOut(dataPin, clockPin, MSBFIRST, dataRED);
digitalWrite(latchPin, HIGH);
delay(1000);
}
}

Test 74HC5951.ino (2.23 KB)

How many bits do you need to shift out to light, or not, 32 LEDs? How many ARE you shifting out?

I'm shifting out 32 bits.

Nielska:
I'm shifting out 32 bits.

No. You are shifting out 8 bits, 4 times. That is NOT the same as shifting out 32 bits.

Your shiftOut() function needs to take a 32 bit value (unsigned long), and shift out all 32 bits during one latch pin cycle.

PaulS:
No. You are shifting out 8 bits, 4 times. That is NOT the same as shifting out 32 bits.

Nonsense.
How are these two supposed to be different?

set latch pin low
repeat 4 times {
    repeat 8 times {
        set data pin
        pulse clock pin
    }
}
set latch pin high
set latch pin low
repeat 32 times {
    set data pin
    pulse clock pin
}
set latch pin high

How are these two supposed to be different?

They aren't. But neither example reflects what OP is actually doing, with regards to when the latch pin state is changed.

What I'm actually trying to do is, to control an RGB-matrix with 74HC595 shift registers. I thought it was as simple as just sending some bits like they told me in the example on the arduino website.

PaulS:
They aren't. But neither example reflects what OP is actually doing, with regards to when the latch pin state is changed.

What I'm actually trying to do is, to control an RGB-matrix with 74HC595 shift registers. I thought it was as simple as just sending some bits like they told me in the example on the arduino website.

I thought it was as simple as just sending some bits like they told me in the example on the arduino website.

It is.

But, you must send the 32 bits between toggling the latch pin. What you are doing now is toggling the pin between each group of 8 bits.

PaulS:
But, you must send the 32 bits between toggling the latch pin. What you are doing now is toggling the pin between each group of 8 bits.

No, that is not correct.

Op's code:

    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, dataCA);
    shiftOut(dataPin, clockPin, MSBFIRST, dataGREEN);
    shiftOut(dataPin, clockPin, MSBFIRST, dataBLUE);
    shiftOut(dataPin, clockPin, MSBFIRST, dataRED);
    digitalWrite(latchPin, HIGH);

That shifts out 4 x 8-bit values then raises latchPin. The 74HC595 is +ve edge triggered. That is correct.

Nielska:
the bits I send through the shift registers don't go further then the second shift register.

You must have a hardware fault between the second and third shift register.
Check your wiring.

Yours,
TonyWilk

TonyWilk:
You must have a hardware fault between the second and third shift register.
Check your wiring.

Seconded. The data pins should be daisy-chained, the latch output should just go to all 4 chips as-is. But if you have 2 working, then you already know that. Youre looking for some bad soldering. What happens when you take the data output from the arduino off the first chip and just put it on the second chip? Do 16 bits go through and then stop, or do only 8 go through?

Hi,

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Not a picture of the layout, the one you have supplied does not identify pinouts, and you can't even read component numbers.

Please label pinouts and component numbers.
Include you power supply and how it supplies the LEDs and UNO.

Thanks.. Tom... :slight_smile:

PaulMurrayCbr:
Seconded. The data pins should be daisy-chained, the latch output should just go to all 4 chips as-is. But if you have 2 working, then you already know that. Youre looking for some bad soldering. What happens when you take the data output from the arduino off the first chip and just put it on the second chip? Do 16 bits go through and then stop, or do only 8 go through?

Only 8 go through.

I've made a circuit in Multisim, I als spit it op in parts so it's less chaotic. I took a picture of the outputs and the pins that go the he shift registers.

ToShiftRegisters.PNG

Nielska:
I've made a circuit in Multisim snip

That looks ok to me.

It must be something in the wiring... if you have a multimeter, check continuity from the Arduino pins for each common line (masterClear, clockPin, latchPin and outputEnable ) to all the shift registers
Check each shift register's pin 9 out to the next pin 14 in.
Do they all have +5V and GND connected ?

If you have LEDs plugged in each of those headers, I guess the RED ones work... could you plug the RED LEDs into the BLUE or GREEN socket? It could be those other LEDs are not wired correctly.

Yours,
TonyWilk

Hi,
Can you post a higher resolution image of your schematics please?
It is not possible to read pin designators.

What will you be doing with CA output header?

Have you got this breadboarded and using a UNO, or a 328 chip and PCB?

Can you post a picture of your project please?

Thanks.. Tom.. :slight_smile:

Nielska:
Only 8 go through.

Well, there you go then. Same code, it should be pushing out 16 if it was a bug in the code. Only 8 go through.

How about if you feed the bits into the third register? Do all 16 bits load into the 3rd and 4th? You have a wiring problem between the data out of the second register and the data in of the third.

Hi,
This Library will probably make things easier.

  ShiftRegister74HC595.h - Library for easy control of the 74HC595 shift register.
  Created by Timo Denk (www.simsso.de), Nov 2014.
  Additional information are available on http://shiftregister.simsso.de/
  Released into the public domain.
*/

#include <ShiftRegister74HC595.h>

// create shift register object (number of shift registers, data pin, clock pin, latch pin)
ShiftRegister74HC595 sr (1, 0, 1, 2);

Tom... :slight_smile:

Well, this is something weird. I tried connecting the 'green' LED's to the first register and they don't light up.

Hi,
This diagram is weird, what are the green lines doing?

Tom.... :o