Page 1 of 1

GPIO always high

Posted: Wed Dec 23, 2020 4:24 pm
by mradovan
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?

Re: GPIO always high

Posted: Wed Dec 23, 2020 4:59 pm
by Roberthh
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.

Re: GPIO always high

Posted: Wed Dec 23, 2020 5:03 pm
by ellisjr
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

Re: GPIO always high

Posted: Wed Dec 23, 2020 5:28 pm
by mradovan
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!

Re: GPIO always high

Posted: Thu Dec 24, 2020 12:32 am
by Mike Teachman
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.