If you have been following this blog, or following me(@varunkumar) on Twitter, by now you would have found out that I am a big fan of JavaScript. JavaScript is everywhere. You can use it to write web servers. You can run it on your mobile devices. You can even use it as a build tool. And, of course, you can use it in its original home, the browser. But, what about running it on embedded devices? Can we control robots with JavaScript? Yes, developers have been successful in controlling robots with JavaScript. Read this interesting article on JavaScript robotics: "The Rise of JS Robotics". In the rest of this post, I will talk about Johnny-Five, a cool JavaScript framework for interfacing with Arduino boards. I will also show how easy it is to build a Tweet notifier (LCD display connected to an Arduino board displaying the count of mentions from Twitter).
What is Johnny-Five?
Johnny-Five is a JavaScript Arduino programming framework written by the awesome JavaScript developer Rick Waldron (@rwaldron). The framework which can be installed as a node module uses Firmata protocol to communicate with Arduino boards. Firmata is a generic protocol for communicating with microcontrollers from software on a host machine. Johnny-Five is a JavaScript implementation of the Firmata protocol which provides easy-to-use modules for interfacing with Arduino boards. Check it out here. Video
Getting started
- Preparing your Arduino board. The first thing you need to do is to flash your Arduino board with Firmata. You can do it from Arduino IDE (File > Examples > Firmata > StandardFirmata). I tried it out on a Mega ADK board. Now, one end of your communication is ready. Software on the host machine will communicate this board using Firmata protocol.
- Installing Johnny-Five. As mentioned above, Johnny-Five is a node module and can be installed using npm (npm install johnny-five). johnny-five depends on node modules firmata and serialport. Note: You might have to build serialport for your environment using "node-gyp configure build".
- Writing Hello, world! In the context of Arduino, writing a hello world is nothing but glowing an LED. You have to write a Node.js JavaScript file and include johnny-five module.
Arduino Tweet notifier
This is just a fun hack I have built with Johnny-Five (This is just for demo. You can do much more with JF). I have connected a 16x2 LCD display to an Arduino Mega ADK board (pins 8-13) and was writing data on it using Johnny-Five. Then, I have employed nTwitter module to get the stream of mentions from twitter. Whenever someone mentions @varunkumar on twitter, LCD will display a notification for the same. Check out the code here.
References:
Johnny-Five. Link.
Arduino & LCD getting started. Link.
-- Varun