As the title says... Chat on...

User avatar
By cal
#13357 Moin,

I would expect https://github.com/nodemcu/nodemcu-firm ... n#gpioread to provide what you want.

Or did I miss something?

Carsten
Michael Lee wrote:Good day,
node.key and node.led have been removed from the API. I can work out how to turn the LED on and off (
Code: Select allgpio.write(0, 1)
) but I can not work out how to read button presses.

Cheers,
Michael
User avatar
By Michael Lee
#13762 I've tried reading from 0 but it always returns zero. It also does not provide a trigger when the button is pressed. The api for "key" suggests that it fires an event. Trigger seams to be the api for that but it is not supported for this pin.

Thanks.
User avatar
By draco
#13879
Michael Lee wrote:I can not work out how to read button presses.


I've never used the 'official' board with a button on it, so I'm not sure how it's wired, but in general I would try this below. The documentation says the button is on GPIO16, which should be pin 0 on all firmwares since 2014-12-19. If your firmware is older than that, you'll probably need to upgrade it.

Code: Select allpin = 0
gpio.mode(pin, gpio.INPUT)
result = gpio.read(pin)


I guess it's possible that the button is wired in such a way that you need to use the pullup resistor?
In which case you could instead use
Code: Select allgpio.mode(pin, gpio.INPUT, gpio.PULLUP)