Wednesday, March 9, 2011

Android as a User Interface to your Hardware Projects

In my Humidity Temperature Light and Pressure Project (HTLPSensorNode), I showed you the benefits of using Android for the data visualization of a hardware project. The communication was solely based on the Arduino having a connection to my network via WiFi or LAN and the Android device requesting data on the Arduino in a pseudo REST communication protocol.

This might be sufficient if you only have one project with which you want to interact, but sometimes you have a bunch of projects with different purposes. So what might be a good solution if you want to visualize/control several projects with one Android app?

Right now I am implementing my second revision of an Android to Arduino interfacing app.
It is designed in a dynamic way so that it could scale pretty well. Dynamic in this case means that the applications user interface will adapt to the data which is received.

So imagine a project like the HTLPSensorNode. It's a measurement project so you would only need to display data. In another project you might just need to control a servo, so you would need some movement buttons instead of visualization. You can achieve this by defining your own communication protocol where your hardware project dictates what should be displayed to the user of the Android device.

And now the really interesting part. How can you address your projects from your Android device? There are several possibilities which you could use. You could "hardwire" each URL of your projects, you could request data from a webservice, and so on. I took another approach.

I am a big fan of the openness and the synergy effects of the Android platform so I thought about some apps which I could use to "connect" to my projects. There is an app called Barcode Scanner which is around for quite some time now. It scans many types of barcodes and it is just perfect for scanning QR codes.
So what I did was to generate QR codes for my projects in the form of an URL.


...translates to:

You can generate your own QR codes here.

In the Android world apps communicate via so called Intents. Intents are actions which your app wants to do. So it only tells the system what to do but not how. The system then looks for installed applications which can serve the app's request. If there are several applications which are registered in the system that could serve for that particular request then the user can decide which one to use. Sometimes however there are situations where no application can serve that request and the user has to install some app from the Android market. To spare the user some irritation the team behind the Barcode Scanner has provided a small integrator library which you can integrate into your app. What it does is to check if the user has installed the Barcode Scanner app before trying to start it for scanning purposes.
You can find a detailed description on how to integrate it here.

After I attached the generated QR codes to my projects the workflow is as following.

1. Start up the Android visualization/control app.
2. Hold up device infront of your project.
3. Initiate scan via Barcode Scanner.
4. Fire a request to the scanned URL.
5. Receive the data from your project.
6. Parse the response and dynamically build your user interface on the Android client.
7. Repeat steps 2-6 for your other projects.

It's a quite charming approach and it could be a perfect user interaction for the art geeks among yourselves. Just imagine a user exploring your exhibition or art project and interacting with it with his dearest companion, his smartphone.

Since I didn't have time to make a demo video or to provide a finished prototype, I thought it would be best to share at least the concepts and the theory. My prototype worked quite well with that concept and if I have time I will post a short demo.

Until then, have fun experimenting.

No comments:

Post a Comment