Being the big fan of technology that I am, I always wanted to try out the latest things happening on the technology world. Some of the buzz words being talked about in the technology world are HTML5 and mobile development. After having fun writing games during my college days, I was interested in building a HTML5 based game. Then, I came across this HTML5 based implementation of classic Helicopter game. In the mean time, I was also playing around with Android ADK and Arduino boards. Finally, made up my mind to hack something cool connecting all these technologies – HTML5, mobile and USB accessories. And, here is the result of the experiment - “Arduino based game controller”. In a nutshell, it’s a game controller which can be connected to an Android phone using which we can play HTML5 games on the browser. The heart of the hack was built over a weekend and source code of the same can be found here. Check out the video demo of the hack at the end of this post.
What is it?
Arduino based game controller is a Joystick / game controller which can be connected to an Android phone via USB. Using the controller, we can play games on the browser. An android driver app has been built which reads the data from the game controller (using Android ADK) and routes it to the browser over web sockets. The game has been hosted here (The multi-player mode might not work properly as the hosting site does not support web sockets). More detailed information can be found here.
The hack consists of three core modules:
1. Game module. HTML5 based Helicopter game originally written by Dale Harvey. The game uses HTML5 canvas for rendering the game elements. I have forked his code and have built the networking layer of the game. I have integrated the game with Node.js and Socket.io to support multi-user mode. In order to facilitate seamless communication between the controller and the game module, web socket technologies have been used.
2. Joystick / Controller module. For this hack, I have used Arduino Mega ADK board and a joystick shield mounted on top of it. Arduino board has been flashed with the firmware which reads analog data from the controller and sends it to the connected Android device using Android accessory protocol.
3. Android module. An android app for linking the game module and the controller. The app can be installed on any device running Android 2.3.4 (Your device needs to have the USB compatibility library). It reads the data from the controller and forwards it to the browser over web sockets.
How to contribute?
The source code is available here under MIT licence. I have added enough inline documentations all around the code. Please send any bugs, feedback, complaints, patches about the hack to me at [email protected].
-- Varun
That is awesome.
ReplyDeleteWow.. Excellent demo.
ReplyDeletearduino->android->web!
Is the Joystick analog? I guess it would be more fun to make use of analog signals..
Does android.permission.INJECT_EVENTS permit one to inject any key press events to other apps? It would be cool to play many games on android with analog stick.
Is the Joystick analog?
ReplyDelete[V] Yes, it sends out analog data.
android.permission.INJECT_EVENTS
[V] Thought abt playing Angry birds using Joystick. However, its not possible for applications to send events to other applications. Guess, only signed system apps can use this permission.
Thanks,
Varun
Oh, bad..
ReplyDeleteAngry birds may not benefit greatly with analog stick. Racing games, and Tank Hero kind of games could be played better using analog stick.
http://stackoverflow.com/questions/5383401/android-inject-events-permission seems to suggest that android.permission.INJECT_EVENTS
can be used on rooted phones.
Also http://stackoverflow.com/questions/3598662/how-to-compile-android-application-with-system-permissions
Thanks Nikanth. Will check it out.
ReplyDeleteVarun
Awesome..
ReplyDeleteYour creativity is WILD .. Good stuff
ReplyDeleteWow... this is really good work!! Keep it up dude.
ReplyDelete