Using standard Arduino board as Google’s ADK kit

When Google announced about the Open Accessory Development kit (ADK) in the last Google IO conference, I was really excited since it was based on Arduino boards.

But after the initial bliss went off, I was disappointed for two reasons. First you need an Android phone running Android version 2.3.4 or above. The second reason is that the original ADK kit is not compatible with the plain Arduino board. The downside of this is that all your existing Arduino Shields will not work with that board and not to mention you have to buy a rather expensive ADK kit. Now there is also an Arduino compatible ADK kit, but it is again expensive and it didn’t made sense for me to buy another Arduino board when I already had a bunch of them lying around.

Since it is based on Oleg’s USB Host Shield, I was trying to see if I can build a board with just plain Arduino board and Oleg’s USB Host Shield. It turns out it is possible and with the release of Oleg’s second version of the USB Host Library, it is much simpler.

Things you need

Any Arduino board.

You can use either UNO or Duemilanove. You can also use Arduino Mega, if you have one lying around. The advantage of using Mega is that you will have additional I/O pins.

USB Host Shield

You need a USB Host shield for Arduino. You can use the original shield by Oleg for $40, or you can buy a cheaper clone from sparkfun for $25. I recommend the original one by Oleg, since it doesn’t need an external power supply. If you are going to use Sparkfun’s version you need an external power supply. Also make sure you don’t buy the older version of Sparkfun shield. It has pins marked wrongly and you need to make changes to the library to make it work.

ADK compatible Android phone

You need an Android Phone which is ADK compatible, which means you need a phone which is running 2.3.4 or above. I tested this setup in Nexus S and it is working properly.

Sensors, LED’s, buttons

You would need additional sensors, LEDs or buttons to test the flow. To start with, you can just use some LED’s

Connections

Stack the USB Host shield on top of the Arduino board. Connect an LED on pin number 3. Connect your phone’s cable to the USB port of the shield.

Arduino Firmware

Download v2 of the USB Host Shield Library and place it in the library folder of your Arduino setup. Open the demokit_20 example sketch from the /examples folder and upload it to your Arduino board.

Android App

The Android demo app for ADK, can be found under the /app folder of the ADK package. Upload the app to your Android phone.

Testing it

Power on Arduino and connect your Android phone to the other side of the cable. You should see a dialog box, which asks you whether you want to launch the app. Click yes. Once the app is launched you can control the LED connected on pin 3, by moving the slider in the Android app.

Now enjoy your new cheaper ADK kit 😉

Posted in Android/Java, Arduino | Tagged , , , | 22 Comments

Introduction to Node.js at jsFoo

I gave a talk about Node.JS at jsFoo, the JavaScript conference today. I thought of sharing the slides and the source code of my demos so that it would be useful for others.

You can find the slide that I used for the talk from my slideshare account. I have also embedded it below for quick browsing.

Continue reading »

Posted in Events/Conferences, JavaScript/jQuery | Tagged , , | 5 Comments

Making text unselectable in browser

Long time back, I was working in a project which required us to make a particular position of text unselectable by the user on a webpage.

I was looking at various JavaScript solutions and finally found the CSS selectable property. But it was not working across different browsers. It took a considerable effort to make it work across different browsers.

I found this code while browsing through archives and thought of posting it here so that I know where to find it, if I need it and also it would be useful for others who want to do the same thing.

BTW, one quick disclaimer. Even I hate it when people make a particular position of text unselectable in a browser. So use it if it is really needed and also remember it is not fool-proof.

Well, let’s see the code then.

Posted in Web Programming | Tagged , | 3 Comments

Trip to Western Ghats

Long time readers of my blog, would know my love for travel and treks. Last week we had a long weekend and I completed my dream trip. (If you have been following me on Twitter, then you would have know about, since I was tweeting about it pretty frequently)

Me and Aswin have been planning for this for quite some time and the following are the places we visited.

Day 0 (Aug 30 2011)

The initial plan was to start from Bangalore at around 5, so that we can reach Hassan in a decent time. We got delayed by rain and were able to start only at 7:30 PM and by the time we crossed Bangalore it was already 9.

We had a quick dinner and started towards Hassan at around 9:45 PM and reached Hassan past midnight. After a few minutes of search, we found a decent hotel and went to sleep at around 1 AM.


View Day 0 – Bangalore, Hassan in a larger map

Day 1 (Aug 31 2011)

Thanks to Aswin’s alarm, we got up early in the morning and started at around 7 AM and reached Belur around 8 AM. We had a quick breakfast at Belur and started towards Chikmagalur. The road was awesome and we stopped in a couple of places for photo-shoots.

I couldn’t resist it when I saw this Banyan tree 🙂

Can you do it?

From Chikmagalur, we went to Kemmannugundi through Mullayanagiri.

Mullayanagiri is the highest peak in Karnataka. By the time we reached the top, it was drizzling and the place was completely covered with mist. I was just wearing a sleeveless t-shirt while the others were all shivering 🙂 You could see the frost which deposited on me in these photos.

mullayanagiri-4 mullayanagiri-6 mullayanagiri-5 Frost on my body On top of Mullayangiri

The road was good until Mullayanagiri, but it was the last 20Km to Kemmannugundi. We reached Kemmannugundi at around 3 and had omelettes as late lunch in a road side shop.

We wanted to visit Hebbe falls on the same day, but the locals told us the road is not good and it is better to go there the next day early in the morning. We then visited Kalhatti water falls and went to Bellavara and stayed in a home stay.


View Day 1 – Hassan – Belur – Chikmagalur – Mullayanagiri – Kemmannugundi in a larger map

Day 2 (Sep 1 2011)

We got up early again, (thanks to Aswin’s alarm) and hired a jeep to go to Hebbe falls. The jeep took us on a sloppy road for around 11 Km and stopped. We had to trek the last few Km of leech infested forest, cross 3 streams to go the Hebbe falls.

It was one of the most amazing falls and as we went close to it all of us started to shout in joy. We were in the middle of a deep forest inches away from an amazing water fall with no other human nearby for alteast another 10 km, with only leeches as company 😉 The locals told us to use neem oil and gun powder which was very effective against them, but we still had to donate a few ml of our blood to them 🙂

Update: Checkout Aswin’s blog post about our Hebbe falls trip as well.

Hebbe Falls Hebbe Falls Hebbe Falls

After spending a couple of hours in the falls we came back to our home stay and stated towards Udupi. We wanted to reach Udupi before it gets dark but it started to rain heavily and we had to stay at Kalasa.


View Day 2 – Kemmannugundi – Hebbe Waterfalls – Kalasa in a larger map

Day 3 (Sep 2 2011)

We started early in the morning (again you know how 😉 ) and drove through the Kudremukh forest area. This drive was one of the awesome drives of my life. We were driving through rain and the road was covered with mist with just a few meters of visibility surrounded by huge treas. On the way I also spotted a tiger club right in the road.

From Kudremukh we reached Udupi via Karkala and Manipal. After having lunch we started to Maravanthe Beach. At Maravanthe beach the tide was heavy and we spent a couple of hours playing in the beach like kids 🙂 Check out some of the photos which were taken while we were playing in the beach.

Can you do that? oops... Me and Rat Enjoying waves Enjoying waves

From Maravanthe Beach we went to Batkal. By the time we reached Batkal, it was around 6:30 PM and we had a dilemma. Jog falls was another 90 Km away and it had already started to get dark and it was raining heavily. When we asked a couple of locals, they said that the road to Jog falls in a ghat road surrounded by deep jungle. After some minutes of discussion we finally decided to do it 🙂 The look on the local people’s face said how crazy we are getting into 😉

It took as close to 3 hours and 15 minutes to cover the 90 Km of bad ghat road in pitch dark with pouring rain. We reached Kargal at around 9:45 PM and took a room and rested.


View Day 3 – Kalasa – Kudremukh – Karkala – Manipal – Udipi – Maravanthe Beach – Jog falls in a larger map

Day 4 (Sep 3 2011)

The next day we woke up late, and lazily roamed around Kargal and went to Jog falls after having breakfast.

The board on the way to Jog falls claimed it to be “World famous” and when we reached the falls, we felt that it indeed was “World famous”. It was massive and had around 4-5 mini-falls. We had to climb down 1500 steps to get to the place where the water was falling and it was worth it. Once again, the kid inside us came out and we were playing the water.

Me and Rat after getting up early in the monring

After that we also went to another viewpoint, on top of the falls from where we could clearly see the edge of the water falls. After Hebbe falls, Jog falls was one of the highlight of the entire trip 🙂

Jog Falls From the edge of the falls From the edge of the falls Side view

After spending almost the entire day in Jog falls, we went to Sagar and had dinner at a friend’s place.


View Day 4 – Jog falls – Sagar in a larger map

Day 5 (Sep 4 2011)

We again woke up lazily on Sunday and from Sagar, went to Shimoga, met another friend and then came to Arasikere. At Arasikere we had lunch and then started racing towards Bangalore. We reached Tumkur at around 5:30 PM and reached Bangalore at around 8 PM.


View Day 5 – Sagar – Shimoga – Tumkur – Bangalore – Home in a larger map

I was soo dirty and tired when I reached home, but was really happy that I did this amazing trip when I was young and had the energy to do it. Thanks Aswin, Rat and Subbu 🙂

Some facts

  • Total distance travelled – 1200 Km
  • Duration – 4 nights and 5 days (Didn’t book any hotel before hand 🙂 )
  • Total expense – Around Rs. 5,000 per person (Plus Rs 20,000 ring that I lost 🙁 )

Posted in Travel/Trek | Tagged , , , , | 17 Comments

Expand any shortened url using PHP

Recently for a project which I was working on, I wanted a way to expand urls shorted by url shorteners.

After a couple of web searches I found an API site called LongURL. This service was really slow and I had to look for alternatives.

I thought of writing my own using curl and then parse the headers. I was searching for the curl functions in PHP Manual and I found a simple but not so famous function called get_headers().

This function is all we need to expand the urls. The following function expand_url() takes a short url and will return the longer version of the url.

Enjoy 🙂

Posted in Web Programming | Tagged , , | 11 Comments

Updates to my WordPress Plugins

Over the past week, I have updated nearly half of my Plugins. I thought of consolidating all them in a single post instead of writing separate post for each of them.

If I have fixed a bug or added a new feature, I call them as mandatory updates. If I have just added new translations, the those updates are optional. But it is recommend that you always update irrespective of whether they are mandatory or optional updates.

You can update all these Plugins from your WordPress dashboard or by manually downloading them from their homepage.

Try these updates and let me know if you face any issues.

Mandatory Updates

Easy Retweet

Easy ReTweet is a WordPress Plugin, which lets you add retweet or Tweet this buttons for your WordPress posts, together with the retweet count.

I updated this Plugin to v2.7. I fixed a bug and added new feature, so it is a mandatory update

The following are the major changes

  • Enabled custom bit.ly pro domains (Thanks to Michelle McGinnis for the patches)
  • Added Bulgarian translations
  • Added Lithuanian translations

Github Ribbon

Github Ribbon is a WordPress Plugin, which can be used to add Github ribbons to your website. The github ribbons can be configured either for the entire site or on a post by post basic.

I updated this Plugin to v0.4

The following are the major changes

  • Added CSS style to hide ribbon on printed pages

Posts by tag

Posts by Tag WordPress Plugin, provides sidebar widgets which can be used to display posts from a specific set of tags in the sidebar.

I have updated this Plugin to v1.8.

The following are the major changes

  • Added support for displaying content (Thanks to rjune for the patch)

Twitter Avatar Reloaded

Twitter avatar reloaded Plugin adds a new field to the comment form to get the user’s Twitter username and stores it together with comments and using it replaces gravatar with twitter avatar when the comment is displayed.

I have updated the Plugin to to v1.0

The following are the major changes

  • Using transient api for storing cache
  • Also improve performance

Optional Updates

Geo mark

Geo Mark is a WordPress Plugin which will automatically locate Geo information in your WordPress posts using Yahoo Placemaker and YQL API’s.

I have updated this Plugin to v0.7

The following are the major changes

  • Added Bulgarian translations
  • Added Lithuanian translations

Post to Friendfeed

Post to FriendFeed is a WordPress Plugin which will allow you to post excerpts from your blog posts as a message in FriendFeed with images. By default FriendFeed posts them without images and this Plugin overcomes this issue.

I have updated this Plugin to v1.0.2

The following are the major changes

  • Added Bulgarian translations

Tweetback Helper

Tweetbacks Helper is a helper Plugin for Tweetbacks Plugin to help it detect more tweets.

I have updated this Plugin to v0.4

The following are the major changes

  • Added Bulgarian translations
  • Added Lithuanian translations
  • Added German translations

Posted in Plugin Releases | Tagged , , , , , , , , | 7 Comments

Embedding Github files in your WordPress posts

Recently while debugging the issue with my WordPress feed, I found out that the Plugin which I was using to display files from my Github Gist was highly unoptimized. As promised, I created a Plugin to do it properly.

While working on this new Plugin, I felt that it would be really nice to embed Github files as well in addition to embedding gist.

Gist-it

My search lead to a Google app engine based solution called Gist-it. I really liked it, but one problem with it was that it was not supporting embedding particular regions of the file. So during the Yahoo HackU last week, I hacked on it and added support for specifying line numbers.

I also updated my WordPress Plugin to support gist-it urls as well.

Download & Usage

You can download the latest version of the Plugin from the Plugin’s home page. The Plugin’s home page also has detailed examples of different ways by which you can embed gist or Github files in your WordPress blog posts or pages.

Feedback

If you have any comments or if you want to report any bugs, please leave a comment below.

Stay updated

I would be posting updates about this Plugin in my blog and in Twitter. If you want to be informed when new version of this Plugin is released, then you can either subscribe to this blog’s RSS feed or follow me in Twitter.

Posted in Plugin Releases | Tagged , , , , | 4 Comments

Yahoo HackU at IIT-Kanpur

This past weekend, Yahoo conducted HackU (Hackday for university) at IIT – Kanpur and I was part of the Technical crew that conducted the event.

In the event, I talked about Yahoo Application Platform (YAP) and thought of sharing the slides here so that it could be useful for others as well.

Continue reading »

Posted in Events/Conferences | Tagged , , | Leave a comment

Hardware hacking in Yahoo Open hackday

The annual Yahoo Open Hack day is back and this year it is going to happen on 30th and 31st of July.

This hackday is special for me, for a couple of reasons.

First and foremost, I am going to see my idol Douglas Crockford in person 🙂 He is one of the reasons why I started loving JavaScript and I am really excited about meeting him in person and to listen to his talk.

Update: Here are the photos

Me and Doug

Me and Doug

And the second reason is that, we are going to have hardware hacks during the event. Yes you read it right 🙂 This time we are planning to have tech talks about hardware and let people do hardware hacks as well.

Regular readers of my blog would know that I hack around hardware (especially Arduino) as a hobby and you could understand my excitement.

I am also going to give a talk on Arduino and Android ADK and will be demoing some of the hacks which I have created using them.

If this hasn’t convinced you, then there is more. Yahoo is also going to sponsor 50% price for the hardware that you need for hacking. Yes, you read it right again. 😉 We have arranged this offer with 9 Circuits.  Head over to the Open hackday wiki to get more details about it.

See you guys at Open Hack day next weekend.

Update:

My Slides

Open hack 2011-hardware-hacks from Sudar Muthu

More information

Posted in Arduino, Events/Conferences, Google/Yahoo | Tagged , , , | 14 Comments

Fixing WordPress Feed timeout issues

Recently I got an email from my friend Sudheer, saying that the feedburner feed of my blog is not working. I thought it might be some small issue, but it took me more than a couple of hours to fix it. As usual, I thought of documenting it since it was an interesting problem and also someone who has the same problem might also find it useful.

WordPress feed timeout

I started the debug process by logging into Feedburner dashboard. Feedburner reported that it is not able to fetch my blog’s feed url. When I tried to open the feed url directly in browser it was loading, but it took a couple of minutes for WordPress to generate it. But both feedvalidator and feedburner said that the feed times out.

My website was loading properly and my error log was empty. I tried lot of different things but was not able to figure out why the feed was timing out.

Increasing memory used by WordPress

After a couple of web searches, I landed on a old forum thread, which stated that we should try to increase the amount of memory used by WordPress. I tried doing that as well, but it didn’t make difference 🙁

Reducing post count in feed

Then I tried to reduce the number of recent items that were shown in my feed to 10 from the default value of 25. The feed was getting generated in some decent time and was able to let feedburner pick up my feed. But it still didn’t solve my original issue.

Unoptimized Plugin

After some more debugging, I found the root cause of the issue. An unoptimized Plugin was the real culprit.

I was using github’s gist to store the code samples that I use in my blog posts and used a Plugin to embed the code directly from github. The advantage of this approach is that, there is one centralized repository for my code samples with versioning and also github provides nice syntax highlighting.

The Plugin was making curl request to github to retrieve the code sample and it so happened that most of my last 25 blog posts had code samples and some blog posts even had around three code embeds.

The problem with the Plugin was that, it was not using WordPress’s built-in HTTP request object and also it was not caching any of the response that it got from the curl request. I quickly rewrote the Plugin and WordPress was immediately able to serve the feed in less than a second. (Will be releasing the Plugin pretty soon) Update: You can find the Plugin in its homepage

Solution

So if you are also facing timeout issues with your WordPress feed, then try the following

  • Try increasing the memory used by WordPress
  • Try reducing the number of blog posts that are disabled in your feed.
  • If nothing works, then it’s mostly because of some unoptimized Plugin.

Posted in WordPress | Tagged , , , , | 4 Comments