Skip to content
This repository has been archived by the owner on Mar 14, 2023. It is now read-only.
/ SmallProjects Public archive

ISR-based projects demonstrate how to use ESP8266TimerInterrupt, ESP32TimerInterrupt and TimerInterrupt Library

License

Notifications You must be signed in to change notification settings

khoih-prog/SmallProjects

Repository files navigation

SmallProjects Library

arduino-library-badge GitHub release GitHub contributions welcome GitHub issues

Buy Me A Coffee



Why do we need this SmallProjects library

Features

SmallProjects library collects all complicated projects to demonstrate the usage of Khoi Hoang's libraries, such as ISR-based timers for ESP8266, ESP32 and Arduino Mega, Nano, etc. These projects are much more complicated than the ordinary libraries' examples. Some can even be used directly in real-life.

ISR-based Fire Smoke Alarm demonstrate how to use ESP8266TimerInterrupt, ESP32TimerInterrupt and TimerInterrupt Library

These are examples how to use, design and convert the code from normal software timer to ISR-based timer.

Why do we need this Hardware Timer Interrupt?

Imagine you have a system with a mission-critical function, measuring water level and control the sump pump or doing something much more important using extensive GUI, such as medical equipments, security and/or fire-smoke alarm, etc. You normally use a software 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, 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 in cooperation with an Input Pin 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), and must be lean / mean, and follow certain rules. More to read on:

https://www.arduino.cc/reference/en/language/functions/external-interrupts/attachinterrupt/

Important Notes:

  1. Inside the attached function, delay() won’t work and the value returned by millis() will not increment. Serial data received while in the 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.

Design principles of ISR-based Fire and Smoke Alarm

The design principles are as follows:

  1. Fire or Smoke measurement and alarm activation are considered mission-critical, and must not be interfered or blocked by any other bad tasks, intentionally or unintentionally. This principle can be applied to any of your projects. Please check the way ISR-based are designed ( very lean and mean ), no delay() and no unnecessary baggage.
  2. The sound alarm is also considered critical. Alarm without sound has no meaning in life-threatening dangerous situation.
  3. Blynk is considered just a Graphical-User-Interface (GUI). Being connected or not must not interfere with the alarm detection / warning.

Certainly, with Blynk GUI, we can achieve many more great features, such as remote check and control, configurable test case and value , etc. when possible.

This can be applied in many projects requiring reliable system control, where good, bad, or no connection has no effect on the operation of the system.



Changelog

Release v1.0.2

  1. Add STM32_LAN8720 examples

Release v1.0.1

  1. MasterController
  2. SmartFarm_DeepSleep
  3. AutoReConnect

Initial Release v1.0.0

Initial v1.0.0 release of sample codes to demonstrate the usage of ISR-based timers, designed for Arduino (Mega, Nano, UNO, etc.), ESP8266 and ESP32-based boards, by using these Hardware Timers libraries:

  1. TimerInterrupt for Arduino (Mega, UNO, Nano, etc. ) boards
  2. ESP8266TimerInterrupt for ESP8266 boards
  3. ESP32TimerInterrupt for ESP32 boards

Sample codes:

  1. FireSmokeAlarm
  2. FireSmokeAlarm_Arduino
  3. ISR_FireSmokeAlarm
  4. ISR_FireSmokeAlarm_Arduino
  5. ISR_Timer_4_Switches

The corresponding codes using Software Timers are also included to help understand the steps taken in order to convert those codes to be ISR-based.



Installation

Use Arduino Library Manager

The best and easiest way is to use Arduino Library Manager. Search for SmallProjects, then select / install the latest version. You can also use this link arduino-library-badge for more detailed instructions.

Manual Install

Another way to install is to:

  1. Navigate to SmallProjects page.
  2. Download the latest release SmallProjects-master.zip.
  3. Extract the zip file to SmallProjects-master directory
  4. Copy whole SmallProjects-master folder to Arduino libraries' directory such as ~/Arduino/libraries/.

VS Code & PlatformIO

  1. Install VS Code
  2. Install PlatformIO
  3. Install SmallProjects library by using Library Manager. Search for SmallProjects in Platform.io Author's Libraries
  4. Use included platformio.ini file from examples to ensure that all dependent libraries will installed automatically. Please visit documentation for the other options and examples at Project Configuration File


Issues

Submit issues to: SmallProjects issues



Contributing

If you want to contribute to this project:

  • Report bugs and errors
  • Ask for enhancements
  • Create issues and pull requests
  • Tell other people about this library

License

  • The library is licensed under MIT

Copyright

Copyright 2019- Khoi Hoang