I am really new to electronic and wish to learn more. Pardon me if the question is inappropriate.
I am trying to turn a led on, off or dim over the Internet. My question is how can i maintain the state of the led if something happens to the Esp8266, for example the unit get reset or crash. So that the led doesnt go off if it was previous turn on when the Esp8266 rebooting.
My guess is that this might involve some external chip or circuit. When the esp8266 receives a command to turn the led on. it will then forward the state to a chip which powered separately. And so, the chip can power the led even if the esp8266 is rebooting.
I am wondering what the chip or circuit would be? (shift register or etc).
Thanks for the advice.
1 Answer 1
You are correct, if the micro resets, the GPIO state will be lost.
You will need an external chip, but you need to make sure that any intermediate state of the micro's GPIO during reset does not update the external chip's state. This often means putting pull-up or pull-down resistors so that the GPIOs going high-Z doesn't trigger anything.
The external chip could be a shift register with an independently clocked output stage, such as the SN54HC595 or an addressable latch such as the 74HC259.
One other thing I suggest is to feed the outputs from the external chip back to additional GPIOs, set as inputs. This way, when your microcontroller reboots, it can read these GPIOs to see the actual state of these outputs.
-
\$\begingroup\$ Hi @DoxyLover, thanks for the information. Just a few more doubt i would like to seek for your advice. if a shift register is used, how can i provide a independent clock to the shift register and the mcu? Both clocks have to be sync right? \$\endgroup\$HW Siew– HW Siew2016年04月19日 02:07:11 +00:00Commented Apr 19, 2016 at 2:07
-
\$\begingroup\$ In general, the shift register clock is completely independent of any clock going to the mcu. You'd use several GPIO outputs from the mcu: one for the clock, one for data, and one for the load outputs (and maybe one for output enable). Basically, your code would set the data GPIO, then set the clock high and then low (or visa versa if active low) to clock the data into and through the SR. Most shift registers are completely synchronous to the clock and it can come as fast or slow or have as much jitter as you want, as long as you obey the timing restrictions of the device. (continued) \$\endgroup\$DoxyLover– DoxyLover2016年04月19日 05:35:25 +00:00Commented Apr 19, 2016 at 5:35
-
\$\begingroup\$ Running code on a low-MHz clocked mcu, it's almost impossible to overrun most shift registers. \$\endgroup\$DoxyLover– DoxyLover2016年04月19日 05:36:25 +00:00Commented Apr 19, 2016 at 5:36