Input Pin.value() always zero unless pin switched on.

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
tecdroid
Posts: 27
Joined: Thu Apr 08, 2021 6:22 am

Input Pin.value() always zero unless pin switched on.

Post by tecdroid » Wed May 18, 2022 5:21 am

Hi there,

just not shure if this is normal behaviour.. that's why i ask here before running an issue
I just loaded a fresh copy of v1.18 on a d1mini.
My goal is to build a simple remote control for my robots and.. it didn't work as expected.
My plan is to use pin irqs to send the pins number via socket connection but my pins were deaf.

So I wrote a little test.. which didn't work, too:

Code: Select all

from machine import Pin
pins = [Pin(x,Pin.IN|Pin.PULL_UP) for x in [14,12,13,15,4,5]]

for pin in pins:
    pin.irq(lambda p: print (p))
I played with a single pin, too and sometimes, it worked.. Finally I found out that I had to switch each pin on befor it really reads a value.
After re-writing my test like this:

Code: Select all

from machine import Pin
pins = [Pin(x,Pin.IN|Pin.PULL_UP) for x in [14,12,13,15,4,5]]

for pin in pins:
    # I just added this line
    pin.on()
    pin.irq(lambda p: print (p))


It worked... But why?
Maybe, pin creation misses some pin initialization? or is this normal behaviour?

Edit: Just in case... here are my files https://gitlab.com/rapp.jens/mp-robot-remote

Post Reply