I'm still learning. I have a project in mind that will require more GPIO pins than what is available on an UNO. Most of those pins will be simple on/off type signals for controlling transistors that in turn control small motors. Sounds like a good use for an 8-bit 595 shift register right?
The way I am seeing a simplistic way of visualizing how a shift register works is this: 2 trays with room for 8 blocks each. Send over a bit to the "memory tray". Hit the latch empties the memory tray and it shifts over to the execute tray. Send over another bit to the memory tray, hit the latch. Now the first bit is in position 2 and the new bit is in position 1. I could also fill the memory tray with 8 bits, latch, and have a whole new execute tray.
If I have my execute tray as this: 00000100. Now I want to turn on bit 2 and leave 3 on, I should send this byte: 00000110. Latch. Now 2 and 3 are on.
The programming would be something like take a byte (CurrentState) and add or subtract a byte (00001000 for pin 5) to turn it on or off respectively.
The memory tray overflows into the memory tray of the next register if they are daisy chained together. So in a chain of 3, I could send out 3 bytes, the first byte sent landing in the memory tray of the last register in the chain. Then hit the latch and have new execute trays.
Is my visualization accurate? It may be too simplified so any help would be greatly appreciated.
Not quite correct.
One thing to keep in mind is that numbering and indexing starts at zero
so bit numbering starts at zero not one.
In this statement, the bits are off by one.
If I have my execute tray as this: 00000100. Now I want to turn on bit 2 and leave 3 on, I should send this byte: 00000110. Latch. Now 2 and 3 are on.
example: 00000100 has bit 2 set.
Also, a 595 shift register is not capable of GPIO since the 8 data pins are output only.
You can shift in bits to be stored on the output pins, but you can not use the data pins as inputs .
But in the bigger picture, there some important things to keep in mind.
There are actually two types of shift registers.
latching outputs with an internal storage register (example: 74hc595, 74hc4094)
non latching outputs. (example: 74ls164)
The difference is that one has an extra temporary 8 bit register that can be loaded by shifting in bits which can be moved to the output pins using a latch signal.
The other type shifts in bits and the output pins are immediately affected as each bit is clocked in.
There are actually 3 function signals typically called.
(different chips use different names for them but the function is the same)
data
clock
latch (only used on the latching shift registers like the 74hc595
Each time the clock signal is triggered, the signal level (bit) on the data signal pin is clocked in as all the other bits are shifted over to make room.
On a non latching shift register the output pins are altered immediately.
On a latching shift register an internal register is updated and then at some point in the future (usually after all 8 bits have been shifted in) the internal register can be transferred to the output pins by triggering the latch signal.
I have a project in mind that will require more GPIO pins than what is available on an UNO
Hi,
Well, the obvious answer is to use a Mega!
But if you explain your project idea in more detail, experts here may be able to come up with ways to do the same thing with dramatically fewer outputs. For example, one way of dealing with a large number of identical components is to arrange them into a matrix. This is how keyboards work. They don't contain a chip with 100+ inputs!
One last piece of advice: once you have a circuit worked out for your project, ask here for advice before you spend your money!
But that takes all the fun out of it! Like using a shotgun to kill the fly. Chopsticks, Daniel-san.
PaulRB:
But if you explain your project idea in more detail, experts here may be able to come up with ways to do the same thing with dramatically fewer outputs. For example, one way of dealing with a large number of identical components is to arrange them into a matrix. This is how keyboards work. They don't contain a chip with 100+ inputs!
The final goal is to build a waterfall display. Many solenoid valves controlling the flow of water to create a falling pattern of pictures/text. I've read through some of the posts about LED cubes and controlling the rows/columns of anodes/cathodes. I could do something using the same principle to control an array of solenoids.
There are a few obstacles between me and Disney calling me to set up a feature in the Animal Kingdom Lodge. First I will try to control 8 LEDs through a 595 shift register. Then move on to a 8x8 grid with 2 595s. Basically work through the LED cube problem. My end-goal setup will be linear but I think the academics of it are similar enough.
I also need to work on the water nozzle setup. That's just a fluid dynamics hardware issue and not at all an Arduino issue. Educated experimentation on a few different kinds of solenoids will solve that one.
The difference between my goal and the LED cubes is that is seems the "dance" is hard coded in. Or having an array on an SD card and parsing through line by line. I want to have on my computer a pile of arrays that I can select and load on the card. Then have the arduino run through them like a playlist. I started a separate post on that issue but I'm pretty sure I have that worked out at least in my head.
Thanks all for your help. Time to spend a couple dollars on a couple shift registers and LEDs to begin the initial learning stages.
Well, ok, but watch out with those 74xx595. They can't sink or source much current, only around 20mA per output and 70mA per chip in total, so keep those led series resistors high and use transistors for common rows/columns. Maybe get a tpic6(c/b/a)595 to experiment with. They behave just like a 74xx595 but can sink far more current (but cannot source any current). Maybe a useful chip for driving solenoids.
PaulRB:
Maybe get a tpic6(c/b/a)595 to experiment with. They behave just like a 74xx595 but can sink far more current (but cannot source any current). Maybe a useful chip for driving solenoids.
Actually, they are designed specifically for driving solenoids as they include the "kickback" suppression components internally.
These chips are the correct answer for this application. Multiplexing is not going to work unless you have special ("latching") solenoids (like in your bus destination displays).
I'll look more into using the tpic6 chips. My plan was to use the shifts to drive an NPN transistor(2N3904) that would actually switch the solenoids. I was going to use a series of shift registers to use 1 pin per transistor solenoid pair. I hadn't yet learned of the multiplexing concept.
I still think this is the way to go. Multiplexing LEDs using persistence of vision is good. The LED doesn't mind being switched on/off many times per second to create the illusion of many on at the same time. I don't think a solenoid would behave well. It wouldn't ever really be completely open or closed during operation. The waterfall display would have many valves open and closed.
The benefit of multiplexing to save on wiring interfering with the illusion in an LED cube is good. Not really a concern in my application. The only thing on display and visible would be hidden anyway.