Chat freely about anything...

User avatar
By martinayotte
#37973 The reason why the GPIO0 is almost connected to CH_PD is to use GPIO0 as an output HIGH to maintain the CH_PD to HIGH level even if the button is released, and when the code in ESP has finished it job, the ESP turn off itself by simply bringing back the GPIO0 to LOW. (Otherwise, the release button will turn off the ESP instantaneously, which maybe not has finished to do it job)
User avatar
By Barnabybear
#37995
shoelessone wrote:Thanks for this Barnabybear! Yes, this is very similar to what I want to do, although I'll add that I don't fully understand why some of the circuit in this example is setup as it is.. Two questions come to mind:

shoelessone wrote:1. it seems that the person is treating GPIO0 the same way as CH_PD in this sketch. Couldn't they just permanently have GPIO0 pulled HIGH? It's not using power as long as CH_PD is low, correct?


Yes, the reason they used GPIO 0 to hold CH_PD high is they wanted to use the the other GPIOs to control the led. Its not much different other than it made things easier in their application - its not the best idea as when GPIO 0 is set as an output and set low if the switch if closed it will damage the output.

shoelessone wrote:2. This is more of a (very) basic EE question, but one concept I don't fully understand is how, despite the CH_PD being connected to GND through a resistor, CH_PD is pulled HIGH when connected to VCC. In other words, and at the risk of sounding really stupid, I don't quite understand how to figure out why CH_PD isn't pulled low even when the button is pressed, because it is still connected to ground (albeit through a resistor!). And, for example, could a resistor be used between VCC and CH_PD? In the past I've used 4k7 (thanks to Martin's) to pull up/down GPIO pins as needed, including CH_PD, but in the schematic shown the person us connecting directly to vcc. I imagine there is a "fight" between GND and VCC, and the resistor causes GND to "loose" and the CH_PD pin to be pulled high, and perhaps adding a resistor between VCC and CH_PD would cause a less certain outcome?


Yes, you are correct, and a fight is not a bad way to describe it. Two things:
1. A resistor is only a resistor if current is flowing through it, if no current flows its a short. So when the switch is open because no current is flowing (no connection to Vcc) the resistor becomes a short and connects CH_PD to ground. However when the switch is closed, current flows and it becomes a resistor. At this point the voltage difference between Vcc and ground is equily disipated by all the resistors in that part of the circuit. As there is only one, all the voltage will be disipated by it, so one end will be at Vcc and the other will be at ground. As CH_PD is on the Vcc side that is the voltage it will see, untill the switch is opened again.

2. If GPIO 0 is set as an output and set high, it outputs a voltage (Vcc) this also causes current to flow through the resistor and has the same effect. Finaly whe the switch is open and the ESP has completed its tasks it sets GPIO 0 low. No current flows through the resistor and it becomes a short again connecting CH_PD to ground turning off the ESP.

When resistors are used like this they are know as 'pull up' or 'pull down', depending on their connection to Vcc or ground. They are normaly high values 1K and above, that can be overpowered by other parts of the circuit if needed.