Remarks

MAG3110
Status Not tested
Source code GitHub
NuGet package Not published

The MAG3110 is a three axis magnetometer with an I2C interface. The magnetometer is capable of single and continuous readings.

Code Example

This library supports interrupts when the sensor completes a reading:

public class MeadowApp : App<F7Micro, MeadowApp>
{
    public MeadowApp()
    {
        Console.WriteLine("MAG3110 Test Application");
        Mag3110 mag3110 = new Mag3110(0x0e, 400, Pins.GPIO_PIN_D8);
        mag3110.OnReadingComplete += mag3110_OnReadingComplete;
        mag3110.InterruptsEnabled = true;
        mag3110.Standby = false;
        Thread.Sleep(Timeout.Infinite);
    }

    static void mag3110_OnReadingComplete(Mag3110.SensorReading sensorReading)
    {
        Console.WriteLine(
            "Reading: x = " + sensorReading.X.ToString() + 
            ", y = " + sensorReading.Y.ToString() + 
            ", z = " + sensorReading.Z.ToString());
    }
}

Sample projects available on GitHub

Polling Mode

The following application reads the values from the magnetometer and displays the readings on the debug output:

public class MeadowApp : App<F7Micro, MeadowApp>
{
    public MeadowApp()
    {
        Console.WriteLine("MAG3110 Test Application");
        Mag3110 mag3110 = new Mag3110();
        mag3110.Standby = false;
        int readingCount = 0;

        while (true)
        {
            mag3110.Read();
            readingCount++;
            Console.WriteLine(
                "Reading " + readingCount.ToString() + 
                ": x = " + mag3110.X.ToString() + 
                ", y = " + mag3110.Y.ToString() + 
                ", z = " + mag3110.Z.ToString());
            Thread.Sleep(1000);
        }
    }
}

Wiring Example

In it's basic configuration the magnetometer requires four connections:

Meadow Pin Sensor Pin Wire Color
3.3V Vcc Red
GND GND Black
SC SCK Green
SD SDA Blue
D8 INT1 Orange

Characteristic Locus
Inheritance System.Object > Mag3110
Inherited Members System.Object.ToString() System.Object.Equals(System.Object) System.Object.Equals(System.Object, System.Object) System.Object.ReferenceEquals(System.Object, System.Object) System.Object.GetHashCode() System.Object.GetType() System.Object.MemberwiseClone()
Namespace Meadow.Foundation.Sensors.Motion
Assembly MAG3110.dll

Syntax

public class Mag3110

Constructors

Mag3110(II2cBus, IDigitalInputPort, Byte)

Create a new MAG3110 object using the default parameters for the component.

Declaration
public Mag3110(II2cBus i2cBus, IDigitalInputPort interruptPort = null, byte address = 14)

Parameters

Type Name Description
II2cBus i2cBus

I2C bus object - default = 400 KHz).

IDigitalInputPort interruptPort

Interrupt port used to detect end of conversions.

System.Byte address

Address of the MAG3110 (default = 0x0e).

Mag3110(IIODevice, II2cBus, IPin, Byte, UInt16)

Create a new MAG3110 object using the default parameters for the component.

Declaration
public Mag3110(IIODevice device, II2cBus i2cBus, IPin interruptPin = null, byte address = 14, ushort speed = 400)

Parameters

Type Name Description
IIODevice device

IO Device.

II2cBus i2cBus
IPin interruptPin

Interrupt pin used to detect end of conversions.

System.Byte address

Address of the MAG3110 (default = 0x0e).

System.UInt16 speed

Speed of the I2C bus (default = 400 KHz).

Properties

DataReady

Indicate if there is any data ready for reading (x, y or z).

Declaration
public bool DataReady { get; }

Property Value

Type Description
System.Boolean

Remarks

See section 5.1.1 of the datasheet.

DigitalInputsEnabled

Declaration
public bool DigitalInputsEnabled { get; set; }

Property Value

Type Description
System.Boolean

Standby

Change or get the standby status of the sensor.

Declaration
public bool Standby { get; set; }

Property Value

Type Description
System.Boolean

Temperature

Temperature of the sensor die.

Declaration
public sbyte Temperature { get; }

Property Value

Type Description
System.SByte

X

Reading from the X axis.

Declaration
public short X { get; }

Property Value

Type Description
System.Int16

Remarks

Data in this property is only current after a call to Read.

Y

Reading from the Y axis.

Declaration
public short Y { get; }

Property Value

Type Description
System.Int16

Remarks

Data in this property is only current after a call to Read.

Z

Reading from the Z axis.

Declaration
public short Z { get; }

Property Value

Type Description
System.Int16

Remarks

Data in this property is only current after a call to Read.

Methods

Read()

Force the sensor to make a reading and update the relevanyt properties.

Declaration
public void Read()

Reset()

Reset the sensor.

Declaration
public void Reset()

Events

OnReadingComplete

Generated when the sensor indicates that data is ready for processing.

Declaration
public event Mag3110.ReadingComplete OnReadingComplete

Event Type

Type Description
Mag3110.ReadingComplete