Advertisement

Sri Lanka's First and Only Platform for Luxury Houses and Apartment for Sale, Rent

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

Sunday, September 4, 2016

Quick Hack Arduino Marine Fish Feeder

Anyone who owned a pet would know that the biggest worry you have is when you leave your pets at home on vacation is how to feed them.

I am a novice Marine fish keeper with a 32 Litre Nano Saltwater Fish Only Aquarium. The livestock is not much but I have 2 Clarks Clownfish (Amphiprion clarkii) which are common in Sri Lankan waters, 1 Ocellaris clownfish (Amphiprion ocellaris) which is actually not so common in Sri Lankan waters but imported from Pacific Oceanic waters specifically Indonesia and 1 Sand Gobi which usually stays under the rock. 

Sri Lanka has strict policies on handling Live Rock and Corals in order to protect our shores, so it is almost impossible to find a legal pet store having those. Importing also strictly controlled.

Anyway I wanted a way to feed the fish while I was away on Vacation for 2 days and 1 night. So with this intention I put up a quick hack fish feeder within couple of hours which actually managed to do the job and keep my fish fed and alive. I had to come up with this because Automatic Fish Feeders are also not so common in Sri Lanka and one have to import it from online shops if they really want one.

I had some servos and an Arduino UNO Rev 3 hanging around and managed to put a small step up where Arduino pin 9 is connected to Servo's actuating pin and 5v to power pin and ground pin to ground.

With this small setup I took the Example for Servo Sweep and Managed to modify it so that the Servo does 180 Degrees rotation 5 times every 6 hours.



I took a candy container, cut it to make it shorter and put some holes near the bottom with a hot nail. Then went in the fish food. Finally I used to box lid to hold the servo in place and managed to secure it with rubber bands, powered the Arduino using a 12v power adaptor and voila! I have a Quick hack fish feeder.

You can see the feeder in action below in video,




References

  1. http://www.instructables.com/id/Arduino-Fish-Feeder/