ESP vs Pico Timer Declaration?
Posted: Wed Aug 17, 2022 1:48 am
Recently was doing some testing across micropython supported controllers, i.e. ports. Pico versus ESP variants. And I discovered the following was required:
The methods IsPico, IsPicoW, IsESP01, etc., actually are my creation, they reference a static dictionary that qualifies what a device is, based on what values are available, unique_id from machine, MAC address from network.WLAN, etc. The issue is how the virtual timer has to be declared.
Here is the interesting part... "theTimer=Timer(-ONE, period=1000*60, mode=Timer.PERIODIC, callback=Ping)" Fails on ESP modules, but works on Picos? Is this by design. intentional? On ESP module, the error returned is "TypeError: function takes 1 positional arguments but 4 were given." So the ESP Timer() invocation can't mirror the Pico invocation at all.
If so, why? Would you not want the same declaration to work on different ports, so make documentation streamline and consistent? Development more universal? Not sure I see the logic of the ESP port working one way versus the Pico port another way.
Code: Select all
from machine import Timer
if (IsPico() or IsPicoW()):
theTimer=Timer(-1, period=1000*60, mode=Timer.PERIODIC, callback=Ping)
elif (IsESP01() or IsESP8266 or IsESP32()):
theTimer=Timer(-1)
theTimer.init(period=1000*60, mode=Timer.PERIODIC, callback=Ping)
Here is the interesting part... "theTimer=Timer(-ONE, period=1000*60, mode=Timer.PERIODIC, callback=Ping)" Fails on ESP modules, but works on Picos? Is this by design. intentional? On ESP module, the error returned is "TypeError: function takes 1 positional arguments but 4 were given." So the ESP Timer() invocation can't mirror the Pico invocation at all.
If so, why? Would you not want the same declaration to work on different ports, so make documentation streamline and consistent? Development more universal? Not sure I see the logic of the ESP port working one way versus the Pico port another way.