74HC595 shift register with mkr wifi 1010: what am I doing wrong

Tried out a bunch of examples with my arduino mkr wifi 1010 and all have worked so far (buzzer, led, rgb led, switches etc), except the shift register I cannot get to work: the code I have below cycles through all the bits so the LED should light up one at a time, in turn left to right. But it lights up in seemingly random pattern.

So I simplified the problem and just connect one LED, to Q0. I've attached a photo of the setup, I tried setting it up so it is really easy to see what is connected where (but let me know if there is a better way). Basically on arduino:

  • 5V to + column,
  • ground to - column,
  • pin 2 to clock on shift register
  • pin 3 to latch on shift register
  • pin 5 to data on shift register

and on shift register:

  • GND to - column
  • OE to ground (- column)
  • VCC to + column (5V)
  • MR to + column (5V),
  • Q0 to 220 ohm resistor

and finally the LED:

  • resistor to long leg (cathode)
  • short leg to ground

I'm using the following which is from an example sketch:

int clockPin = 2; //Pin 11 (SRCLK) of the shift register
int latchPin = 3; //Pin 12 (RCLK) of the shift register
int dataPin = 5; //Pin 14 (SER) of the shift register
byte leds = 0; // hold the pattern of which LEDs are currently turned on or off
int currentLED = 0;

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

    leds = 0;
}

void loop()
{
  // clear the bits in the leds variable at the start of every iteration so that 
  // all the bits are set to 0 as we only want to light up one LED at a time. 
  // After this we increment or reset the currentLED variable so that we 
  // are lighting up the correct LED next.
    leds = 0;

    if (currentLED == 7)
    {
        currentLED = 0;
    }
    else
    {
        currentLED++;
    }

    bitSet(leds, currentLED);
    Serial.println(leds);

    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, leds);
    digitalWrite(latchPin, HIGH);

    delay(5000);
}

I'm thinking I'm missing something so obvious I can't see it, or my shift register is damaged.


It's missing a bypass capacitor. 0.1uF ceramic, close to the power pins of the chip, for example across the breadboard power strips next to where the chip is connected to them. Bypass caps are not optional.

This may not turn out to be the reason for the undesired behaviour. But there is absolutely no point worrying about any other possible reasons until you have fixed that.

but let me know if there is a better way

Yes, post a schematic. Your pic isn't too bad because the circuit is simple and you have kept half of the wiring neat, but imagine if the circuit was a little more complex, or if was all made with flying wires. The pic would be indecipherable. Your schematic can be hand drawn, that's ok as long as it is neat.

It appears pin 13 is floating, it must be connected to - or you will not get any output. This response is to help you get started in solving your problem, not solve it for you.
Good Luck & Have Fun!
Gil

Thanks @gilshultz for info. However pin 13 of the shift register is Output Enable (OE) and it is active low so it is connected to ground (the yellow wire for the row between the green and orange jumper cables near the shift register). Only pins 1-7 and 9 are floating.

From the datasheet:
"The maximum voltage that the I/O pins can tolerate is 3.3V."

Yep, the MKR 1010 WiFi is a 3.3volt board.
So why do you connect something powered with 5volt to it's I/O.
You must power the 74HC595 from 3.3volt, not 5volt.
Not sure how immune this board is to 5volt I/O abuse.
Leo..

That goes for the output from the MKR1010 as well. It is 3V3 and not enough to drive the shift register if you power it from 5V.

schollii:

  • Q0 to 220 ohm resistor

and finally the LED:

  • resistor to long leg (cathode)
  • short leg to ground

resistor to anode of LED,
LED cathode (the side with the flat section on the body) to ground.

There is no consistent meaning to lead length on LEDs, the flat on the body marks the cathode.
Lead length conventions vary by manufacturer.

Grumpy_Mike:
That goes for the output from the MKR1010 as well. It is 3V3 and not enough to drive the shift register if you power it from 5V.

Well, that is arguable.

Theoretically according to the datasheet the threshold could be 3.5 V at an extreme of tolerance but in practice it will almost certainly work just fine.

Wawa:
So why do you connect something powered with 5volt to it's I/O.

You are only connecting the inputs of the 74hC595 to the MKR. How is that ever going to cause a problem? :astonished: