Pin.IN value always 1

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
feiming
Posts: 1
Joined: Fri Oct 26, 2018 4:16 pm

Pin.IN value always 1

Post by feiming » Sat Oct 27, 2018 1:39 am

Hi, I'm new to this micropython and esp8266.

I'm trying to read pin value. It always return 1 even when there's nothing connected to the pin.
how do I make sure it's reading correct value?

[code]
>>> from machine import Pin
>>> pin = Pin(14, Pin.IN)
>>> pin.value()
1
[/code]

Christian Walther
Posts: 169
Joined: Fri Aug 19, 2016 11:55 am

Re: Pin.IN value always 1

Post by Christian Walther » Sat Oct 27, 2018 9:14 am

The state of an input pin is undefined when there is nothing connected to it. Have you tried connecting it to GND or 3.3V? (This applies to all digital circuits, not just the ESP8266.)

Scarsz
Posts: 6
Joined: Sat Nov 03, 2018 8:03 am

Re: Pin.IN value always 1

Post by Scarsz » Sat Nov 03, 2018 8:08 am

You can use the Signal class to invert the output, if that's what you're going for

signal = machine.Signal(pin, invert=True)
signal.value() # 0 if not connected to ground, 1 if connected to ground

Post Reply