2016 Nov 18, 01:01 AM
(2016 Nov 17, 11:11 PM)dan Wrote: There is now a page on the SIP wiki that describes the shift register interface:
https://github.com/Dan-in-CA/SIP/wiki/Relay-interface
I have to admit it is interesting comparing the two hardware approaches. I wasn't aware of the shift register approach until I started looking at the available software solutions for irrigation systems.
The shift register approach is cheaper, and probably also quite easy to lay out on a board. - That said, a layout using a MCP23017 is also easy. The MCP23017 is a more expensive chip however. Each MCP23017 also only gives you 16 GPIOs.
Using an I2C GPIO controller, you don't need to worry about timing in your software.
There is a gotcha with chips like the MCP23017 in that if you have a relay on, and the Pi reboots, the outputs on the MCP23017 stay as is. - You need a way of switching them off when the Pi reboots to ensure that stations don't accidentally stay on if your system crashes or reboots. I have addressed this by tying the !Reset pin of the MCP23017 to one of the GPIOs. As soon as the GPIO goes low (which it will do when the Pi shuts down) the MCP23017 goes into a reset state.
Neither solution provides the ability to reliably drive enough current for a relay - the 74HC595 can drive 35mA on the the parallel outputs. The relays I am using would require a current of 35.93mA (hold current that is). Realistically both solutions still need something like a Darlington transistor array to drive the relays. - Arrays like the ULN2803A also provide integrated flyback diodes which are needed when driving an inductive load (like a relay).
With 20/20 hindsight, I would probably now look at using solid state relays with a zero crossing function to minimise transients generated when relays are switched off.