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

User avatar
By lotus49
#87127 Firstly, I did search here and to my considerable surprise got the following response “No posts were found because the word esp-01 is not contained in any post.” which clearly cannot be true. I also spent an hour trawling the web trying to find out how to boot it but there was so much conflicting information that I am no wiser.

I have written a sketch that works perfectly on a NodeMCU. For the production version (this is just a hobby project but you know what I mean) I want to use one of the ESP-01s that I have as I only need a single GPIO input and it seems wasteful to use a full development board when I don’t need to. My sketch publishes an MQTT message based on a sensor input.

When I upload the sketch to my ESP-01 using my ESP-01 programming/UART adapter it works as expected in that it boots and outputs the appropriate MQTT messages. I obviously cannot connect the sensor to the ESP-01 while it is attached to the adapter so the MQTT message always says “OFF”.

When I try to boot it using a separate 3.3V power supply, I connected GND, VCC and connected CH_PD to VCC and it does boot successfully And published the same MQTT messages. However, when I connect the sensor to GPIO2, it’s not clear what’s happening but it doesn’t publish any messages so it looks like it’s not booting.

I presume that there is something I need to do either in the code or in hardware to get it to boot while GPIO2 is connected as an input. GPIO2 will either be HIGH or LOW depending on the status of the sensor at boot time. What am I missing?
User avatar
By lotus49
#87144 I have been doing some more digging with this and I've sort of got it working but not in a way that is either useful nor that I understand.

If I disconnect the sensor (on GPIO2) at boot time, leaving GPIO0 and GPIO2 unconnected with Vcc and CH_PD connected to +3.3V and GND connected to 0V it boots and then when I connect the sensor to GPIO2, it works, correctly reporting the status of the sensor.

Obviously, this isn't much use but I'm getting closer. Nothing I've seen in my research suggests that the state of GPIO2 matters at boot time. What am I doing wrongly?
Last edited by lotus49 on Sun May 17, 2020 6:23 am, edited 1 time in total.
User avatar
By schufti
#87147 ignoring the fact that the state of gpio2 at boot time does matter indeed?
It might not be mentioned around here (but at least it is mentioned gpio2 has to be high) because it is not bringing esp into a state usefull in arduino but it does matter in fact!
reading espressif documentation (vs. just googling) helps a lot: 0d-esp8266_pin_list_release_15-11-2014.xls and others.
User avatar
By lotus49
#87155
schufti wrote:ignoring the fact that the state of gpio2 at boot time does matter indeed?
It might not be mentioned around here (but at least it is mentioned gpio2 has to be high) because it is not bringing esp into a state usefull in arduino but it does matter in fact!
reading espressif documentation (vs. just googling) helps a lot: 0d-esp8266_pin_list_release_15-11-2014.xls and others.

So if I understand this correctly, I do need GPIO2 to be pulled up to Vcc at boot time. I assume (usually a dangerous thing to do but there you go) that there is an internal pull up resistor as leaving it disconnected works.

However, this then raises the question of how I subsequently use GPIO2 as an input if it's pulled up to Vcc by a resistor. I could use one or the TX or RX pins as a GPIO and use that as the input but is this the only solution? Is it not possible to use GPIO0 or GPIO2 as an input unless you can guarantee that the sensor's output will be high at boot time (something I cannot guarantee with my sensor as the output could be either high or low)?