2
\$\begingroup\$

I've just had my first go at getting a shift register to work with my Arduino.. it was almost flawless, but I seem to be missing my first bit.

I followed the guide here, but using only one shift register: http://arduino.cc/en/Tutorial/ShiftOut

It took a little while to figure out, but it appears as though pin Q1 on my shift register is lighting up when I send the number 2, Q2 is high for 4, Q3 = 8 etc.. when I call shiftout() with the number 1 no LEDs come on.

I checked my wiring and it seems fine.. then I double checked and it's definitely fine.

The only things I can think of are: 1. My shift register is slightly different to the one they're using.. it's a 595N, not a 595. 2. I've done something wrong in the code..

In loop():

  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST, 1);
  digitalWrite(latchPin, HIGH);

Does anyone have any tips on debugging this issue?

Cheers, John

\$\endgroup\$
  • \$\begingroup\$ It also got me wondering what Q0 is on pin 15.. \$\endgroup\$ – John Hunt Mar 19 '13 at 14:42
  • \$\begingroup\$ Q0 is the lowest order output - it's very common (though not universal) for these to be numbered from zero rather than from one. This may well explain why you are getting a different than expected result. Otherwise, you may have one too few or too many clocks. If you had written the shift function yourself, it would also be possible that you were presenting the data at the wrong time relative to the clock, but the library routine is probably OK. \$\endgroup\$ – Chris Stratton Mar 19 '13 at 14:56
  • \$\begingroup\$ Upon further inspection of the Arduino tutorial my mind totally skipped over the fact they were using Q0 - the pin out layout on the circuit diagrams is slightly different from the phillips datasheet. This makes it all make sense :) \$\endgroup\$ – John Hunt Mar 19 '13 at 18:50
7
\$\begingroup\$

The shift register is behaving exactly as designed.

The second-from-lowest significant bit should be lighting up for a value of 2. That's Q1.

To check for a value of "1", you need to be looking at the least significant output bit, which is Q0.

Also, the 595 and 595N are not functionally different.

\$\endgroup\$
  • \$\begingroup\$ Thank you for confirming that :) I like shift registers! \$\endgroup\$ – John Hunt Mar 19 '13 at 16:38
  • \$\begingroup\$ @JohnHunt Yes, they're neat... Even neater are the high current shift registers like TPIC6A596, which can actually sink 350 mA per bit, and can be used to directly control relays, solenoids and entire LED strings! \$\endgroup\$ – Anindo Ghosh Mar 19 '13 at 16:48
1
\$\begingroup\$

I'm no good on code but maybe you are trying to latch the data to the output before it is properly clocked in to the internal shift register? This could result in the data bit previously clocked into the shift register popping up on the output. This could give you what you see. Maybe you need a small delay after the shiftOut command. Or maybe i'm being stupid?

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.