Magnetometer Sensor
The Magnetometer sensor class provides access to a three-dimensional magnetometer.
Constructor
Section titled “Constructor”Magnetometer(options)
Section titled “Magnetometer(options)”Creates a new Magnetometer object instance.
Magnetometer(options)Parameters
Section titled “Parameters”options
An object of properties used to construct the class.
sensor- The hardware connection definition.
interval(optional) - The sampling interval in milliseconds.
Instance Methods
Section titled “Instance Methods”sample()
Section titled “sample()”Returns a sample object containing the current magnetic field data.
sample()Return Value
Section titled “Return Value”An object with the following properties:
x- A number that represents the sampled magnetic field around the x axis in microtesla.
y- A number that represents the sampled magnetic field around the y axis in microtesla.
z- A number that represents the sampled magnetic field around the z axis in microtesla.
Examples
Section titled “Examples”const sensor = new device.sensor.Magnetometer({ sensor: { io: device.io.I2C, address: 0x1E }});
const sample = sensor.sample();console.log(`X: ${sample.x} uT, Y: ${sample.y} uT, Z: ${sample.z} uT`);