The use of the ESP8266 in the world of IoT

User avatar
By khoih-prog
#89729 TimerInterrupt_Generic Library

TimerInterrupt_Generic Library

How To Install Using Arduino Library Manager

This library enables you to use Interrupt from Hardware Timers on supported Arduino boards such as AVR, ESP8266, ESP32, SAMD, SAM DUE, nRF52, Teensy, Nano-33-BLE, etc.

As Hardware Timers are rare, and very precious assets of any board, this library now enables you to use up to 16 different ISR-based timers, while actually consuming only 1 Hardware Timer. Timers' interval is very long (ulong millisecs). The most important feature is they're ISR-based timers. Therefore, their executions are not blocked by bad-behaving functions or tasks. This important feature is absolutely necessary for mission-critical tasks.

Why do we need this [b]TimerInterrupt_Generic Library[/b]

Imagine you have a system with a mission-critical function, measuring water level and control the sump pump or doing something much more important. You normally use asoftware timer to poll, or even place the function in loop(). But what if another function is blocking the loop() or setup().

So your function might not be executed on-time or not at all, and the result would be disastrous.

You'd prefer to have your function called, no matter what happening with other functions (busy loop, bug, etc.).

The correct choice is to use a Hardware Timer with Interrupt to call your function.

These hardware timers, using interrupt, still work even if other functions are blocking. Moreover, they are much more precise (certainly depending on clock frequency accuracy) than other software timers using millis() or micros(). That's necessary if you need to measure some data requiring better accuracy.

Functions using normal software timers, relying on loop() and calling millis(), won't work if the loop() or setup() is blocked by certain operation. For example, certain function is blocking while it's connecting to WiFi or some services.

The catch is your function is now part of an ISR (Interrupt Service Routine), must be lean and mean, and follow certain rules. More to read on:

HOWTO Attach Interrupt

Important Notes:

1. Inside the ISR function, delay() won’t work and the value returned by millis() will not increment. Serial data received while in the ISR function may be lost. You should declare as volatile any variables that you modify within the attached function.

2. Typically global variables are used to pass data between an ISR and the main program. To make sure variables shared between an ISR and the main program are updated correctly, declare them as volatile.

Releases v1.3.1

1. Add many complex examples.
2. Add board Version String.
3. Fix SAMD bug.

Releases v1.3.0

1. Add NRF52_MBED_TimerInterrupt Library to support NRF52840-based board using mbed-RTOS such as Nano-33-BLE.
2. Add support for UNO, Nano, Mini, Arduino Ethernet, Fio, BT, LilyPad, Pro, Pro Mini, NG, UNO WiFi.

Releases v1.2.0

1. Add STM32_TimerInterrupt Library

Releases v1.1.0

1. Initial Super-Library coding to merge all TimerInterrupt Libraries

Currently Supported Boards

- ESP8266
- ESP32
- AdaFruit Feather nRF52832, nRF52840 Express, BlueFruit Sense, Itsy-Bitsy nRF52840 Express, Metro nRF52840 Express, NINA_B302_ublox, NINA_B112_ublox etc..
- Arduino SAMD21 (ZERO, MKR, NANO_33_IOT, etc.).
- Adafruit SAM21 (Itsy-Bitsy M0, Metro M0, Feather M0, Gemma M0, etc.).
- Adafruit SAM51 (Itsy-Bitsy M4, Metro M4, Grand Central M4, Feather M4 Express, etc.).
- STM32 (Nucleo-144, Nucleo-64, Nucleo-32, Discovery, STM32F1, STM32F3, STM32F4, STM32H7, STM32L0, etc.).
- STM32F/L/H/G/WB/MP1 (Nucleo-64 L053R8,Nucleo-144, Nucleo-64, Nucleo-32, Discovery, STM32Fx, STM32H7, STM32Lx, STM32Gx, STM32WB, STM32MP1, etc.) having 64K+ Flash program memory.
- Teensy boards such as :
- Teensy 4.1, 4.0
- Teensy 3.6, 3.5, 3.2/3.1, 3.0
- Teensy LC
- Teensy++ 2.0 and Teensy 2.0

- Arduino AVR boards such as :
- Arduino Uno / Mega / Leonardo / Duemilanove / Diecimila / LilyPad / Mini / Fio / Nano etc.
- Sanguino
- ATmega8, 48, 88, 168, 328
- ATmega8535, 16, 32, 164, 324, 644, 1284
- ATmega64, 128
- ATtiny 84 / 85

- Arduino SAM DUE.


B. ESP8266

1. Argument_None
2. ISR_RPM_Measure
3. ISR_Switch
4. ISR_Timer_4_Switches
5. ISR_Timer_Complex
6. ISR_Timer_Switch
7. ISR_Timer_Switches
8. RPM_Measure
9. SwitchDebounce
10. TimerInterruptTest
11. Change_Interval
User avatar
By davydnorris
#89730 Is it possible to set up a dedicated topic for all of khoih-prog's notifications?

Firstly they are all Arduino specific so should probably go under the Arduino forum and secondly they are not almost all not IoT related and are effectively spamming this topic.

I appreciate you want to post about updates but perhaps set up a dedicated channel - will make it easier for people who use these libraries to follow then