Task Scheduler on a Photon (for multi-tasking and interrupt handling)

Hey guys,

Has anyone tried using a task scheduler or a similar library that allows you to do some level of multi-tasking on a photon or a core?

I’ve looked at the following library built for an Arduino Due, but wonder what it will take to build one like this for the photon?
https://www.arduino.cc/en/Reference/Scheduler

The main advantage of having something like this is to be able to perform better when you have a piece of code handling communication (via Serial, Cloud, etc) and another piece of code making sure that your UI is handled well (Button reads, LEDs, Switched inputs, feedback loops) etc.

I want to see if any one has suggestions / comments before I get on a journey to start implementing/designing something like this.

Thanks in Advance !

Here are a couple of libs that may accomplish what you want or be a good base to build on.

On the Core, the scheduler looks like a good solution. It’s co-operative scheduling so your code would need to be written to call yeild() at appropriate points.

On the Photon, we already have pre-emptive multitasking from FreeRTOS. 0.4.6 will come with multithreading support available in the system firmware, and with the ability to create your own threads.

3 Likes

Thanks @LukeUSMC,

I am already aware of the IntervalTimer Library and it makes perfect sense to re-use it to dedicate a timer to a scheduler and have tasks called from there. I am still haven’t figured out all the details yet, but would ideally go with this idea.

That’s great @mdma

I am actually more interested in the Photon(since it has a few more timers available) and looking forward to the multi-threading library.

Is there an expected release date for 0.4.6? Also, i’d be more than happy to beta test and compile it locally if you can point me to a branch on which it exists/would exist.

The local branch for multithreading is feature/non-blocking in the firmware repo. 0.4.6 will be released within 2 weeks.

5 Likes

@mdma Thanks for pointing me to the branch.

I checked out the branch, but can’t figure out the usage.

Any tips on what header I should include? and what functions/examples I can use in setup() and loop() to see how mutli-threading can be used? Really appreciate your help!