I am trying to run the following program for the water detect click.I am only able to run it on repl as I am working on the zephyr port of micropython currently.Can someone please guide me how can I get an output of this program.The click board works on GPIO and the pin goes high when it comes in contact with water or any such liquid.I have tried running it on thonny as well, but I can only access the shell there and cant save the program on the board, as I get an error.The code for my error is as follows.
>>> from machine import Pin
>>> waterdetect= Pin(("GPIO_0", 29), Pin.IN)
>>> if waterdetect.value(1)
>>> while true:
... if waterdetect.value(1)
... print("1"):
... else
... print("0"):
Thank you very much!!
Problem running Micropython program on REPL
- OlivierLenoir
- Posts: 126
- Joined: Fri Dec 13, 2019 7:10 pm
- Location: Picardie, FR
Re: Problem running Micropython program on REPL
Can you try this?
Depending on your schematic, you may have to use Pin(29, Pin.IN, Pin.PULL_UP) or Pin(29, Pin.IN, Pin.PULL_DOWN).
Code: Select all
from machine import Pin
waterdetect = Pin(29, Pin.IN)
if waterdetect.value():
print('1')
else:
print('0')
Olivier Lenoir
https://gitlab.com/olivierlenoir
https://gitlab.com/olivierlenoir
Re: Problem running Micropython program on REPL
Thank you very much Olivier.It worked.