Mar 27

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.

This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.

8 Responses to “Simulating accelerometer data in the Windows Phone 7 emulator”

  1. G. Andrew Duthie Says:

    This is absolutely awesome! Great way to combine an existing library with WP7 to solve an immediate need.

  2. Michael Sync Says:

    Do I need to buy actual accelerometer in order to run your sample? OR Can I still use mouse?

  3. billreiss Says:

    For this version you need to use a wiimote. The original Pete Blois sample uses the mouse.

  4. Michael Sync Says:

    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
    —————————

  5. Michael Sync Says:

    Thanks, Bill.. :) I got it..

  6. Jay Desai Says:

    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

  7. zavolokas Says:

    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…

  8. zavolokas Says:

    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

preload preload preload