Donation

If you found the contents in this blog useful, then please make a donation to keep this blog running. You can make donations via Skrill with email address shazin.sadakath@gmail.com

Saturday, September 24, 2016

Advanced Arduino Programming : Threads, Semaphores and Mutexs with ChibiOS-Arduino

Arduino is a great tool for rapid prototyping. It has a good Hardware and Software platform to quickly get started. But when it comes to Advanced Software concepts like Threads, Semaphores and Mutexes the Vanilla Arduino IDE doesn't have much to offer.

That is where ChibiOS comes in. ChibiOS is Real Time Operating System (RTOS) which is intended for Embedded system. Likely ChibiOS has a port for Arduino which can be used in Arduino IDE as a Library.

Using this allows Parallel code execution, Synchronized code excution and many more possible in Arduino. Previously I have done a small project to show Temperature and Humidity on 8x2 LCD Display.

This project has two parts, a Sensor Input Reading and LCD Output Writing both of which are done inside the void loop() section of the Arduino Sketch. But as we all know Input and Output are tasks can sometimes take longer than expected. For Ex:- During Network Input and Output.

So It is better to Parallelize the Input and Output. This can be achieved with ChibiOS-Arduino Library.

So I used the same setup from the aforementioned post with Threads this time to separate Read and Write. Plus Reading will take place every 200 Milliseconds but Writing will take place every 1000 Milliseconds (1 Second). And Read Thread and Write Thread communication is done via a Semaphore. Write Thread will wait on the Semaphore for data to be available and Read Thread will Signal on the Semaphore whenever data is available. So the Serial output for the Arduino Program will look like following, 1 Output Thread for 5 Input Threads


The full Arduino Sketch is following;



References

  1. ChibiOS
  2. ChibiOS-Arduino
  3. Getting Started With ChibiOS

1 comment:

Jeffy said...


Thank you for sharing such a nice and interesting blog with us. I have

seen that all will say the same thing repeatedly. But in your blog, I had

a chance to get some useful and unique information. I would like to

suggest your blog in my dude circle. please keep on updates. hope it

might be much useful for us. keep on updating...

seo company in chennai

Digital Marketing company in chennai