Your advice helped at least some steps forward. Calibration changed the x, y, z -values to make at least some sense. I used this program (partly copied from these pages):
Originally Posted by vladestCh
During calibration the phone was rotated e.g. along a Moebius strip. The output showed how the variable calib_level changed from 0 to 1 to 2 and finally to 3, within
from sensor import *
import e32, time
self.sobj = MagnetometerXYZAxisData()
self.counter = 0
self.xs = 0
self.ys = 0
self.zs = 0
if self.counter % 10 == 0:
print "X:%s, Y:%s, Z:%s, c:%s" % (self.sobj.x,
self.sobj.y, self.sobj.z, self.sobj.calib_level)
#print "Timestamp:", self.sobj.timestamp # works
self.counter = self.counter + 1
self.xs += self.sobj.x
self.ys += self.sobj.y
self.zs += self.sobj.z
if __name__ == '__main__':
d = DemoApp()
e32.ao_sleep(30) # 30 seconds
print d.xs / d.counter, d.ys / d.counter, d.zs / d.counter
print "Normal exit"
some seconds. Thus the calibration was much simpler than I thought .
After calibration I restarted the program so that the phone was still in a constant orientation and position during the program run. I took note about the averages of x, y, and z.
I restarted again, now z-axis of the phone exactly in the opposite direction compared to the previous test run. One would suppose that now the z-axis would be about the same magnitude as earlier but with the opposite sign. The test gave about the expected answers, but the the variation of the numbers was fairly large, ten or even tens of percent. The uncalibrated values were total garbage.
In repeated tests the calib_level went back to 0 after 2-4 tests typically. (during one test the phone was still). This makes the sensor unusable in my intended bike application: it is not practical to start waving the phone in every minute! Any ideas?
By the way, the gyroscope idea might be good. I did not know that there are already Nokia phones with a gyroscope.