am i outputting to 4 74HC595 the correct way>

When I run this code the leds flash off, then come back on. I have 4 595s that I'm learning with and that was a real surprise. The leds were already on because they sat on after each sketch run.

int latchPin = 9;
int clockPin = 10;
int dataPin = 12;

void setup()
{

  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);


  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST, B11111111);
  shiftOut(dataPin, clockPin, MSBFIRST, B00000000);
  shiftOut(dataPin, clockPin, MSBFIRST, B00000000);
  shiftOut(dataPin, clockPin, MSBFIRST, B00000000);
  digitalWrite(latchPin, HIGH);                       
    delay(500);




}

void loop() {

}/code]


Thank you,

Tony

How to you have things wired up? Since all your code is inside setup() the only way to run it again would be to cycle power or hit the reset button or close/re-open the Serial monitor. All of these things reset the arduino which means all those pins become INPUTs (the default power up state) so things may be floating for a small while until your code sets them to OUTPUT.

You could wire the OE/ pins with a pullup resistor, and a pin from the Arduino to control it.
When the 328P is reset, the outputs get turned off until the 328P drives the output low.

Hi Tony,
for a deeper analysis could you post your circuit? a hand made raw drawing is enough.
You could connect the second electrodes of the LEDs to ground or to +5V.

How about stepping back to one single shiftregister before cascading them?

I have done this several years ago with a parallax propeller microcontroller same thing
bitbanging IO-pins High/Low but I don't remember it all.

I looked up the datasheet
If Pin "G" (Pin 13) (is low outputs are enabled

The change of "RCK" (Pin 12) from low to high stores the bits from the shiftregister into to storage register

best regards

Stefan

I've been at this trying to get it right. For some reason I get poor results unless I have the four 74HC595s wired as in the photo. I have a little movie, hopefully it uploads - I scaled back the resolution quite a bit. I'm switching to the TPICs but I still want to learn from the 74HCs. I have a question but don't know if the the little movie will load. I'll hold off with the question until I see if it uploads. Best, Tony

  • sadly, the movie won't upload, dang

in the movie below, i have three relays swapped in for LEDs. seems to work just fine. i have some higher powered ICs coming today. crossroads recommends before moving forward.

trying google drive: https://drive.google.com/file/d/1e_M2EviCh5x8VGtp3IWqn2WZMOZBP3Me/view?usp=sharing

Pin 10 on the 74HC595 (~SRCLR or ~MR depending on the brand) will reset all the outputs to a low state, when it is pulsed low. I looked at some Arduino examples and they usually connect that to +5V. You didn't say what you're using as an example, but that would explain why they don't reset on power up if you have it connected that way. You can connect pin 10 to the Arduino RESET pin and the LEDs will be reset along with the Arduino.

Also, you posted movies instead of the pencil sketch requested by @Stefan. It is important to provide as much of the information that is needed to solve your problem as you can, in your first posts. Looking back, you were asked for wiring details in reply #1. We're still waiting.

RE the QTY 7 74HC595s, attached is the sketch I'm currently working with at the moment. 10 is connected to +5. I've had some issues with DATA pin 14, and pin 9 and the proper method for wiring them separately or together. When I've hooked up to 9, following pin 14 on the first chip, I get a catastrophe.

The movie was just a concept idea for triggering the solenoids to drop the little booze bottles.

tperry724:
RE the QTY 7 74HC595s, attached is the sketch I'm currently working with at the moment. 10 is connected to +5. I've had some issues with DATA pin 14, and pin 9 and the proper method for wiring them separately or together. When I've hooked up to 9, following pin 14 on the first chip, I get a catastrophe.

The movie was just a concept idea for triggering the solenoids to drop the little booze bottles.

Your schematic:


Did you try my suggestion of connecting pin 10 to RESET? Your second statement concerns cascading registers. That is also easy.

Please read this:

working on it....and a few other things simultaneously...ha

Please check the link I added to the post...

I read the article, and built their circuit. They posted code but i couldn't get much out of it even though it didn't error out. I see that the data pin feeds a slave pin and so on. Still, I haven't been able to get much out of any two or four IC circuits. I'm very weak on the code side but I do a good job with my breadboards, oftening cutting each wire.

The idea of the process is clear to me now. It's like everyone gets handed a present but no one can open one until everyone else has one. Kinda.

Supposed to get the power upgrade of the 74s. TPIC, I think. Can't wait to get a working prototype. The mechanical side is done (well the part i'm building to test anyway).

I've been over that new 16 LED board from the article 6 or 7 times. Double checking in. I need some simple code to check things outs because as it stands, it appears that the second 74HC595 isn't doing too much. The first shift register seems to respond to other programs, even if not designed for 2 shift registers and 16 LEDS. I've been working on my own code to push some data into the shift registers to see if everything is operating correctly. I'll post below. I'm not going for heavily efficient code, as I'm a novice, its just something I can (hope to) understand and make some changes to once in a while.

const int SER   =12;
const int LATCH =11;
const int CLK = 9;

void setup() {
  
  pinMode (SER, OUTPUT);
  pinMode (LATCH, OUTPUT);
  pinMode (CLK, OUTPUT);

int digitalDelay; 

digitalDelay = 1000;


digitalWrite(LATCH, LOW);
   shiftOut(SER, CLK, MSBFIRST, B10000001);
   shiftOut(SER, CLK, MSBFIRST, B00000000);
   shiftOut(SER, CLK, MSBFIRST, B00000000);
   shiftOut(SER, CLK, MSBFIRST, B10000001);
    digitalWrite(LATCH, HIGH);
      delay(digitalDelay);


digitalWrite(LATCH, LOW);
   shiftOut(SER, CLK, MSBFIRST, B10101010);
   shiftOut(SER, CLK, MSBFIRST, B10101010);
   shiftOut(SER, CLK, MSBFIRST, B10101010);
   shiftOut(SER, CLK, MSBFIRST, B10101010);
    digitalWrite(LATCH, HIGH);
      delay(digitalDelay);

}

void loop() 
{
  }

I hope you can see what I was going for.

Best,

Tony

It looks like you connected the output (Q7') of the bottom '595 to the input (DS) of the top '595, which is also connected to the Arduino's data pin. This will create a short.
(I'm looking at the red vertical wire between the two chips in your second picture.)

Q7' (pin 9) of the top '595 should be connected to DS (pin 14) of the bottom '595, not the other way around.

There's a very real possibility that you have damaged either the output driver of the Arduino data pin, or of the bottom '595.

Pieter

Hi,

I hope you got it working. I found your post because I was looking for a sketch to check 2 shift registers daisy chained. I finally got it working with 16 LEDs in a row. This simple sketch works to check 2 shift registers, modify for more.

I lined my LEDs up so that looking at them from left to right they are connected to Qa-Qh (on 74HC595). The LSB is on the right. With this setup I use the LSBFIRST to shift out the bytes using the shiftOut() function.

The way I look at it is the Arduino shiftOut() clocks in 8 bits at a time, no more, no less. The daisy chained shift registers have d-type flip-flops, chained together and each chip extends the chain. Each bit that comes in moves in an orderly fashion to the next flip-flop as the clock is cycled. So a bit coming in must move all the way through 32 flip-flops when you have 4 SIPO shift registers daisy chained.

Now, in my setup, where Qa is on my left, and Qh is on my right, when I added another shift register (to the right of the first), it becomes the least significant byte and when I shift 1111111100000000 into the two registers (now one big one), I need to break it up into the 2 bytes, and shift out the LSB first, then the MSB, because if I did it the other way around, it looks like this once latched: 0000000011111111

So, for 2 shift registers, you need to shift the top 8 bits right, before you transmit, because the shiftOut() can't SEE the rest of the 16 bits (or 32 etc.) in your variable.

The notes at the bottom of the shiftOut() page explain this: shiftOut() - Arduino Reference

So here is a very simple example using 2 shift registers, and 16 LEDs, arranged so looking at them in a row from left to right, each row is wired to Qa through Qh on the 74HC595.

I added a lot of serial monitor output so you can visualize the code. To make an animation of 4 LEDs appear to move from right to left through all the LEDs then disappear, I needed 10 bytes. I could have also used an array, but this is the raw demo.

// Example code for 2 SIPO shift registers with 16 LEDs.
//
// define pins on Arduino

const int latchPin = 5;
const int clockPin = 6;
const int dataPin = 4;

// unsigned variable to deal with bitshift
unsigned int leds;
int wait = 500;

void setup()
{
  Serial.begin(115200);
  while (!Serial);
  Serial.println("RESET");

  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  // Run at start to clear bits
  leds = 0;
  updateShiftRegister();
  delay(wait);
}

void loop()
{
  Serial.println("LOOP");

  leds = 0x000F;
  updateShiftRegister();
  delay(wait);

  leds = 0x00F0;
  updateShiftRegister();
  delay(wait);

  leds = 0x0F00;
  updateShiftRegister();
  delay(wait);

  leds = 0xF000;
  updateShiftRegister();
  delay(wait);

  leds = 0;
  updateShiftRegister();
  delay(wait);

}

void updateShiftRegister()
{
  Serial.print("shift byte with value 0x");
  Serial.print(leds, HEX);
  Serial.print(" : ");
  Serial.println(leds, BIN);
  digitalWrite(latchPin, LOW);  // keep latch low while sending 16 bits stored in variable
  shiftOut(dataPin, clockPin, LSBFIRST, leds);  // send low byte
  shiftOut(dataPin, clockPin, LSBFIRST, (leds >> 8)); //bitshift and send high byte
  digitalWrite(latchPin, HIGH);
}

This guy has a nice example setup and code for 2 registers: https://www.best-microcontroller-projects.com/74hc595.html

For learning about using 1 shift register, I like this site: https://lastminuteengineers.com/74hc595-shift-register-arduino-tutorial/

The latch pin doesn't need to be held low during the shifting process, it can just be pulsed after all the bits
sre shifted in, as its a DQ flipflop register on the output of the shift register. On a rising edge to the latch
pin the current shift register state is copied to the output, otherwise the outputs are unchanging.

If it were a transparent latch, you'd need to hold it across all the shifts, but its not.

Transparent latches have two states, one is locked unchanging, the other lets the input
through constantly.

DQ flip flop latches only change at the clock edge, usually rising edge.