In this article we connect a MMC5603 3-axis AMR magnetic sensor to the Raspberry Pi Pico
Sensor Information
The MMC5603NJ is a monolithic complete 3-axis AMR magnetic sensor with on-chip signal processing and integrated digital bus (I2C fast mode and I3C interface), the device can be connected directly to a microprocessor, eliminating the need for A/D converters or timing resources.
It can measure magnetic fields within the full scale range of 30 Gauss (G), with up to 0.0625mG per LSB resolution at 20bits operation mode and 2mG total RMS noise level, enabling heading accuracy of 1º in electronic compass applications. Contact MEMSIC for access to advanced calibration and tilt-compensation algorithms.
An integrated SET/RESET function provides for the elimination of error due to Null Field output change with temperature. In addition it clears the sensors of any residual magnetic polarization resulting from exposure to strong external magnets. The SET/RESET function can be performed for each measurement or periodically as the specific application requires.
Features
Monolithic integrated 3-axis AMR magnetic sensor and electronic circuits requiring fewer external components
Superior Dynamic Range and Accuracy:
±30 G FSR
20bits operation mode
0.0625mG per LSB resolution
2 mG total RMS noise
Enables heading accuracy of 1º
Sensor true frequency response up to 1KHz
Ultra-Small Wafer Level Package 0.8×0.8×0.4 mm
On-chip automatic degaussing with built-in SET/RESET function
Eliminates thermal variation induced offset error (Null field output)
Clears the residual magnetization resulting from strong external fields
On-chip sensitivity compensation
On-chip temperature sensor
Selftest signal available
Data_ready Interrupt (I3C only)
Low power consumption – 1 μA power down current
I2C slave, FAST (≤400 KHz) mode
I3C interface available
1.62V to 3.6V wide range single power supply
1.2V logic IO
Parts Required
The sensor you can pick up in the $6 price range – you can connect to the sensor using a standard header the classic dupont style jumper wire.
I used a Qwiic cable – since a few sensors seem to use these but this is optional
Name | Link |
Pico | Raspberry Pi Pico Development Board |
MMC5603 | adafruit MMC5603 |
Connecting cables | Aliexpress product link |
Schematic/Connection
I used the Adafruit LTR303 sensor and in this case used the Stemma connection
For the STEMMA QT cables, it uses the Qwiic convention:
Black for GND
Red for V+
Blue for SDA
Yellow for SCL
So color coded for ease of use, this layout shows a connection to the module
Code Example
I used Thonny for development and I am using Circuitpython
You will need to download and install the latest circuitpython from the citrcuitpython download site
The following is based on a library which you can download the zip bundle from https://github.com/adafruit/Adafruit_CircuitPython_Bundle/releases
Before you continue make sure your board’s lib folder or root filesystem has the adafruit_ltr329_ltr303.mpy, adafruit_bus_device, and adafruit_register files and folders copied over on the RP2040 – https://circuitpython.org/libraries
This is the basic example
import board import busio import adafruit_mmc56x3 i2c = busio.I2C(board.GP1, board.GP0) # SCL, SDA # i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller sensor = adafruit_mmc56x3.MMC5603(i2c) while True: mag_x, mag_y, mag_z = sensor.magnetic temp = sensor.temperature print( "X:{0:10.2f}, Y:{1:10.2f}, Z:{2:10.2f} uT\tTemp:{3:6.1f}*C".format( mag_x, mag_y, mag_z, temp ) ) print("") time.sleep(1.0)
Output
Here is what I saw in Thonny REPL window
>>> %Run -c $EDITOR_CONTENT X: 4.37, Y: -75.27, Z: -66.97 uT Temp: 16.2*C X: 4.39, Y: -74.82, Z: -67.07 uT Temp: 16.2*C X: 5.22, Y: -70.01, Z: -59.61 uT Temp: 16.2*C X: 26.26, Y: -73.11, Z: -93.55 uT Temp: 17.0*C X: 61.47, Y: -63.10, Z: -39.96 uT Temp: 20.2*C
Links
https://media.digikey.com/pdf/Data%20Sheets/MEMSIC%20PDFs/MMC5603NJ_RevB_7-12-18.pdf