ESP32 Virtual Timers??

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
jdts
Posts: 18
Joined: Mon Dec 23, 2019 2:55 pm

ESP32 Virtual Timers??

Post by jdts » Sun May 17, 2020 4:00 am

Does MP actually support virtual timers on ESP32? The documentation sure claims so, but the example given to demonstrate it doesn't even run correctly, and:

Code: Select all

>>> Timer(-1)==Timer(-1)
True

patrickw
Posts: 12
Joined: Sat Feb 01, 2020 7:51 pm
Contact:

Re: ESP32 Virtual Timers??

Post by patrickw » Sun May 17, 2020 5:58 am

What board and firmware are you running?

This is my setup IDF4 nightly build:

Code: Select all

>>> import os
>>> os.uname()
(sysname='esp32', nodename='esp32', release='1.12.0',
version='v1.12-452-g801f7dca7 on 2020-05-14', machine='TinyPICO with ESP32-PICO-D4')
This ran fine on my board.

Code: Select all

from machine import Timer

tim = Timer(-1)
tim.init(period=5000, mode=Timer.ONE_SHOT, callback=lambda t:print(1))
I don't understand the point of Timer(-1)==Timer(-1) but it is also True on my board.

jdts
Posts: 18
Joined: Mon Dec 23, 2019 2:55 pm

Re: ESP32 Virtual Timers??

Post by jdts » Sun May 17, 2020 7:05 pm

Code: Select all

>>> os.uname()
(sysname='esp32', nodename='esp32', release='1.12.0', version='v1.12-35-g10709846f on 2019-12-29', machine='ESP32 module with ESP32')
Yes you can run one timer callback, but the example has two calls with a virtual timer. You never see the "1", since the 2nd overwrites the first, as it would for a fixed hardware timer:

Code: Select all

=== tim = Timer(-1)
=== tim.init(period=5000, mode=Timer.ONE_SHOT, callback=lambda t:print(1))
=== tim.init(period=2000, mode=Timer.PERIODIC, callback=lambda t:print(2))
>>> 2
2
2
2
2
2
2
2
2
2
...
It appears there are only 4 timers on the ESP32, and -1 is the same as 3:

Code: Select all

>>> Timer(-1) == Timer(0)
False
>>> Timer(-1) == Timer(3)
True

Post Reply