OpenSprinkler Forums Hardware Questions OpenSprinkler Pi (OSPi) How to read current station status? Re: Re: How to read current station status?

#24841

Ray
Keymaster

Sorry guys, just had time to read the thread here, and I can help answer some of the questions:

– The control of shift register is a one-way communication: the microccontroller or RPi sends command and the shift register changes state. Your program usually has a variable that stores the current state of the shift register (for example, in OpenSprinkler firmware, it’s an array called station_bits). Since the microccontroller is single-threaded, the firmware variable and the actual state of the shift register should always match. The only exception is when there are signal interference, which may cause a bit flip on the shift register. This is why the OpenSprinkler firmware refreshes shift register every second to ensure it matches the firmware variable. Now, on RPi, since you can potentially run multiple processes / threads that simultaneously write to shift register, you need to be careful to avoid concurrent writing.

– Contrary to what was mentioned in this thread earlier: when updating the 74HC595 shift register, the stations will NOT all reset, that’s why you don’t see all valves close first, and then one of them re-opens. This is because the 74HC595 shift register has a storage buffer and an output buffer. When a new byte comes in, it gets stored in the storage buffer first, and then latched to the output buffer. The ‘latching’ step is controlled by a low-to-high rise on the latching pin. Before the latching pin is pulled from low to high, you can update the storage buffer as many times as you want, and these will not be reflected in the output buffer. The shift register will ‘dump’ the storage buffer to output buffer on the low-to-high rise of the latching pin. Hope I’ve explained this clearly.

Not all shift registers have the latching pin. For example, 74HC164 does not. So whatever you are writing to the shift register gets reflected on the output immediately.

– I wrote the microcontroller-based OpenSprinkler firmware, but if you want to know more about the RPi-based version, Dan is the best person to ask. On the microcontroller, everything is serialized, and when the controller is switched from program mode to manual control mode, all stations will reset first. So there is no question of a manual control ‘interrupting’ a program — all stations would have been closed before the manual control mode is turned on.