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

Remarks

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

Examples

Interrupt Mode

This library supports interrupts when the sensor completes a reading:

using System.Threading;
using Meadow;
using Meadow.Foundation.Sensors.Motion;

namespace MAG3110_Sample
{
    public class Program
    {
        static IApp _app; 
        public static void Main()
        {
            _app = new App();
        }
    }

    public class App : AppBase<F7Micro, App>
    {
        public App ()
        {
            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());
        }
    }
}

Polling Mode

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

using System.Threading;
using Meadow;
using Meadow.Foundation.Sensors.Motion;

namespace MAG3110_Sample
{
    public class Program
    {
        static IApp _app; 
        public static void Main()
        {
            _app = new App();
        }
    }

    public class App : AppBase<F7Micro, App>
    {
        public App ()
        {
            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);
            }
        }
    }
}
Example Circuit

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

Constructors

View Source

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).

View Source

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

View Source

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.

View Source

DigitalInputsEnabled

Declaration
public bool DigitalInputsEnabled { get; set; }

Property Value

Type Description
System.Boolean
View Source

Standby

Change or get the standby status of the sensor.

Declaration
public bool Standby { get; set; }

Property Value

Type Description
System.Boolean
View Source

Temperature

Temperature of the sensor die.

Declaration
public sbyte Temperature { get; }

Property Value

Type Description
System.SByte
View Source

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.

View Source

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.

View Source

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

View Source

Read()

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

Declaration
public void Read()
View Source

Reset()

Reset the sensor.

Declaration
public void Reset()

Events

View Source

OnReadingComplete

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

Declaration
public event MAG3110.ReadingComplete OnReadingComplete

Event Type

Type Description
MAG3110.ReadingComplete