Page 1 of 1

Problem running Micropython program on REPL

Posted: Wed Jul 21, 2021 7:07 pm
by Yadnik
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!!

Re: Problem running Micropython program on REPL

Posted: Thu Jul 22, 2021 5:28 am
by OlivierLenoir
Can you try this?

Code: Select all

from machine import Pin
waterdetect = Pin(29, Pin.IN)
if waterdetect.value():
    print('1')
else:
    print('0')
Depending on your schematic, you may have to use Pin(29, Pin.IN, Pin.PULL_UP) or Pin(29, Pin.IN, Pin.PULL_DOWN).

Re: Problem running Micropython program on REPL

Posted: Thu Jul 22, 2021 7:31 am
by Yadnik
Thank you very much Olivier.It worked.