Use this forum to chat about hardware specific topics for the ESP8266 (peripherals, memory, clocks, JTAG, programming)

User avatar
By hobby_guy
#96177 I have a problem which I can't seem to wrap my head around. Either way I approach this, something gets GND which should have VCC, or other way around, and I come back to the same problem:

How can I have two "sensors" attached (plain old switches, which close to GND), and still support normal boot and boot into "flash mode"? This is using ESP8266 (or ESP-01).

The sensors (switches) are simple "door sensors", which detect if a door is open or closed by reading the corresponding voltage at the pin. The pins are, thus, pulled high (VCC = 3.3V) through 10K resistors, and if the switches are closed then the pins "see" GND. I can't know at any time what state the switches (i.e. doors) are in.

As I understand it, normal boot requires GPIO0 to be floating (or high), and GPIO2 to be high. Flash mode requires GPIO0 to be grounded, and GPIO2 to be high.

My first idea was to remap the RX pin as an input, and use that instead of GPIO0 -- dedicating this to a "boot select" switch. Furthermore, since we need GPIO2 to be high, I had the idea of having this switch simply toggle GND -- to either GPIO0 (boot) or the returns of the external switches. This way, when choosing "flash mode", we essentially disconnect the external sensors in the sense that -- if closed -- they are simply floating, and no longer closing to GND. This also solves the problem of RX (the new input pin) eating the data if that switch (SW2) would happen to be closed. Obviously, the remap (RX to input) only happens when my program is loaded, so the boot loader works as normal. This way, I can keep using TX for "debug output" from my program, to see what (if anything) is going on using a terminal software :)

Image

The "//" in the drawing is to indicate that SW1 and SW2 are external sensors (connected by cables). Not that it matters...

For normal boot, however, this gives a problem. The selector switch will "move" GND back to the sensors, whereby leaving GPIO0 floating. That's good. But, once again we have the problem that GPIO2 needs to be high (during boot). If that switch (SW1) is closed, it now grounds the pin, and we can't boot the firmware.

My question is, how can I ensure that GPIO2 is high (or at least not ground) for the "time required" to do a normal boot? I was thinking maybe something could be done using a capacitor, which would keep the pin high for a brief moment while discharging, but I'm not sure if this is at all how stuff works.

I think this problem (of external sensors affecting boot) might be of interest, so I did this whole writeup. I know I could (probably should) upgrade to ESP32, but I like trying to figure this out...
Last edited by hobby_guy on Wed Apr 05, 2023 1:03 pm, edited 2 times in total.
User avatar
By hobby_guy
#96183 Thanks for replying!

This is a way of internally pulling GPIO2 high? But I don't see how this affects the situation. If GPIO2 is also connected to ground (through a sensor, or a closed switch) then we'd still have a low input at boot time -- causing a improper boot?

Or am I misunderstanding something?