How do I configure and read from the magnetometer?

How do I configure and read from the magnetometer?

adnamaadnama Member Posts: 6
I'm writing a very simple app that plays a sound from the north. I'm totally blind since birth. I think a constant cardinal awareness would improve my ability to mentally map a space and it might also do the same for sighted people.

I'm new to Swift but not to programming. The magnetometer is the only sensor that has no associated demo or sample code in the documentation. I need information about what methods to call, return values to expect, etc. Thanks.


  • Nadine@Bose[email protected] Member Posts: 111
    Hi @adnama

    The SDK does not provide direct access to the magnetometer as that data is not useful in isolation. The hardware fuses the raw magnetometer data with the other sensors to derive the rotation vector which is relative to magnetic north. The compass heading is accessible via the yaw property of a quaternion value provided by the rotation sensor.

    The rotation sensor provides quaternion values as well as estimated accuracy readings (in radians). These are both provided to the SensorDispatch.rotationCallback block and to the SensorDispatchHandler.receivedRotation(quaternion:accuracy:timestamp:) function.

    This information is visible in the Data Example app in the iOS SDK. Connect to a device, select Sensor Data, then enable the Rotation sensor. The yaw value will show the device's heading relative to magnetic north.

    Hope this is helpful,
Sign In or Register to comment.