Friday, November 18, 2011

The ADK Paper Piano at the Google Developer Day 2011 in Berlin

Tomorrow is the Google Developer Day 2011 in Berlin. It's the biggest Google Developer event hosted on an international scale and this year Berlin was one of the eight stops for this event.

Some months ago Google hosted a challenge to promote the Android Accessory Development Kit (ADK) which was presented at its annual Google IO. The challenge was to create something cool with the ADK so that the popularity of the ADK gets a boost among the developer community.

This is the documentation of my project submission which was selected as one of the finalist entries for this years GDD. It's called "The ADK Paper Piano".

I had this idea to build a musical instrument to let the people engage with the project. The first thing I had to think about was how to recognize the pressing of a key on the piano. A while ago I read an Arduino tutorial which described how to build a DIY capacitive touch sensor. The approach was really simple and cheap. You would uitilize one output pin of the ADK board as an output port and connect it to a receiving input pin on the board. Now you periodically set the state of the output pin from LOW to HIGH. The receiving pin measures those state changes. To not damage the board permanently you would put a high valued resistor in series in between the pins to limit the current flow. To this closed circuit you now add a connection to a piece of aluminum foil. The foil is conductive and when you touch it you interfere with the receiving pins capacitance. Your body capacitance adds to that of the receiving pin and result is that the state change of the sending pin is recognized a bit later than usual at the receiving pin. So when a touch happens the state change is slower and you can recognize that it happened and react in your code. The Arduino CapSense library implemented that use case nicely. So naturally my first little prototype was based on that library. Here is a short video of the prototype:

Here you already can see how the piano keyboard is built. You have a base layer of normal paper for insulation. On top you have stripes of aluminum foil which overlap a bit. On top of that you have the layout of the piano keyboard also on a insulating layer of paper.

The only problem of that approach was that a normal piano has 88 keys and the ADK board "only" has 54 IO pins. The solution to that problem was to use shift registers for more inputs. A shift register is a small integrated circuit (IC) which can transmit the states of multiple of its pins by only using a few pins. So I decided to built two modules which host 8 input shift registers.

With those modules I could read 64 input pins by only using 20 pins of the ADK board. Since the whole building process took a long time I decided to scale the piano design down from 88 to 61 keys which is a normal keyboard layout from the note C2 to C7. With the learnings of the CapSense library and some bitshifting techniques I wrote my own implementation of a shiftin capacitive touch sensing library. The manual construction of the keyboard layout and building the connections took most of my time. The coding part was pretty straight forward.

The working principle goes as follows. Periodically all connections are measured by the ADK board. When a user touches a key the corresponding 8-bit shiftin register will report a changed bit. The whole 64 bit message is transmitted via 8 bytes. The Android device receives those 8 bytes determines which bit has changed and plays the corresponding note from a predefined sound array. To be able to play multiple sounds I used the SoundPool class of the Android system. As a visualization I also used the Visualizer class to display the sounds waveform while being played.
Some building steps and the finished ADK Paper Piano can be seen here:


The impressions and some pictures of the GDD event will follow as an update to this post. I hope you like the project and if you are at the GDD in Berlin come by and say hello.


The Google Developer Day 2011 in Berlin was a total success. The Berlin ICC was a great location for the crowd of more than 2000 developers. The atmosphere was very relaxed and the GTUG and Google did an amazing job in the event planning. The conference was divided into differet tracks and sessions featuring Android, Chrome and HTML5, Cloud, Google+ and a special Berlin University track. Additionally there were several exhibitions featuring Google TV, a developer sandbox where different applications were showcased and the exhibition for the ADK challenge finalists. I showcased my ADK Paper Piano in the GTUG ADK challenge area. Here are some photos of the event and a video of the press visit where I explain how the piano works. Also, a local Berlin newspaper featured the piano in an article about the GDD.


Monday, October 17, 2011

GDD11 ADK Challenge / Beginning Android ADK with Arduino

It has been awfully quiet over the last months on this blog and I felt that I should give you guys an update why this is the case. It's not because of missing ideas because I still have plenty of them and a lot of hardware which I want to make use of is lying around catching dust. The reasons why I hadn't the time to post new projects on this blog are very good and positive ones, at least for me they are.

The first reason is that I am one of the finalists of the Google Developer Day ADK Challenge which took place some months ago. The object of the challenge was to create an Android accessory project based on the Android ADK. My submission was a working prototype of a paper piano which worked on the principle of capacitive touch. The touch of a piano key is sensed by an ADK compatible hardware board and propagated to a connected Android device which is Open Accessory compatible. The Android device then plays the according note of that piano key. My project submission was accepted and now I'll have to build a bigger version of my prototype. The final results of that challenge will be presented at the Google Developer Days all around the world. My submission was for the Berlin based German GDD which is held on November 19th. So if you are one of the lucky ones who got tickets for the event make sure to come by at the GTUG showcasing area and say HI. If you are interested in a short preview you can see a video of the prototype here. The final version will be presented at the GDD but I will write a post about the project and my impressions of the event afterwards.

The second reason for my absence in this blog is that some weeks ago the IT book publisher Apress contacted me to ask if I would be willing to put my Android and Arduino knowledge and my passion for tinkering into a book to help others get excited about the possibilities of the Android Accessory Development Kit (ADK). I guess you can already imagine that I agreed and I am happy to tell you that I am already hard at work to write a book that will get others as passionate as I am about the Android ADK. You will learn what the ADK is and how to create exciting projects with it. The book is already listed at Amazon, so make sure to follow its progress until it is released in march 2012.

I would never had those opportunities if it weren't for you the readers of this blog and my friends, family and colleagues which encouraged me to write about my projects and experiments. The feedback I received through my blog gave me the motivation to commit to such large projects which consume most of my free time over the next months. So a big thank you to all of you. I'll try to keep you posted about the progress and I can't wait to share new exciting projects with you in the future.

So long...


Thursday, August 11, 2011

NFC Profile

In my last post I wrote about the NFC capabilities in Android development. As I had so much fun tinkering with NFC and writing that short tutorial I decided to publish my first NFC app in the Android Market.
The app is called NFC Profile and it lets you enable/disable some of your system settings with a simple touch of a NFC tag.

As I was unnerved by disabling my WiFi and setting my ringer to silent each night only to do the exact opposite again in the morning I decided that this made a perfect use case for NFC. The app lets you configure what to turn on/off according to the time of day. Lets you set an Alarm for the next day when toggled into night mode and it even lets you write your profile trigger to a rewritable tag. All in one app. I developed that app solely for fun and learning purposes and I made an open source project out of it. It is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0) License so respect that if you want to use any code.

The code shows how to customize a PreferenceScreen and its PreferenceItems. How to call Activities from a Preference. You can see how to register your Activities for NFC Tag detection and how to write data to a NFC rewritable tag.

You can find the project source at github:
The Android Market link for the app is:

Saturday, July 16, 2011

Android NFC Sleep/Wake Toggle

I experimented a bit with the NFC chip on my Nexus S to solve a problem I had when going to bed at night. My usual routine was to set the phone ringer to silent mode so that nobody wakes me up with a late night drunk call. Then I deactivated my WiFi connection and after that I activated the alarms on my alarmclock. When I woke up the next day (hopefully after my first set alarm) I had to disable my fallback alarm, switch on my WiFi connection and turn the ringer on the phone to normal mode. As this was kind of tedious, I decided to implement a solution with the help of NFC.

NFC or Near Field Communication is a short range wireless technology for data exchange. Data can be written to and read from NFC tags and cards. Those are passive components, meaning that they don't have a battery to operate but draw their power from the magnetic induction happening when a powered reading device is near them. That's what happening when you touch such a tag with your NFC enabled phone.

There is a great talk from this years Google I/O explaining the benefits of NFC and how to incorporate it into your apps.

What you will need in order to tinker around with NFC are rewritable tags, a NFC enabled phone and an app which can write to the NFC tag. I found the Mifare 1K tags to work just great. The most popular and almost only NFC enabled phone right now would be the Nexus S. To write to a rewriteable tag or card you can use the NXP TagWriter App. NXP is a semiconductor company which has broad experience with wireless technology.

So why the need to write data to the tag? Because we want only our app to react on the tag discovery and not other apps which are registered in the system. This can be done by writing an own URI scheme to the tag which is used as an intent filter later on in the Android app. I just wrote to the tag. The intent filter in my applications Activity looks like that:
   <action android:name="android.nfc.action.NDEF_DISCOVERED" />
   <data android:scheme="http"
         android:host="" />

   <category android:name="android.intent.category.DEFAULT" />
So what happens is that the system determines what data is send by the tag and calls out for applications which can handle the NDEF_DISCOVERED event and are registered for that specific URI scheme. If I would have let it out, I would get a chooser window on my device where I had to choose which app I wanted to start. This would destroy the touch and go metaphor of NFC.

As I told in the beginning of the post I used this intent filter to launch my app which does all those tedious tasks for me.
If I launch my app manually I can configure the following settings.

If it gets launched by NFC it processes my tasks according to my personal settings and my configured daytime and nighttime thresholds. Here is a short demo video of the app:


You can see that I configured day time to be after 06:00 and night time to be after 18:00. Since it was already after 18:00 when the phone discovered the tag, the ringer was turned into silent mode, the WiFi was turned off and an Alarm was configured for 19:21 in this case (normally you would configure an alarm for the next morning). In the second run I configured the night time to be after 20:00, so that the phone was set to day mode on detection. You saw that the ringer was turned back to normal mode and the WiFi was reenabled.

Since it might be of interest for other NFC phone owners as well, I plan to polish it up a bit and upload it to the market for free. Afterwards I will publish the source on github and post a market link here, so stay tuned.

Sunday, June 19, 2011

LED Bristle Bot

Today I want to show you my version of the famous EMSL (Evil Mad Scientiest Labs) Bristle Bot. There are already numerous tutorials and videos on how to build one, but for some reason I haven't found a decent one incorporating LEDs. That's why I decided to provide this one as an example.

Bristle Bots are cheap, easy to build and basically pure fun.


These are the parts you need to build one.

  a toothbrush with angled bristles

double sided sticky tape


a 3V coin cell battery

a vibra motor

some wires

Build Instructions

The first thing that you would have to do is to clip off the brush head from the toothbrush.

Next put some sticky tape on the top of the brush head.

The tape holds the motor in place later on. Alternatively you could glue the motor to the brush head. Now prepare the motor. You have to solder on some short wires which you can bend so that you have some kind of battery holder.

Place the LED within the bristles with the connection wires facing to the cut off end of the brush head.

Bend the connection wires around to the top of the brush head. Place the motor on the sticky tape with the soldered on wires facing to the cut off end of the brush head.

For better stability you can also tape the motor on the sides of the brush but it shouldn't be necessary.
Solder the connection wires of the motor and the LED together. The motor has no polarity to worry about, but the LED does. So make sure to remember which connection wire of the LED is the positive one (the longer wire) as this defines in which way you place the battery.

Congratulations, that was all it took.

Place your battery with its positive side touching the positive wire of the LED and enjoy the show.


Notice that I only used two batteries in this video because they were both nearly empty. Normally a fresh single one does the job. The motor still works but the LED might turn off if it gets empty over time.


Saturday, June 11, 2011

Terrarium Twitter Monitoring

In this post I would like to show you how to build a terrarium monitoring system by using twitter for event notifications. This post is also an entry for the Adafruit / Instructables Make It Tweet Contest which will be open for voting after June 26th. So make sure to vote for me then if you like this tutorial.

If you are a reptile owner like myself you should already know that your little friends have very special needs. Be it a certain temperature which they would appreciate in their natural habitat or special humidity settings. You also need to make sure that they have the correct lighting and most importantly that you don't forget to feed your companions.
With most other pets you wouldn't have a hard time keeping track of everything as they would remind you in an audible way. Reptiles on the other hand tend to suffer quietly. This is a big problem as there are a lot of inexperienced reptile holders out there which are overchallenged with their reptiles special needs. Too often this results in reptiles being released into the wild, putting them into animal shelters or in the worst case them dying silently. To give my chameleons a voice to be heard I decided to hook up their terrarium with some sensors and tweet certain events via twitter to be always up to date when my reptile friends need some extra attention.

With this tutorial you will be able to be notified via twitter when the humidity or temperature reaches a defined threshold, when the light is turned on/off and when someone opens/closes the terrarium doors. It is important that the humidity and temperature values are in a range which conforms to the natural habitat of your reptile. So when a threshold is reached you will get notified to take action like sprinkling some water on the terrarium plants to increase the humidity and lower the temperature. Reptiles have also special needs when it comes to light settings. They need spotlights to heat up an area for sunbathing and regulating their body temperature. They also need special UV lights to enable molting and to harden their bones since they lack calcium in captivity. With the twitter monitoring you can keep track of the on/off cycles of your lights, if they are broken or even if they decay slowly in their intensity. It might also be helpful to monitor when the terrarium doors have been opened or closed to make sure that they can't wander around in your home. You could also be reminded that you haven't fed them yet if the doors were closed the whole day.

After this long but neccessary introduction it is time to get to work.


For this tutorial you will need an Arduino Uno or similar microcontroller board, a WiFly shield or Ethernet shield for socket communication with a desktop computer, a photoresistor for light sensing, a temperature and humidity sensor and a tilt switch. Here is the part list of the components I used:

Assembling the WiFly shield / Ethernet shield and Arduino

The first thing you have to do is to assemble the WiFly shield. This turns out to be pretty simple. You only need to solder on the Arduino stackable headers as the board comes without the headers. You could also use an Ethernet shield if you have an ethernet connection near your terrarium. Since mine is in another room I had to stick to the WiFly shield. Once finished stack the shield onto the Arduino. Now you have laid the foundation for the sensor processing.

Building the Door Sensor

As a door sensor I used a Tilt switch. My terrarium has a simple lock which you have to turn downwards from a horizontal position in order to open the door. That kind of lock makes perfect use for a tilt switch as it can close a circuit when turned into a certain position. The tilt switch I used had 4 connector pins so I had to figure out which two pins would be needed to operate the switch. Have a look at the corresponding datasheet or product description if you have one, or just simply use a tilt switch with two connector pins. Make sure that your wires are long enough since you might need the wires of the switch to reach from the front of your terrarium all the way to the upper back. Now solder the wires onto the switch.

Connect one wire to a digital port (I used D5) of the Arduino and the other one to GND.

Congratulations you already finished the door sensor.

Building the Light Sensor

The light sensor is a simple photoresistor which changes its resistive value when exposed to light. When connected together with the 10kΩ resistor in a voltage devider circuit, you can read voltage changes on an analog port of the Arduino. The analog port on the Arduino converts those voltage measurement values to digital values which can be processed in your code. This is called ADC or analog to digital converter.
Solder some wires to your photoresistor and again make sure that they are long enough as they have to reach from your Arduino to your lighting setup. Then connect the photoresistor to +3.3V and an analog port of your Arduino (I used port A0). Connect the 10kΩ resistor to the same analog port and to GND. This is how it should look when you connected everything.

Congratulations you finished the light sensor.

Building the Humidity and Temperature Sensor

I used the SHT15 breakout board which is a preassembled board which had a humidity and temperature sensor combined. You will need to solder on only 4 pin headers. Two for VCC and GND and two for DATA and SCK as it works with a two-wire digital interface. Solder on the necessary wires. Connect the VCC wire to +5V. Connect the GND wire to GND. Connect the DATA wire to a digital pin (I used D4). Last but not least connect the SCK wire to another digital pin (I used D2). It's as simple as that.

Sources and Communication with the Desktop Computer

Now that you have assembled everything the next step on the list is the coding part. Since my terrariums are situated in another room than my dekstop computer I chose to let the Arduino communicate via WiFi with a small desktop console application running on my desktop computer. The desktop part is fairly simple. It consists of a single Java class which handles the socket communication and posts default message to Twitter depending on the events it receives. For the Twitter communication part I used the well known twitter4j library which handles the OAuth authentication part and the posting.

You can download the example desktop application from github. Once downloaded you can run the code from a console. Make sure that you have Java installed on your machine and navigate to the download folder. Change into the executable_jar folder and edit the file. You have to insert the credentials for your own Twitter account. Afterwards run the application from the console by typing:
javac -jar TwitterTerrariumConnector.jar
Now the desktop machine will listen for incoming data.

The Arduino code is pretty simple too. The most complex part is getting the values from the SHT15 humidity and temperature board. The rest is a piece of cake. The Arduino code can also be found on github .

You will have to change some settings in this code to let the WiFly shield connect to your home network. The lines are documented in the setup routine.

After you have uploaded the code to your Arduino the WiFly shield will connect to your home network and starts to poll the sensors for their values. If one of your configured thresholds is reached or an event is triggered, the Arduino will send the corresponding event in form of a byte to the IP-address of your desktop computer. The desktop computer receives and evaluates the event and posts the corresponding message to Twitter.

Position the Sensors and let the Monitoring begin

Now position your sensors in the measurement critical areas of your terrarium. Please make sure that you position them in an area where your little friends can't reach them as you don't want them to get hurt by accident. You can see where I placed them in the demo video. Now let's see the whole project in action.

Door Monitoring:

Light Monitoring:

Humidity and Temperature Monitoring:

Tuesday, May 24, 2011

Android ADK with a standard Arduino Uno and USB Host Shield

A few weeks have past since my last post and a lot was going on. First off how great was Google IO? I hadn't the chance to participate personally but I watched a lot of sessions online and was amazed of what Google had up its sleeve. New APIs, services, best programming practices but most importantly a lot of great talks about Android. As a software and hardware tinkerer I was glad to hear that Google pushes into the direction of the internet of things. With the upcoming project Android @ Home and the introduction of the Accessory Development Kit (ADK), Google showed some future outlook into their internet of things strategy.

Here is the link for the keynote of day one where they announced the ADK, and the dedicated ADK session, in case you missed one of them.

So what was done to support hardware communication? With Android 3.1 and Android 2.3.4 Google implemented USB APIs to communicate with accessories via USB. The Android devices operate in USB slave mode so that the accessories need to provide USB host capabilities. To demonstrate what is possible when your device communicates with external hardware, Google developed a reference demo board and released it as open source. They based their reference board on the Arduino which is really great, because it is widely spread in the open hardware community. Their example firmware and Android software is based on their reference board to show what kind of sensors and actuators are easily accessible. So if you attended the Google IO and got your reference board on site, that's great news for you. You could just dive right in and tinker with it.

Unfortunately not everyone could get a ticket (me neither :( ), so those developers have to wait for compatible hardware boards being distributed some time at the end of the year, or they could order one from the japanese company which produced them for the Google IO. Unfortunately they are very pricey and cost about 400$.

Soon after hearing that I decided to port the firmware and software to my basic Arduino Uno and my USB Host Shield. It is no suprise that I wasn't the only one who did that.

So if you have the Arduino Uno and a USB Host Shield lying around you might just want to give the ADK a try.
The cool thing about it is that you register a USB Broadcast receiver on your device that can automatically detect when the device is connected to your board and start up the corresponding application.

Here the steps I took to make my setup work with the ADK:
  1. Read and understand the ADK section in the Android Developers Guide.
  2. Follow the installation process.
  3. Don't use Googles USB_HOST_SHIELD library. I used a patched version which I found here. If you are having trouble compiling the demokit.pde it may result from a wrong pin definition in the patched USB_HOST_SHIELD library. Just open the Max3421e.cpp file and change #define INT PB1 to #define INT PORTB1 and #define RST PD7 to #define RST PORTD7. You might also try to use the newly released original version of the USB_HOST_SHIELD library which now supports the ADK, but I don't know if it works.
  4. Strip down the demokit.pde to its bare essentials, meaning only the communication part.
  5. Strip down the example Android app to the communication part and implement your own use cases.
To make it a bit easier I provided my example Android app and my stripped down version of the demokit.pde at github. Feel free to play around with it. Note that my approach would be considered as a temporary hack or proof of concept rather than a good solution of the porting problem. So when new versions of the ADK will be released you would have to modify them again which would be painful.

Here is a quick demo of controlling the digital pins 2-7 in output pinmode:


As promising as the ADK is right now, I have a problem with having to connect my device via cable to the accessory. The future of the internet of things will be wireless, so as long as there are no Android devices which support a Zigbee like protocol, I will use my Arduino/Android Wifi approach which you might remember from a post in the past.

That being said...
I can't wait for Android @ Home at my home ;).

Saturday, April 30, 2011

Show Love in a Heartbeat

I wanted to show my appreciation for the patience my girlfriend has with me when I'm hooked on a new project, so I decided to dedicate a project to her. Well she also pushed me a little bit by buying a small plastic heart and telling me to create something for her for a change :).

This could be a perfect gift for your loved one as well.

You need the following parts:

  • transparent and hollow heart shaped object 
  • 2 x red LEDs
  • 2 x 100kΩ resistors
  • 2 x 470Ω resistors
  • 2 x 100μF capacitors
  • 2 x NPN transistors (BC547)
  • 9V Battery with connector
  • transparent layer as a circuit board
I wanted a thin transparent circuit board so I took a transparent plastic sheet cut out of a grocery box. You can take anything you like but you may want to make sure that is transparent to let the whole heart glow in the front and in the back. After cutting it to the heart shape of the container object the fun part begins. Make the required holes for the components in your circuit board and assemble the cicuit in the following way:


Since I used a plastic layer, I had to be very careful to not melt it with my soldering iron. Due to the limited space I had on my circuit board, I had to assemble the circuit on both sides and had to place the capacitors on opposing sides. My finished circuit looked like this:

The red LEDs are already diffused, but still you would only see two dots blinking in the dark. To diffuse the light even more, you can fill your heart shaped container with a thin layer of soft tissue. The heart container I had wasn't big enough to hold my 9V battery block so I cut a small hole at the top to let out the connector wires.

As a last step I attached the 9V battery block at the back of the heart with some tape and connected it to the heart. When everything is finished it looks like this:


You can see that the load and unload cycles of the capacitors produce a heartbeat like effect.

Monday, April 25, 2011

Custom QR-Codes

While I was in the process of creating a QR-Code for this blog, I stumbled upon some pretty cool techniques to make those standard black/white edgy QR-Codes a little more appealing. I want to show you how to create an QR-Code and how to add some visual tweaks to it. Most QR-Code generators work with a failure tolerance up to 30%. Meaning that if some parts of the image get corrupted, the QR-Code can still be functional. That's basically what we are about to do.

First, find a QR-Code generator online which generates the code for your content.
The generator from the ZXing (Zebra Crossing) project has a great set of features. The more basic generator from Kaywa will work just as fine.

Now that you have your generated QR-Code image, it's time to make some changes. First let's make the edgy fragments a bit smoother so that they are much more easy on the eyes. I show you how to do that with Gimp but any advanced graphic software will work just fine.

You have to follow several steps to round up those edgy fragments. First you might need to convert the black and white image to RGB mode to allow some filter algorithms to be applied.

Afterwards you need to blur the image with an gaussian filter to achieve an anti-aliasing effect.

A blur radius of 10 pixels produced a good result in my case.

To sharpen your blurry QR-Code you use a color curve adjustment.

Now you need to experiment with the settings to produce a sharp contrast. I used the settings depicted here to achieve a good result.

When you are done you end up with a QR-Code with really smooth fragments.

Much better but still not very eye catching. QR-Codes don't have to be so colorless. You can choose different colors for the background and foreground as long as you keep in mind that the foreground color has to have a stronger contrast color. So if you would choose to bright colors, your QR-Code can be difficult to identify. Let's change the foreground color of this QR-Code.

I chose a blueish color for the fragments, which still has a strong contrast to the white background.

Now we added some color to the QR-Code, but still there is more we can do. As I mentioned in the beginning, most QR-Codes have a failure tolerance of up to 30%. That means that we can add other graphics on top to make it more appealing, to describe the content of the code or to follow a corporate branding if you are a company. I just added my blogs logo on top as an example.

I found the center of the code to be a good place to add some graphics. Some side regions might work just as fine. Just remember to test your resulting QR-Code thoroughly as it might break if your graphics are in a sensible spot. I hope this small guide will help you produce more appealing QR-Codes so that we get rid of those unpersonal black and white default ones in the future. Let's be honest no one recognizes them anymore.