GPIO-Reset-button?

RP2040 based microcontroller boards running MicroPython.
Target audience: MicroPython users with an RP2040 boards.
This does not include conventional Linux-based Raspberry Pi boards.
Post Reply
kurtHansen
Posts: 3
Joined: Mon Dec 27, 2021 10:01 am

GPIO-Reset-button?

Post by kurtHansen » Mon Dec 27, 2021 4:16 pm

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?

kurtHansen
Posts: 3
Joined: Mon Dec 27, 2021 10:01 am

Re: GPIO-Reset-button?

Post by kurtHansen » Wed Dec 29, 2021 11:33 am

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

hippy
Posts: 130
Joined: Sat Feb 20, 2021 2:46 pm
Location: UK

Re: GPIO-Reset-button?

Post by hippy » Wed Dec 29, 2021 4:57 pm

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.

kurtHansen
Posts: 3
Joined: Mon Dec 27, 2021 10:01 am

Re: GPIO-Reset-button?

Post by kurtHansen » Thu Dec 30, 2021 4:08 pm

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?

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)
    

Post Reply