Compass app for Windows Phone 7

January 17, 2011 by
 
As per the request of an XDA user, I’ve put together a Compass application for Windows Phone 7 that will work (for now) on Samsung phones.  Windows Phone 7 device guidelines dictate that each phone must have Compass hardware, but there is not a common API through which developers can access the hardware.  Samsung includes support in their platform drivers, so I’ve taken advantage of that.

As always, you can download the XAP and source code.  A developer-unlocked Windows Phone is required.  This app will not work on Dell, HTC or LG phones as of this posting.

I have tested so far on the Samsung Focus, I suspect it will work on all Samsung Windows Phones.

Comments

21 Comments on Compass app for Windows Phone 7

  1. Sina on Tue, 18th Jan 2011 12:36 AM
  2. LG Phones already have a fully working Compass.Yyou can access a fully working compass in the MFG app under Engineer Menu->Device Test->Sensor Test->Compass. Or you can just run ScanSearch…Perhaps that could help in getting it to work on LG phones?

  3. David Gardiner on Tue, 18th Jan 2011 1:38 AM
  4. Installs and runs on my Samsung Omnia 7, though I’m not convinced that it’s displaying valid data.. compass keeps swinging around all over the place.

    Maybe it’s because I’m indoors?

    -dave

  5. Dave on Tue, 18th Jan 2011 1:42 AM
  6. @dave -

    Maybe. For best results, hold it as if you’re trying to take a photo of the floor. Leaving it still on a table (away from other electronics) should result in a pretty stable reading after several seconds.

  7. Dave on Tue, 18th Jan 2011 1:43 AM
  8. @Sina – thanks, I’ll look into it!

  9. Menny on Tue, 18th Jan 2011 8:57 AM
  10. great work once again Dave is the man.

  11. Ando on Tue, 18th Jan 2011 9:50 AM
  12. On Omnia 7 it randomly jumps all over the place

  13. Dave on Tue, 18th Jan 2011 3:34 PM
  14. @Ando – even while holding it still, pointing downward, as if you were to take a photo of the floor?

  15. Ashraf on Tue, 18th Jan 2011 4:04 PM
  16. Dave, thanks; you did a great job.

  17. David Gardiner on Tue, 18th Jan 2011 5:14 PM
  18. I left it sitting on my desk and the reading didn’t look correct.

    I did notice that if I tilted the phone (in a horizontal way), then the reading sometimes seemed to follow the the down-side of the tilt..

    almost like it was hooked into some kind of data source but not the necessarily the compass.

  19. Dave on Tue, 18th Jan 2011 5:17 PM
  20. @David -

    The driver doesn’t give me a way to verify accuracy or anything. On iOS, it instructs you to remove electronic interference (which means your desk/computer may be the issue). It also instructs you to wave the phone around in a figure 8… and then it gets a reading.

    It does sound like you may have an interference issue.

  21. David Gardiner on Tue, 18th Jan 2011 11:07 PM
  22. Did another couple more tests, as I noticed there was a big steel filing cabinet below the desk which could have been a problem.

    Went for a walk outside – reading was still inaccurate, and would change depending on the angle I tilted.

    Then did some more tilting and it’s almost like the app has actually hooked into some kind of gyroscope-type data.

    Having said that, I’ve now had the phone hang twice whilst using the compass app, so there’s definitely something strange going on. If I get a chance, I’ll grab your source code and run it on the phone with the debugger enabled to see if that sheds any light on what’s going on.

  23. Dave on Tue, 18th Jan 2011 11:11 PM
  24. @David – I’m pretty sure the reading of any digital compass (magnetometer) will change based on angle. As far as I can tell, doing anything but facing it straight down will result in an inaccurate reading.

    The Samsung interface doesn’t seem perfect – sometimes it would return data >360 (like in the 10,000 range).

    Also note that, if you force-quit the application using the debugger, the Samsung driver gets into a bad state and the phone will need a reboot, else the reading will remain constant at zero.

  25. Roger on Wed, 19th Jan 2011 5:18 AM
  26. On my Focus, the needle rotates the wrong way. For example, when I hold the phone level (and “north up”), it reads ~0°N as expected. Then, as I turn to the west, the “needle” moves toward E (but the readout displays in °W as expected). This makes the compass confusing to use.

  27. Gerald on Wed, 19th Jan 2011 8:33 PM
  28. Seems to work fairly well, but appears a bit jumpy. I haven’t had a chance to check the accuracy, though. It’s certainly in the right ballpark.

    Now a question: I can’t load the Homebrew solution –
    the TestApp.csproj

  29. Dave on Wed, 19th Jan 2011 8:37 PM
  30. @Roger – it rotates the correct way. The needle will always point north. I realize having the face itself not rotate is causing some confusion though.

  31. Dave on Wed, 19th Jan 2011 8:37 PM
  32. Gerald – Just remove TestApp from the solution, it isn’t needed.

  33. Roger on Thu, 20th Jan 2011 2:31 AM
  34. @Dave – thanks, that makes better sense, I wasn’t interpreting the compass correctly at all (user fail!)

  35. Martin on Sat, 22nd Jan 2011 3:09 PM
  36. If the compass is so bad maybe that’s the reason the API wasn’t included at first…
    Has anybody yet heard of a way to access compass data on HTC devices?

  37. Simon on Tue, 15th Feb 2011 4:15 PM
  38. Is there any known models for converting these readings based on the XYZ accelerometer data? For example, if I tilt the phone as if I was taking a picture of the horizon; how can we translate the heading to get an accurate reading? I’ve tried searching for the web but not sure how to get an answer to this! Thanks for any help.

  39. xutoma on Fri, 18th Mar 2011 5:39 PM
  40. Very good

  41. Dave on Fri, 1st Apr 2011 3:55 PM
  42. @Simon – check the Samsung COM interface, there is a method for Bearing that returns x/y/z.