GPIO always high

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
mradovan
Posts: 3
Joined: Sun Oct 11, 2020 4:32 pm

GPIO always high

Post by mradovan » Wed Dec 23, 2020 4:24 pm

Hi,
I want to read digital state at Pin 15, but it is always 1, although there is fresh flashed firmware (esp32-idf3-20191220-v1.12 and also esp32-idf3-20200902-v1.13).

The code is very simple:

Code: Select all

from machine import Pin
from time import sleep
led = Pin(2, Pin.OUT)
button = Pin(15, Pin.IN)
while True:
  button_state = button.value()
  led.value(button_state)
  sleep(0.1)
Pins 2 and 15 are not connected, but the LED is on (and should not be). I tried with both of this firmwares (both are stable versions). And I tried with two different devices. The result is the same. What's the problem?

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

Re: GPIO always high

Post by Roberthh » Wed Dec 23, 2020 4:59 pm

What's the problem?
The problem is most likely, that Pin 15 is not connected and therefore floating. In that state, the value read back is not defined. It can be low or high. I assume that the led is connected to Pin 2. On the Wemos boards I have the LED is connected to Pin 5.

ellisjr
Posts: 24
Joined: Sun May 17, 2020 8:30 pm

Re: GPIO always high

Post by ellisjr » Wed Dec 23, 2020 5:03 pm

Maybe it's the way you copied your program, but that looks like an empty While true: loop followed by one go at copying button.state to the LED
John Ellis
What cannot go wrong, will. What definitely cannot go wrong absolutely will... :roll:

mradovan
Posts: 3
Joined: Sun Oct 11, 2020 4:32 pm

Re: GPIO always high

Post by mradovan » Wed Dec 23, 2020 5:28 pm

No, I don't think it is up to While Loop. After I reset the device, entered this directly into the shell:
>>> from machine import Pin
>>> led = Pin(2, Pin.OUT)
button = Pin(15, Pin.IN)
>>> print(button.value())
1
>>> print(led.value())
0

But with GPIO4 works good.

Tnx for advances!

User avatar
Mike Teachman
Posts: 155
Joined: Mon Jun 13, 2016 3:19 pm
Location: Victoria, BC, Canada

Re: GPIO always high

Post by Mike Teachman » Thu Dec 24, 2020 12:32 am

GPIO15 is an ESP32 strapping pin, used to configure silencing of boot messages. It has an internal pull-up resistor which gives you the '1' reading when nothing is connected to the pin. If you ground the pin you should read a zero.

Post Reply