Revision as of 23:55, 31 October 2013 by kiran10182 (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Calibrating the magnetometer sensor in Qt

From Nokia Developer Wiki
Jump to: navigation, search

This snippet shows how to calibrate the device's magnetometer sensor by physically rotating the phone and how to handle the calibration level information in the Qt / QML code.

Article Metadata
Tested with
Devices(s): Devices with magnetometer sensor
Platform(s): Symbian
Keywords: Calibration, magnetometer sensor
Created: kratsan (23 Mar 2011)
Last edited: kiran10182 (31 Oct 2013)


Calibrating the device

The device is calibrated by rotating the device through all of its axes. A good way to do this is to rotate the device in a figure of eight as indicated by the picture here. Rotating the device in the Möbius strip at the same time speeds up the calibration.

Calibrate by moving along the path of a Möbius strip

User experience considerations

An application should guide the user to perform the calibration when needed. Whether this is a part of the starting procedure of the application or performed only when needed, depends on the case. Either way, the procedure should be clear to the user and the user must be informed and notified when the calibration is complete. As a reference, the following Compass example does several things to guide the user properly, besides the figure and textual instruction, such as:

  • vibra is used to indicate that the user is expected to perform the calibration
  • progress of the calibration is shown
  • when the calibration is ready, a sound is played and a "calibration ready" note is shown

after which the application automatically proceeds to the compass functions. Using an audio notification to indicate that the sensor has been calibrated is highly recommended since it is difficult for the user to monitor the screen while calibrating the device.

Detecting the calibration level in code


Qt Mobility 1.1 or higher is installed.

Qt / QML code

Add the Qt Mobility project configuration option in the .pro file as shown below

CONFIG += mobility
MOBILITY += sensors


#include <QCompassFilter>
#include <QVariant>
class CompassFilter :
public QObject,
public QCompassFilter
bool filter(QCompassReading *reading);
void azimuthChanged(const QVariant &azimuth, const QVariant &calibrationLevel);


#include "compassfilter.h"
bool CompassFilter::filter(QCompassReading *reading)
// The azimuth and calibration level are retrieved through the
// reading object. The calibration level has values 0..1 where
// the 1.0 means that the sensor is fully calibrated.
emit azimuthChanged(reading->azimuth(), reading->calibrationLevel());
return false;


#include <QCompass>
#include "compassfilter.h"
// ...
QDeclarativeView view;
QObject *rootObject = dynamic_cast<QObject*>(view->rootObject());
QCompass compass;
CompassFilter filter;
connect(&filter, SIGNAL(azimuthChanged(const QVariant&, const QVariant&)),
rootObject, SLOT(handleAzimuth(const QVariant&, const QVariant&)));


#import QtQuick 1.0
Rectangle {
function handleAzimuth(azimuth, calibrationLevel) {
if(calibrationLevel < 1.0) {
// show calibration dialog with calibration level
else {
// show compass with azimuth


The code snippet demonstrated how to calibrate the device by rotating it through all of its axes. The snippet also demonstrated how to retrieve the calibration level on a Qt / QML codes.

This page was last modified on 31 October 2013, at 23:55.
166 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.