After figuring out how to set up the Raspberry Pi and how to communicate between a Raspberry Pi and an Arduino, I wanted to try a simple home-automation project that incorporated several really awesome and useful technologies:
The following diagram shows how all this tech is arranged.
This is by no means the only way to do home-automation, but its a fun project if you don’t mind programming, and there are a lot of advantages to using these particular tools. Having a browser based interface allows you to work the controls from virtually any computer or mobile device. Canvas gives you the ability to create a rich interactive experience for the end-user. KineticJS makes it incredibly easy to make canvas animations. The Raspberry Pi gives you the benefit of a fully functional web server and allows the project to be portable. Node makes developing that web server as well as serial communication with the Arduino quick and easy. Websockets and Socket.IO allow the server to easily push updates to all clients in real time, so if I tweak a slider, everyone viewing the control panel sees me move it. Finally the Arduino gives us an easy way to control the physical world and access to countless libraries including one that helps to work with the RGB LED Pixels .
Here is a video of the whole thing in action:
In my previous tests, Firmata was a great choice for integrating the Pi and Arduino since it simplified the code base – instead of writing a C program for the Arduino, the Arduino was controlled directly from my Node program. In this case however, I opted to leverage this Adafruit Arduino library to work with the RGB LED Pixels. So it made more sense to write a separate Arduino sketch which incorporates this lib and communicates with Node over serial. Couple of things to note:
1. Arduino libraries go in this location:
2. Node serial communication can be done using this package
sudo npm install -g serialport
3. Optional: Since the Arduino IDE is quite slow on the Pi, Ino is a great option for building and uploading arduino code from the command line.
Next, I’d like to take this project further by having a line of communication coming back from the Arduino to the canvas front-end. When multiple clients are looking at the control panel and one user moves the sliders, everyone should see them move in close to real time.
In addition to my desktop browser, I tried this out from my Android device (LG Nexus 4 running Chromium). I was disappointed to find that the animation is clunky and jumpy, and touch control is inaccurate. I’ve heard that unless they’re very simple, canvas animations require extensive optimization to work in mobile browsers. I have friends that are struggling with similar issues, so hopefully there will be some advancement in this area on mobile browsers to make canvas truly universal.
The source code for this project is available here on Github.