iMX233-OLinuXino I2C tutorial – using MOD-MAG 3 axes magnetometer


MAG3110 is interesting little device, it’s preciese 3 axis magnetometer which measure the magnetic field in range +- 1000 uT and have sensitivity of 0.1 uT.

MAG3110 is manufactured by Freescale and you can find the datasheets here.

MOD-MAG UEXT module contain MAG3110 and connects directly to all our boards with UEXT connector. MOD-MAG user manual is here.

Magnetometers are widely used by treasure hunters to scan geo magnetic field and make maps. Why? because metals in earth change the earths magnetic field and scanning the magnetic field you can see what is under the surface.

Typical magnetometer maps is like this you can see different magnetic levels colored in different colors.

MOD-MAG.c demo code is available on GitHub .

Before you use it make sure your board is with hardware I2C enabled as I explained in my previous post:

Once you download it you can compile and make executable:

$ cc MOD-MAG.c -o mod-mag
$ chmod +x mod-mag

then when you execute it you will see MAG3110 registers:

$ ./mod-mag

Register[0x00]: 0xFF
Register[0x01]: 0x0B
Register[0x02]: 0x59
Register[0x03]: 0xF5
Register[0x04]: 0xDC
Register[0x05]: 0x02
Register[0x06]: 0x85
Register[0x07]: 0xC4
Register[0x08]: 0x02

these 9 registers actually contain X,Y,Z values x2 bytes per axe

by approaching magnet to MOD-MAG you can see how these values are changing, now all you have to do is to scan some surface and find a good way to visualize the captured info 🙂

DuinoMite Project: Measuring Earths Magnetic Field with MAG3110


MAG3110 is nice digital 3-axis magnetometer. We built MOD-MAG which is board with MAG3110 and UEXT so this magnetometer can easily be connected to any of our development boards. The example here is with DuinoMite-Mini.

MAG3110 is pretty sensitive with 0.1 uT resolution and have full scale +-1000uT. For reference the Earth magnetic field varry from equator to poles in range 25-65 uT, so it’s possible to measure Earth’s magnetic field with MAG3110 and make for instance Compass or to scan infield for buried metal objects which affect Earth magnetic field or make tons of other interesting projects.

WiKi as usuall is great source for information on Earth magnetic field:’s_magnetic_field

The complete MAG3110 data sheet is available at Freescale web:

Geomagnetic storms influence our life and you can read more for them here, moderate and intensive Geomagnetic storms could be detected and monitored with MAG3110.

For finer resolution magnetic fields are measured with fluxgate magnetomeres which can sense down to 0.01 uT, here is nice article about the fluxgate magnetometers:

MAG3110 digital interface is I2C so very easy to read it with DuinoMite.
Here is small code I wrote to test MOD-MAG which have on board MAG3110 and UEXT connector:

10 OPTION BASE 0 ‘to make sure we have base 0
20 ID = 0: DIM AXES(6) ‘ID variable and AXES array
30 I2CEN 100,100 ‘enable I2C
40 I2CRCV &H0E, 0, 1, ID, 1, 7 ‘read MAG3110 ID (C4)
50 PRINT “ID = “;HEX$(ID) ‘should print C4 if MOD-MAG is attached
60 I2CSEND &H0E, 1, 2, &H11, &H80 ‘ctrl reg2, auto resets enbl
70 I2CSEND &H0E, 0, 2, &H10, &H01 ‘ctrl reg1, active mode
80 I2CRCV &H0E, 6, AXES(0), 1, 1 ‘read 6 bytes from addr 1
90 PRINT “X =”; HEX$(AXES(0)*256+AXES(1)); TAB(10) ‘X axe
100 PRINT “Y =”; HEX$(AXES(2)*256+AXES(3)); TAB(20) ‘Y axe
110 PRINT “Z =”; HEX$(AXES(4)*256+AXES(5)) ‘Z axe
120 IF INKEY$ <> “” THEN 200 ‘end if key is pressed
130 PAUSE 300 ‘wait a little
140 GOTO 80 ‘read and print again
200 I2CDIS ‘disable I2C


as you can see the magnetometer on my desk do not give steady values, this is because we are surrounded by lot of invisible magnetic noise radiated from the computers, monitors, and so on electronics around us.