ESP8266 Timer and Ticker Example

There are two timers in ESP8266 Timer0 and Timer1, one timer is used by its WiFi functions. We get only one timer to work. To avoid crash issues I recommend use of Ticker instead of Timer. Ticker performs same function as timer.

esp8266 timer

In this tutorial we will see both Timer and Ticker examples

ESP8266 Ticker Example

Ticker is library for calling functions repeatedly with a certain period. Ticker is os_timer Each Ticker calls one function. You can have as many Tickers as you like, memory being the only limitation.  A function may be attached to a ticker and detached from the ticker. There are two variants of the attach function: attach and attach_ms. The first one takes period in seconds, the second one in milliseconds.

LED Blinking using ESP8266 Ticker

This program demonstrates LED blinking ticker example. This function starts timers similar to attach interrupt blinker.attach(0.5, changeState); to stop timer use blinker.detach();

To use Ticker os_timer we need Ticker.h Timer Library

Upload the program and see LED starts blinking at every 0.5 seconds.

ESP8266 Timer Example

Hardware Timer0 is used by WiFi Functions. We can use only Timer1. Use of timer instead of Ticker gives advantage of precision timing and You can get timer interrupt in micro seconds.

Upload program and observe LED Blinking.


Leave a Reply