Chat freely about anything...

User avatar
By vdetez
#78891 Hello,

I have an esp8266-01. I am writing code including #include <ESP8266WiFi.h> via my Arduino env.
In the loop() code, If I have detected that GPIO2 is low, I would like to switch the esp8266 off.
I read that I need to do a digitalWrite(4,LOW); but nothing happens. I check the PIN 4 : CH_PD it's always at HIGH.
Is it well the pin 4 that I have to change? Is it possible to do it?

kr

Valery
User avatar
By QuickFix
#78933
vdetez wrote:I read that I need to do a digitalWrite(4,LOW); but nothing happens. I check the PIN 4 : CH_PD it's always at HIGH.

You've read where? :?

digitalWrite(4, LOW) sets GPIO4 to LOW, not pin 4 (these are NOT the same).
An ESP-01 doesn't even have GPIO4 available, only GPIO0, GPIO1 (AKA TX), GPIO2 and GPIO3 (AKA RX). :idea:
CH_PD needs to be pulled HIGH otherwise the ESP could never run.

In theory you can power down the ESP from code, but in that case you'll have to connect a free GPIO to CH_PD and pull that line LOW when power down is required.

In practice, though I've never done it myself, you can (for instance) connect GPIO2 to CH_PD and pull both HIGH with a resistor (~10k).
In code, you define GPIO2 as output and when necessary do a digitalWrite(2, LOW) when you want to power down.

But... please read my signature regarding using ESP modules when you're new to the ESP8266 (in short: don't). :!: