2 different Ticker Libraries - depend on using a UNO or ESP

I have been exploring the Ticker libraries for use on either ESPs or UNOs

Although both use a file named Ticker.h they are completely different but seem to be allowed to co-exist in the IDE files and have entirely different example files.

When I use a ESP8266-01 the ESP code from the following site compiles and runs OK https://github.com/esp8266/Arduino/tree/master/libraries/Ticker but the same example files supplied with this library will not run on a UNO.

Likewise when programming a UNO I use the following Ticker library https://github.com/sstaub/Ticker but the example code within although calling up Ticker.h will not run on a ESP although both are installed in the IDE.

I suppose this confusion could have been avoided by say the ESP version be called TickerESP.h by the author, not that I'm blaming them as I appreciate their efforts.

Maybe in the ESP code I could just rename the .h file and all reference to in any code a write, would that work?

Comments welcome

What exactly are you wanting to accomplish? Do you want to use https://github.com/sstaub/Ticker or https://github.com/esp8266/Arduino/tree/master/libraries/Ticker with your ESP8266?

What I want to do is write code using Ticker that is portable on original UNOs as well as ESP. Don't want to change code / libraries when I change hardware.


You didn’t really answer my question.

If you want GitHub - sstaub/Ticker: Ticker library for Arduino to always be used for Uno and for ESP8266 then you can accomplish that by adding a library.properties file to the library, which will cause it to have include priority even when compiling for ESP8266. I can give you more information on this if that’s what you’re trying to accomplish.

If you want code that works for what I understand to be the different APIs of GitHub - sstaub/Ticker: Ticker library for Arduino and Arduino/libraries/Ticker at master · esp8266/Arduino · GitHub then you can write your code using preprocessor conditionals:

#ifdef ESP8266
// code using https://github.com/esp8266/Arduino/tree/master/libraries/Ticker API here
// code using https://github.com/sstaub/Ticker API here

Which option is better? I can’t say without taking a close look at the libraries. It might be that Arduino/libraries/Ticker at master · esp8266/Arduino · GitHub is superior to GitHub - sstaub/Ticker: Ticker library for Arduino for the ESP8266 by using some architecture-specific code. On the other hand, the preprocessor option means you must write a bunch of code twice.

Thanks pert for your guidance / comments. I'm going to study the following tutorial that may assist me further in understanding 'preprocessors etc' after which I may refer back to your advice. http://www.deviceplus.com/how-tos/arduino-guide/arduino-preprocessor-directives-tutorial/

Thanks again

Looks like a good overview, which even contains an example similar to what I suggested.

One thing I didn't notice it mention, which is very important, is that you should only use the preprocessor directives when there is no other good option. If you start unnecessarily using this stuff it will make your code extremely difficult to debug and understand, especially if you abuse function macros.

Maybe the esp ticker lib is using freeRTOS, making it impossible to compare which one is better?