Compass is very jittery

I’ve made a compass app, but not a typical circular type compass but a horizontal scrolling type.

The orange coloured cardinal is just for devving purposes.

While developing the app, I’m using a holder to keep the device still and safe while attached to USB cable, this means the device is sat at an angle for good visibility, but this makes the compass so jittery, I can barely do anything with it and have to keep tilting and moving the device to check my progress…what a PITA, the scrolling of the cardinal points goes across the screen faster than Concorde did to Paris.

Of course, if I lay the device on the table and rotate it, readings do settle and are accurate, but tilt the device slightly and compass goes nuts!

Is this just an inherent feature/problem of the sensor?, is there something I can do to compensate?

I tried to catch the jittering on video, but I only have my Jolla1 and the poor framerate almost makes the jittering disappear.

You develop your App indoors, right?

So there might be electromagnetical interferences from line powered Devices around you.

Maybe its a good idea to collect an small amount of datas and interpolate the result to get rid of the jitter, a common way.

lol, of course I develop indoors, what developer sits in his/her garden while writing code?, here in Spain, spending any time outdooors leads to skin cancer, mosquito bites, holiday makers screaming and shouting, dogs barking, motorbike tearing up the main road…indoors, is quiet and the optimum place to write code…however, I cannot disagree with your comment. I thought maybe my wireless keyboard was the problem, but, noooooo, nor my monitors.

Upon your first statement, I took my device out into the middle of the garden, no electrics nearby, no overhead cables or telephone lines and guess what?, the compass is still just as jittery…it seems to be the angle at which the device sits as I am using a holder rather than putting the device flat on the ground, but being flat on the ground, the compass is far, far less jittery, infact, sometimes, it runs perfectly.

I’ve found some code that uses timers to eek out the data flowing from compass, but I couldn’t get to grips with it. any suggestions?, I suppose I should show some code, but I need to explore first and find out if the sensor is a problem or not.

Even a normal rotating compass gets really jittery when the phone is at any angle other than flat, maybe I’m missing something in my code, but a usual, examples are poor/thin on the ground or non-existent.

It really does seem to boil down to the angle of my device as to whether or not compass becomes stable or epileptic.

It would not surprise me if the sensitivity to the orientation of the phone indeed was an hardware issue. In order to allow an orientation-independent measurement of the magnetic field the sensor would have to be rotationally symmetric, which I cannot imagine in a smartphone shaped device. Probably it is optimised for flat use and thus the signal worsens if you tilt the phone (since that way the sensot can only measure the projection of the magnetic field ino its plane, which is weaker).

Could you provide the used code? I’d be happy to try on my xperia 10II.
Also, did you calibrate the compass correctly? When not calibrated, it shifts values quite a bit (for me).
Lastly, you could implement a smooth animation (using debounce / some kind of delta change)? Because sensor / hardware input require such a thing most of the time, in my experience.

I can provide code, but I need to strip it back first to essentials first.

I know nothing about calibration of compass, how is that done?

I’ve tried many different methods to smooth out the animation, but as yet, I haven’t found a suitable way.

Right now, with the device flat on the table, the correct cardinal is displayed, tilt the device from the left or right hand side, and it goes berserk.

I like that compass style, takes me back to my surveying days and Suunto sighting compasses.

FYI, GPSInfo uses the compass so you can compare performance (and look at the source)

(Jolla 1 is very old, and cheap compass chips have improved in a decade)

In X10III SF4.5, GPSInfo shows stable compass when horizontal, jittering a bit as tilt increases.
The shown bearing is meaningless when the phone is vertical. This probably means a two axis compass sensor. i.e. as you tilt it. it will cease to work. (Even if you have a 3 axis sensor , the meaning of the bearing has to be changed at high tilt i.e. you must change the reference plane for it to make sense)

When I was testing the XA2’s compass a couple of years ago, I had a wooden stake hammered in the garden with a fixed alignment plate I could set the phone into. The reading varied by up to 30 degrees day to day. I have not repeated this with the X10III.
My experience of the compass in phones is that they are uselessly inaccurate and unstable.
(So I still have a Silva compass tied to my shirt when hiking)


The bearing given is quite strongly dependent on tilt. eg 15 deg tilt is causing 10 degrees change in bearing in GPSInfo.
This is no surprise. Where I live the earths magnetic field dip is 60 degrees.
Here’s some stuff about this..
If you want a consistent (if not accurate) compass, you will probably need to keep the phone level. Showing a bubble level might be a good idea…
Also don’t forget that you must know declination to find true (map) north