Skip to content

Docu: Multiple machine.Timer() instances on ESP8266  #8383

@manuel-91

Description

@manuel-91

There is sadly only a little docu on the timer usage on ESP8266. It shows this example:

from machine import Timer

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))

As it uses the same timer only "2" is printed every 2 seconds, the one_shot "1" is never printed. I tried two instances of Timer(-1) but still only the last one was active. I just tried Timer(-2) and it worked, with Timer(1) and Timer(2) it also worked:

tim1 = Timer(1)
tim2 = Timer(2)
tim1.init(period=2500, mode=Timer.ONE_SHOT, callback=lambda t: print("once"))
tim2.init(period=1000, mode=Timer.PERIODIC, callback=lambda t: print("periodic"))
sleep(3.5)
tim2.deinit()

# expected printout:
# periodic
# periodic
# once
# periodic

There is one thing I'm not sure about I'd like to understand before starting a pull request on the docu:

  1. Is only one virtual (RTOS -based) timer possible on the ESP8266? machine docu mentions Timer(-1) creates a virtual timer - which sounds good as it doesn't affect hardware.
  2. If I create a timer with another ID, will it interfere with PWM or sleep() or time()?

By the way, great project, love it:)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy