Instructables

Using a shift register with Raspberry Pi

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).
 
Remove these adsRemove these ads by Signing Up
George_8410 months ago
found out what was wrong - putting clear high in Shifter.setupBoard to start with and having Shifter.clear oscillate from low to high.
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])

Thanks for writing and sharing your code mrmath. I'm not moaning.

For anyone else out there if you are using a 74HC595 with RPi.GPIO a slight adjustment is needed.
George_8410 months ago
sage advice... I will have another go at wiring it.
Thanks!!
mrmath (author) 11 months ago
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.

Good luck!
George_8411 months ago
Hi,

I get an odd thing happen using a 74HC595 - my left most led is in essence a mirror to the number 2 (adjacent)
I looped through all the values for setValue from 0 (totally blank) to 255. It's like I'm only 7 bit.

any thoughts? Otherwise it seems to work nicely.
IMAG1016.jpg
ailex1 year ago
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?
ailex ailex1 year ago
is correct #inputA=15 or inputA=15 whitout #?
mrmath (author)  ailex1 year ago
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.
ailex ailex1 year ago
At least it works, i change the pin numbering and voilá
ailex1 year ago
The last thing is
Which values are correct for the argument of setValues Function?
mrmath (author)  ailex1 year ago
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.
ailex1 year ago
thanks again
ailex1 year ago
thank you!!!! this afternoon i'll prove it
mrmath (author)  ailex1 year ago
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!
ailex1 year ago
where is the code?
mrmath (author)  ailex1 year ago
Don't know what happened there, but I've attached it now. You should see it right on the first step. Sorry about that.
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!