Cannot use GPIO2 (D4) as digital input?

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
nagylzs
Posts: 40
Joined: Sat Jan 19, 2019 8:01 pm

Cannot use GPIO2 (D4) as digital input?

Post by nagylzs » Fri Mar 22, 2019 4:34 pm

If I connect GPIO2 (D4) to GND, then I'm not able to boot my ESP8266. If I connect a serial terminal and reset the device, then it starts sending garbage continuously instead of booting up.
  • I have tested this on a WeMos Mini, a NodeMcu 0.9 board and a normal sized WeMos board.
  • I have completely reflashed all of them before testing, and they behave the same.
  • In order to rule out all possible errors, I have used the bare dev boards (e.g. only the USB cable and the GND -> GPIO2 line was connected, nothing else.)
The most interesting thing is that this pin works fine after the device has booted. I can configure it as digital I/O pin and read 0/1 values from it. But if I connect GND on it before booting, then it simply won't boot.

I was digging through information on GPIO pins and found this:

https://community.blynk.cc/t/esp8266-gp ... es-8/22872

There are certain restrictions about GPIO pins on ESP8266, but in particular GPIO2 (D4) is said to be a "safe pin, first choice". That page also says that GPIO2 is initially LOW. On two of my dev boards, GPIO2 is connected to a LED and it is active LOW (e.g. if I connect GPIO2 to GND, then the LED lights up.) It indicates that GPIO2 is either initially HIGH, or (more probably) it is initially an input pin with a possible pull up or pull down resistor. In any case, it does not seem to be an initially LOW (output) pin. I suspected that this pin might be an initially HIGH output pin, so I have also tried to put a 2.2k resistor between GND and GPIO2 but it did not help either (e.g. won't boot).

Here are some questions:
  • Is there something in MicroPython that prevents GPIO2 pin from using as an (initially LOW) input PIN? Was it somehow configured in the firmware as an output pin (initially)?
  • Or maybe this is a "feature" of my dev boards, and not the ESP module itself?
  • Is it a known phenomenon (for either dev boards or bare ESP modules)?
My biggest problem is that I'm out of GPIO pins and I wanted to connect a sensor to GPIO2. The output of the sensor is initially (and usually) LOW. It makes it impossible to boot my device.

nagylzs
Posts: 40
Joined: Sat Jan 19, 2019 8:01 pm

Re: Cannot use GPIO2 (D4) as digital input?

Post by nagylzs » Fri Mar 22, 2019 4:41 pm

Oh I can answer my own question. I have mixed up GIPO4 with D4 (GPIO2). I see now that this pin must be HIGH at boot time. Sorry for the silly question. It was a good lesson...

nagylzs
Posts: 40
Joined: Sat Jan 19, 2019 8:01 pm

Re: Cannot use GPIO2 (D4) as digital input?

Post by nagylzs » Fri Mar 22, 2019 4:42 pm

But now I wonder if there is a similar description for the ESP32?

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Cannot use GPIO2 (D4) as digital input?

Post by Roberthh » Fri Mar 22, 2019 4:58 pm

The esp32 data sheet at the espressif web site.

Post Reply