Hello all!
I am quite new with the Pi Pico. At home I have some normal Pis running as Radio, Calendar and Camara for Birds... However with a Pico I did nothing in the past.
So, please be not so hard to me
I am trying to rebuild a Sport-Timer like a KondiMaster. So far it works good but I have a question there I need your help.
I am searching for a solution for a GPIO-Reset-button.
Let say you start the program 10sec Action / 10sec Break. Than it should be possible to stop the program by pressing a button.
I could cut off the Power and turn it on again but I think that is not the best solution.
Have you any idea?
GPIO-Reset-button?
-
- Posts: 3
- Joined: Mon Dec 27, 2021 10:01 am
Re: GPIO-Reset-button?
The Pico has the possibility to restart by using the "run" - GPIO.
That is the behavior I need. Is it ok to use it or could it be, that it destroy my main.py?
I found it here:
https://www.tomshardware.com/how-to/ras ... ts-3685247
That is the behavior I need. Is it ok to use it or could it be, that it destroy my main.py?
I found it here:
https://www.tomshardware.com/how-to/ras ... ts-3685247
Re: GPIO-Reset-button?
You probably don't need to restart the whole chip, can probably just monitor the button input pin and act on it. But it shouldn't do any harm, 'main.py' will be there and should restart after a reset.
-
- Posts: 3
- Joined: Mon Dec 27, 2021 10:01 am
Re: GPIO-Reset-button?
Hello hippy!
Thank you for answer! How could your suggestion look like?
Please have a look to the code. What command would restart the script?
Thank you for answer! How could your suggestion look like?
Please have a look to the code. What command would restart the script?
Code: Select all
import sys
import utime
from machine import Pin, Timer
actionLed = machine.Pin(21, machine.Pin.OUT)
pauseLed = machine.Pin(22, machine.Pin.OUT)
resetButton = machine.Pin(5, machine.Pin.IN, machine.Pin.PULL_UP)
timer = Timer()
def reset(timer):
# What I need to do here to reset the script?
def resetButtonDebounce(pin):
timer.init(mode=Timer.ONE_SHOT, period=400, callback=reset)
resetButton.irq(handler=resetButtonDebounce, trigger=Pin.IRQ_RISING)
actionLed.value(0)
pauseLed.value(0)
while True:
actionLed.toggle()
utime.sleep(10)
pauseLed.toggle()
utime.sleep(10)