Sunday, September 23, 2012

Arduino tweet notifier built with Johnny-Five!

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

Saturday, September 15, 2012

Animated doodle in CSS!

If you are following the developments on web browsers, you must be knowing the kind of changes CSS is going through. Lots of new features are getting added to CSS3 and you can do lots of stuffs with CSS. Here is a short post about an animated doodle which I had built purely using CSS3. I built this animated logo few months ago for a hackathon we had at our workplace. The speciality of this logo is that it is built only using CSS3 - even the circles and rounded corners are built with CSS and no images are used. You can verify the same with the help of any web inspectors. You can hover over the little guy and see him flip his ears, eyes, teeth, arms and legs. I have employed CSS transitions, CSS transforms and others to get the work done. The implementation is complex and not optimal. But, it is built just to demonstrate the power of CSS. Browser support: All latest browsers. The CSS used in this experiment can be found here. If you are not able to view the logo inline, check it out here. Have fun with CSS!! :)

-- Varun

[How to] Install Linux on Android?

As both the Linux and Android OS are open sourced, developers have enjoyed success in porting Linux on to Android and vice versa. Lots of efforts are still going on in this space. Canonical has been busy working on Ubuntu on Android which enables Android devices to run Ubuntu. “Linux on Android” is another awesome project which helps you to install and run a wide range of Linux distros on your Android device. An Android app has been released as part of this project which will guide you through the installation process. I tried it out myself on my Galaxy S2 and the process was very straight forward. Using this app, you will be able to install any distro as this just ‘chroot’ into the Linux image. This technique will run a virtual Linux on top of the Android OS without disturbing your Android OS. You could still use other apps installed on your Android device. We could replace Android with Linux completely but then you wouldn’t be able to use your Android phone as a phone anymore.

Pre-requisites:

  • Android 2.1 or higher. You need to have at least 3.5 GB of free space on your SD card. You can run Linux from internal SD cards as well.
  • Root access. You must have an Android device with Root access.
  • Support for Loop devices. Your Android OS must support loop devices. The stock image on Galaxy S2 didn’t have the support for loop devices. I have flashed the MIUI ROM with a kernel which supports loop devices. 

Steps to install Linux on Android

  • Download and install “Complete Linux Installer” app from Play store. Also, install VNC Viewer and Terminal App from Play store.
  • Launch the application “Complete Linux Installer”. This will guide you through the download links for different Linux distros.
  • Download the image and place it on your sdcard. By default, the launcher looks for the image directly on the sdcard (for ex: /sdcard/ubuntu). This can be configured from the launch menu. You can create a new launch configuration by specifying the image location and a name to it.
  • Select the configuration which you want to launch. This will open up the Terminal app with the chosen Linux image (say Ubuntu) mounted. If everything goes well, you should see this message “root@localhost:/#” on the terminal. This terminal will act like a Ubuntu command line. You can connect to the GUI from any of your favorite VNC viewer app (either on the same device or other devices).
    • You will be prompted for the root password, screen size and other options while mounting the Linux image.
    • If your kernel doesn’t support loop devices, you will get appropriate messages in this phase.
    • If you don’t have sdcard on your device, you might get some mount errors. You can ignore the errors (close the terminal) and re-connect to the mounted device again.
  • You are done. I have tried both LXDE and Unity desktops on S2 and both worked reasonably well.

Terminal Emulator with Ubuntu mounted

VNC Viewer app running on Galaxy S2 connected to Ubuntu running on the same device - LXDE desktop

VNC Viewer app running on Galaxy S2 connected to Ubuntu running on the same device - LXDE desktop

VNC Viewer app running on Galaxy S2 connected to Ubuntu running on the same device - Unity

VNC Viewer app running on Galaxy S2 connected to Ubuntu running on the same device

VNC Viewer running on Mac connected to Ubuntu on Android

VNC Viewer running on Mac connected to Ubuntu on Android

More information about “Linux on Android” can be found here.

-- Varun

google-site-verification: googlea4d68ed16ed2eea6.html