Intoduction
As all we know there is no support for accelerometer in Windows Phone 7 Emulator. Of course there are projects which are using some hardware such as Wii or XBox 360 controller to emulate mobile device movement. They have one weak point – they needs hardware. Some day, when I had more free time I decided do find some solution for this. After couple of hours I have found one and this is it… I want you to introduce MaciejGrabek.WP7AccelerometerEmulator.
How it works?
Solution consists of three projects:
1. MaciejGrabek.WP7Accelerometer – which is core library to use in your projects. It contains WP7AccelerometerProvider class which provides all functionality given by real Accelerometer from Microsoft.Devices.Sensors ie Start and Stop methods and ReadingChanged event which provides information about gravity for each axis.
2. MaciejGrabek.WP7AccelerometerEmulatorUI - this project allows you to emulate position of phone by simple use of three scrolls for X, Y and Z rotation. It sends all required data to Proxy.
3. MaciejGrabek.WP7AccelerometerEmulatorProxy – this proxy is used to receive data from UI and allows to read it from WP7AccelerometerProvider.
If you running your application on emulator then WP7AccelerometerProvider is trying to read data from Proxy – if something goes wrong on retrieving this data (ex proxy is unavailable) it simply switches into random data mode. You can retry receiving by Stop and Start methods.
How to use it?
It is very simple – like using real accelerometer.
When you create WP7 application first thing what you need to do is adding reference to MaciejGrabek.WP7Accelerometer library (or project). Then create accelerometer object like below:
1 | var acc = new WP7AccelerometerProvider(); |
Now simply add handling to AccelerometerProviderReadingChanged event:
1 2 3 4 5 6 7 | acc.ReadingChanged += OnAccelerometerProviderReadingChanged; private void OnAccelerometerProviderReadingChanged(object sender, WP7AccelerometerReadingEventArgs args) { //do what you want with data ProcessAccelerometerData(args.X, args.Y, args.Z, args.Timestamp); } |
Start WP7AccelerometerProvider and do what you want with received data.
1 2 3 4 5 6 7 8 | try { acc.Start(); } catch (Exception exc) { txtblk.Text = exc.Message; } |
This is all you need to do in application. Now lets see control panel. To do this you need to start MaciejGrabek.WP7AccelerometerEmulatorUI and MaciejGrabek.WP7AccelerometerEmulatorProxy (it should start automatically with MaciejGrabek.WP7AccelerometerEmulatorUI, but if not be sure to do this manually – otherwise you will get random data). Run your WP7 application on emulator and on MaciejGrabek.WP7AccelerometerEmulatorUI mark “Send data to emulator” checkbox and have fun! Result is shown below:
As you can see it is very simple and intuitive to use.
Where to find it?
You can simply download MaciejGrabek.WP7AccelerometerEmulator and use it in your projects. There is of course some demo to see exactly how to use it.
What will appear in future versions?
1. Sometimes You can see Gimbal Lock effect – I am currently trying to solve it
2. Add mouse control for rotation
3. Add movement sequences (you can record movement like shaking, rolling etc, save it, and quick run every time you need)
4. Add additional acceleration for movement (shake etc)
Fell free to comment!













December 17th, 2010 on 13:43
good work, i was thinking about developing something like this. today have seen your article on CodeProject thumbs up will help a good amount of devs.
December 20th, 2010 on 19:20
I’m glad that you liked it
I hope it will help.
March 22nd, 2011 on 18:09
Hey guys,
I recently saw a publication about the use of accelerometers on geology for iphones.
Some of you guys should develop an app like this for WP7
March 27th, 2011 on 00:20
I have checked compass support in WP7 API, but currently there is no such thing (there is Direction but it is fake)
. I hope they will change it in next release.
May 5th, 2011 on 14:40
It is not working for me.
I am getting random data.
I have also checked the “send data to emulator”.
Can you tell me what I am doing wrong?
May 8th, 2011 on 07:30
Hi!
Please check URL of proxy. Default URL is http://localhost:9876/AccelerometerEmulatorProxy.svc – (Project MaciejGrabek.WP7Accelerometer -> WP7AccelerometerProvider.cs line 31). If you want to change it you can use optional parameter of WP7AccelerometerProvider constructor. Be sure that proxy is running when you are debugging app on emulator.
June 13th, 2011 on 17:44
Quoted by:
http://ch3cooh.jp/index.php/tips/windowsphone7/emulator/accelerometer-simulator-kit/
and
http://d.hatena.ne.jp/ch3cooh393/20110430/1304193974
January 3rd, 2012 on 13:27
hi, i am devloping a speedometer using windows phone accelerometer. my first aim is to get speed on one fixed axis say for e.g. y. But later I plan to change it to all axis. At the moment I plan to take around 50 samples (y axis G valuesfrom accelrometer) and find an average and then convert it to meter/second or km/hour. I know it is not easy comapred to the noise and other factors. Is there some help avilable on this direction. Thanks in advance.
January 4th, 2012 on 22:40
Hi!
I’m not sure if accelerometer is good way to create something that calculates speed. Of course it can be calculated using easy equation, but here this acceleration is not constant so calculations are not exact… Maybe you are thinking about something like this app? In this app your idea is perfect (in my app I’m using over 100 last reads from accelerometer).
January 20th, 2012 on 09:22
I used to be more than happy to seek out this internet-site.I wished to thanks for your time for this wonderful read!! I undoubtedly having fun with every little little bit of it and I have you bookmarked to check out new stuff you blog post.
May 14th, 2012 on 22:48
Thanks for the auspicious writeup. It in fact used to be a leisure
account it. Glance advanced to more introduced agreeable from you!
By the way, how can we communicate?
May 14th, 2012 on 22:52
See contact page