I was interested to follow this guide to doing an Arduino FreeRTOS install. It’s a good tutorial and my post here just adds a few more notes around areas that didn’t immediately make sense to me.
Arduino FreeRTOS
This section has a few notes about following the guide, and a couple of things that might not be obvious on first reading.
Basic Usage
I didn’t see on my first reading of the blog post that there are examples available at the github repository, such as the one for Blink_AnalogRead . Going directly to those examples would probably have saved my a bit of confusion.
Compiling an ‘Empty’ sketch with just the import of
#include <Arduino_FreeRTOS.h>
ran with no problems
As did defining parameters
// define two tasks for Blink and AnalogRead void TaskBlink( void *pvParameters ); void TaskAnalogRead( void *pvParameters );
From the code in the blog post itself, there seemed to be a couple of typos – an extra ;
after “Blink” and “Analog Read” in the xTaskCreate function calls.
Updating the loop function
For the loop function with power saving code to work you need to also include
#include <avr/sleep.h>
which is one of the AVR libraries
Specific details on sleep are available here
Task Status Example
There is a nice example on the GitHub repository which includes the blinking of an LED and the option to switch the blinking on or off via the sub connection.
One way to control that blinking is with pyserial
Here is a simply python control script. Note that you will need to change the serial port to the one your arduino is connected to. In Linux this will be something like ‘/dev/tttUSB0’.
import serial my_serial_port = 'COM5' ser.write(b's')
To resume blinking use
ser.write(b'r')
which will trigger the vTaskResume() function within the Arduino.
Taking things further
The Arduino FreeRTOS GitHub repository has some ready to go examples which are made with Arduino in mind.
You can also work your way through the FreeRTOS quick start guide.
Youtube has some channels with good videos covering FreeRTOS such as Digi-key and C and Embedded.