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).
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.
Thanks for the information on using a <a href="http://www.4ab.ca" rel="nofollow">registry in Calgary</a>. I have always wondered about those.
Thanks for the information on using a <a href="http://www.4ab.ca" rel="nofollow">registry in Calgary</a>. I have always wondered about those.

About This Instructable


56 favorites


More by mrmath: Running an HD44780 Display off the ATmega on a Gertboard Voiceberry Pi! Driving an HD44780 Display using a Shift Register and a Raspberry Pi
Add instructable to: