Testing a game in the Windows Phone emulator that uses the accelerometer can be tricky since that data can be hard to simulate. Peter Blois in his labyrinth sample uses mouse movement to simulate it, but this only allows for 2 directions of movement. This got me thinking about how we could better simulate the accelerometer, and I considered using an Xbox gamepad or other device but then realized I could use an actual accelerometer which is readily available and relatively affordable. You might also already have one. This accelerometer can be found inside the game controller for the Wii.
What makes the Wii controller even more attractive is that it communicates over Bluetooth and so can be hooked up to any PC with a Bluetooth adapter. Additionally Brian Peek put together a great library to access Wii controller data with .NET.
Since Windows Phone in the emulator doesn’t have access to this data, I created a simple console app that can get data off of the Wiimote and serve it up over HTTP. On the client side if starting the device accelerometer fails, the code will instead make requests to this HTTP server to get the accelerometer data.
There is some latency here because of the nature of making HTTP requests so if anyone has suggestions on reducing this latency please let me know.
You can download the source code for the console app and a modified version of Peter Blois’ labyrinth app that uses this accelerometer proxy code here:
http://www.bluerosesystems.com/wiimoteaccelerometersample.zip
Make sure to run the console app as administrator or you won’t be able to listen on the HTTP port. Note that this code is a quick sample and I’ll be working on a more robust version that I will post on Codeplex.
March 29th, 2010 at 12:45 AM
This is absolutely awesome! Great way to combine an existing library with WP7 to solve an immediate need.
April 9th, 2010 at 11:01 AM
Do I need to buy actual accelerometer in order to run your sample? OR Can I still use mouse?
April 9th, 2010 at 11:05 AM
For this version you need to use a wiimote. The original Pete Blois sample uses the mouse.
April 9th, 2010 at 11:06 AM
Hey Bill,
This is Michael again..
I can't run Madness sample. I'm getting this error below..
—————————
Microsoft Visual Studio 2010 Express for Windows Phone
—————————
Object reference not set to an instance of an object.
—————————
OK
—————————
April 9th, 2010 at 11:36 AM
Thanks, Bill..
I got it..
April 10th, 2010 at 1:54 AM
How about using a Serial port reading within C# if the device fails… say on COM5 where u may have a USB joystick hooked up
December 19th, 2010 at 5:02 PM
I've found an interesting way to get an accelerometer sensor work recently. There is used augmented reality, in a way you get able to twiddle a piece of paper as your phone in front of your web camera. I hope you will find it useful http://winphoned.blogspot.com/2010/12/ar-accelero…
December 20th, 2010 at 2:08 AM
I've found an interesting way to get an accelerometer sensor work recently. There is used augmented reality, in a way you get able to twiddle a piece of paper as your phone in front of your web camera. I hope you will find it useful