Reading inputs from shift registers using just one single pin

Here’s an interesting article about reading data from shift registers using less than three pins. 74HC165 shift registers are a popular choice for adding inputs to a microcontroller. They have a parallel input register which can be read using the latch, then shifted into a microcontroller via the data and clock pins. For those counting, that’s the three pins normally associated with driving these devices.

This hack first does away with the latch pin. The addition of a carefully trimmed RC circuit (capacitor is charged by the clock pin, then the resistor lets that cap slowly discharge) means that the device will not latch until after the clock stops toggling. This technique drops the control down to just two pins (data and clock). You can still use hardware SPI to read the data using this method. It’s the same as using SPI to drive 595 shift registers except the microcontroller reads data instead of writing it.

But wait, there’s more! The diagram above actually shows a way of reading this shift register with just one pin. Notice that the clock and data pins are now connected to just one of the microcontroller pins. The data pin has an added resistor, which keeps the current low enough that it will not compete with the clock signal coming from the microcontroller. In between clock pulses, the microcontroller switches from output to input to read the data pin on each cycle. Give it a try, it’s a fun experiment!

Comments

  1. Darkknight512 says:

    That’s pretty nifty and useful, gotta keep this in mind when I am short on pins.

  2. Brilliant

  3. Mike says:

    This is insanely cool. Though my guess is the tolerance on the circuit has got to be pretty tight.

  4. Mike says:

    Very swish. Respect to the designer.

  5. ScottInNH says:

    About 6 months ago here I saw a variation, using similar technique so that some 8-pin chip could run a second LED off the same pin.

    I don’t remember who/when details, but specifically I remember they used a cap and a resistor to enable selection between the two LEDs. I wish I had bookmarked it then… love these clever tricks.

  6. WestfW says:

    It was an EDN Design idea; I had posted it to the Arduino Forums, and you might have seen it there. Slightly different (used the inherent pin capacitance and hysteresis instead of adding them explicitly.)

    http://www.edn.com/article/518373-Drive_16_LEDs_with_one_I_O_line.php

    Note that since the shift register used doesn’t have a separate latch, all the values will shift out all the pins at some point. Fine for steady-state indicator LEDs, but perhaps not for other things.

    • ScottInNH says:

      Thanks WestfW – this was the one I was thinking of. I remembered it a little differently (I thought there was a cap in the circuit), but I recognize the page. This is very clever stuff, and a pity it’s not something I’ve found in my introductory electronics books.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 93,813 other followers