Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.

FreeRTOS support for Adafruit sensors
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

FreeRTOS support for Adafruit sensors

by dsxoiniana on Sun Jun 21, 2020 7:12 pm

Hi there,

I've started exploring FreeRTOS and it's only now that I realize it's a completely different framework compared to the typical Arduino like programming. I have a rather complex LEGO robotic arm and all the motors are driven by Adafruit Motor Shields. I have also included a couple of Adafruit INA219 to measure power consumption for various components of the project. So the question is basically, is there a straightforward way to still use Adafruit libraries for these sensors/shields in a FreeRTOS setup? I understand that FreeRTOS mainly uses C, whereas the libraries are written in C++, is this correct?

Posts: 51
Joined: Mon Nov 25, 2019 4:41 pm

Re: FreeRTOS support for Adafruit sensors

by westfw on Tue Jun 23, 2020 5:42 am

First of all, there is no reason that an operating system written in C can't support C++ programs.

I'm not familiar with FreeRTOS, but in general an embedded OS provides two types of services:

1) multitasking - A scheduler and context switching thing that run tasks and switches between them (either at time intervals, or when a task tells the OS that it needs to wait for something.) This is the part that isn't normally part of Arduino.

2) Drivers - libraries for common peripherals, or that perform common tasks.

To run a driver for something like the INA219, there are several choices:
a) look for a FreeRTOS driver for it. It probably doesn't exist.
b) use the Arduino driver essentially as-is. As long as there is no FreeRTOS service that is using the same resources, you might get away with this with no changes at all. Alternately, you can wrap the arduino driver inside "stop doing FreeRTOS stuff while I do this other thing." As long as it doesn't interfere with other tasks...
c) some intermediate scheme. The INA219 is an I2C device. On Arduino is uses the "wire" library to do the low-level I2C stuff, but the rest is probably quite generic. There is probably an I2C library for FreeRTOS (at least on many chips), so you can use the general code from the Arduino Library, and replace the "wire" calls with the FreeRTOS equivalents. This is probably the best solution, and it shouldn't be very difficult.
d) you can write a native FreeRTOS driver from the ground up...

Posts: 1721
Joined: Fri Apr 27, 2007 1:01 pm
Location: SF Bay area

Please be positive and constructive with your questions and comments.