Problem running Micropython program on REPL

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
Yadnik
Posts: 65
Joined: Thu May 13, 2021 6:01 am

Problem running Micropython program on REPL

Post by Yadnik » Wed Jul 21, 2021 7:07 pm

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!!

User avatar
OlivierLenoir
Posts: 126
Joined: Fri Dec 13, 2019 7:10 pm
Location: Picardie, FR

Re: Problem running Micropython program on REPL

Post by OlivierLenoir » Thu Jul 22, 2021 5:28 am

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).

Yadnik
Posts: 65
Joined: Thu May 13, 2021 6:01 am

Re: Problem running Micropython program on REPL

Post by Yadnik » Thu Jul 22, 2021 7:31 am

Thank you very much Olivier.It worked.

Post Reply