Plasma 2040 I Can't get a Timer working

Hello,

A bit of Newbee her. Just trying to use a Timer on the Plasma 2040 board.
I have the latest Pimoroni firmware loaded [ pico_usb-v1.23.0-1-pimoroni-micropython.uf2 ]

and I am trying to run a simple timer example code;


from machine import Timer

Create a Timer instance
timer = Timer(0) # Use Timer 0

Define a callback function that the timer will call periodically
def tick(timer):
print(“Timer tick”)

Initialize the timer to call tick every second (1000 milliseconds)
timer.init(period=1000, mode=Timer.PERIODIC, callback=tick)


But on the timer = Timer(0) line
I get the following error “ValueError: Timer doesn’t exist”

Any pointers on what I am doing wrong?

Many Thanks
Ian

I also tried this firmware, [ pico-v1.23.0-1-pimoroni-micropython.uf2 ]

with the same error message in Thonny.

Sorry Solved it by trial and error, I used’

timer = Timer(-1)

Not too sure why this works but it does.
Ian

If you check the Micropython documentation for the RP2 there is a statement: “There is no need to specify the timer id (id=-1 is supported at the moment) as it will default to this.”

https://docs.micropython.org/en/latest/rp2/quickref.html#timers

I find Micropython documentation to be concise and helpful if you just want to get some code written.

1 Like