This instructable will attempt to explain, in simple terms, what a shift register is, and how you can use it with the Raspberry Pi to expand the GPIO port by running eight outputs with just four GPIO ports.

To start with, what is a shift register?  Wikipedia has a technical definition of shift registers, but in a nut shell, shift registers let you take serial input (one bit after the other), and output it in parallel.

Let's say, for example, you wanted to output six digital bits from your Raspberry Pi to drive a display based on the HD44780, like this one, but your project had to give up almost all the GPIO to other things, and all you have left is four pins. You can send those six bits one after the other to the shift register using those four pins, which will then appear to the display as six parallel outputs.

For this project, which is a first step towards the above situation, I'm going to run LEDs off each of the eight outputs, just as a proof of concept.  The attached video shows the end result of this process.  Just a bunch of flashing lights for now, but stay tuned.  This is really the second in a series of instructables leading up to my Voiceberry Pi  (see the first one here).

Step 1: Wiring up the chip Part 1: Data pins 1-4

I picked up a few shift registers for $0.39 each at Jameco.com.  The ones I eneded up getting were SN74HC164N's from Texas Instruments.  Not that it really means anything one way or the other, but that's what I ended up getting.  The datasheet is available right there at Jameco, and details how to wire up the chip are in there.  But here's the pinout:

1: Input A
2: Input B
3: Data 1
4: Data 2
5: Data 3
6: Data 4
7: Ground
8: Clock
9: NOT Clear
10: Data 5
11: Data 6
12: Data 7
13: Data 8
14: Vcc

Unless you get the same chip, your pinout will be different, and you should follow your datasheet.

To start with, the chip goes in the bread board, and then four LEDs are linked up from data pins 1-4 to a common lead (not ground, yet).
<p>I could not open any of the videos you provided.</p>
<p>A couple of words of caution:</p><p>1) In Step 2), it looks like you are using one current limiting resistor and is it 22 ohms? 1/4W or 1/2W? Using one current limiting resistor with 8 LED's will make all the current go through one resistor. That can be bad for a project.</p><p>Say Vled = 1.8V</p><p>Vpin = 5V</p><p>Vresistor = Vpin - Vled = 5V - 1.8V = 3.2V</p><p>R = Vresistor / Isink</p><p>If I read the spec sheet correctly for a TI SN74HC164, I(input clamp) = +/- 20mA</p><p>I think that is the maximum current that can be sunk by a pin when low.</p><p>R = 3.2V / 20mA = 16 ohms</p><p>However, you have all LED's routed through one resistor.</p><p>I = 3.2V / 22 ohms = 0.145A</p><p>0.145A x 8 = 1.16A</p><p>P = (I^2)R = (1.16A ^ 2)22ohms = 29.6W</p><p>If you have your project working with these values, I must have missed something - it would not be the 1st time!</p><p>1.16A would be far too high for even a 1/2W resistor.</p><p>2) A schematic would go a long way to resolving what is going on here, what the resistor value is, exactly how the IC, LED's and resistor are all connected.</p><p>3) A list of components or BOM would also make things easier, especially when trying to gather your parts. This might seem unecessary with a project with only three different electronic components invovled, but it would resolve my questions.</p>
found out what was wrong - putting clear high in Shifter.setupBoard to start with and having Shifter.clear oscillate from low to high. <br>I am using a different chip but I don't know how that changes things (as I don't know lots about chips - other than eating them [omm nom nom nom]) <br> <br>Thanks for writing and sharing your code mrmath. I'm not moaning. <br> <br>For anyone else out there if you are using a 74HC595 with RPi.GPIO a slight adjustment is needed.
sage advice... I will have another go at wiring it. <br>Thanks!!
First thing I would check is to make sure the wiring is coming from the chips pins to the diodes correctly. Next I would swap out the chip for another one if that's possible. Last thing I'd do is tear the whole thing down, and start from scratch. Can't tell you how many times I've had a circuit not working, and been unable to find a wiring error, tore it down out of frustration, built it back up, and had it work perfectly. <br> <br>Good luck!
Hi, <br> <br>I get an odd thing happen using a 74HC595 - my left most led is in essence a mirror to the number 2 (adjacent) <br>I looped through all the values for setValue from 0 (totally blank) to 255. It's like I'm only 7 bit. <br> <br>any thoughts? Otherwise it seems to work nicely.
Sorry, but after putting all wires and check everything, I used the code and nothing happens. I added to the code the typical # / usr / bin / python. I tried changing the pins numbering but nothing happens. What i do wrong? <br>
is correct #inputA=15 or inputA=15 whitout #?
My shift register has two inputs that are ANDed together, so I have an inputA and and inputB. Originally, I was setting inputA high and using the input on inputB to run the shift register, but then I changed it to link inputA directly to inputB on the breadboard, and I didn't need inputA in my code anymore. So I commented it out.
At least it works, i change the pin numbering and voil&aacute; <br>
The last thing is <br>Which values are correct for the argument of setValues Function?
Whatever you want the output to be. It's binary, but flipped, so 1 is on the left and 128 is on the right. So 0x15 is HEX for 37, which in binary is 00010101. That would light the first, third and fifth LEDs from left to right.
thanks again
thank you!!!! this afternoon i'll prove it
WAIT! That was the wrong code. You have to get the code that I just put up there. shifter.py. NOT shifterDisplay.py. My apologies!
where is the code? <br>
Don't know what happened there, but I've attached it now. You should see it right on the first step. Sorry about that.

About This Instructable




More by mrmath:
Add instructable to: