3.9.2.5 class MagnetometerXYZAxisData

Class Attributes

Example

from sensor import *
import e32

class DemoApp():

    def __init__(self):

        self.magnetometer = \
            MagnetometerXYZAxisData(data_filter=LowPassFilter())

        self.magnetometer.set_callback(data_callback=self.my_callback)

        self.counter = 0

    def my_callback(self):

        # For stream sensor data the callback is hit 35 times per sec(On
        # 5800). The device cannot handle resource hungry operations like
        # print in the callback function for such high frequencies. A
        # workaround is to sample the data as demonstrated below.

        if self.counter % 5 == 0:
            print  "Calib:", self.magnetometer.calib_level
            print "X:%s, Y:%s, Z:%s" % (self.magnetometer.x, self.magnetometer.y,  self.magnetometer.z)
        self.counter = self.counter + 1

    def run(self):

        self.magnetometer.start_listening()

if __name__ == '__main__':

    d = DemoApp()

    d.run()

    e32.ao_sleep(5)

    d.magnetometer.stop_listening()

    print "Exiting MagnetometerAxis"

See About this document... for information on suggesting changes.