MicroPython MMC5603 Library

mmc5603

MicroPython driver for the Memsic MMC5603 Magnetometer

  • Author(s): ladyada, Jose D. Montoya

class micropython_mmc5603.mmc5603.MMC5603(i2c, address: int = 0x30)[source]

Driver for the MMC5603 Sensor connected over I2C.

Parameters:
i2c : I2C

The I2C bus the MMC5603 is connected to.

address : int

The I2C device address. Defaults to 0x30

Raises:

RuntimeError – if the sensor is not found

Quickstart: Importing and using the device

Here is an example of using the MMC5603 class. First you will need to import the libraries to use the sensor

from machine import Pin, I2C
from micropython_mmc5603 import mmc5603

Once this is done you can define your machine.I2C object and define your sensor object

i2c = I2C(1, sda=Pin(2), scl=Pin(3))
mmc = mmc5603.MMC5603(i2c)

Now you have access to the attributes

magx, magy, magz = mmc.magnetic
property continuous_mode : bool

Whether or not to put the chip in continous mode - be sure to set the data_rate as well!

property data_rate : int

Output data rate, 0 for on-request data. 1-255 or 1000 for freq of continuous-mode readings

property magnetic : tuple[float, float, float]

The processed magnetometer sensor values. A 3-tuple of X, Y, Z axis values in microteslas that are signed floats.

property measure_time : str

Sensor measure_time adjust the length of the decimation filter. They control the duration of each measurement. Note: X/Y/Z channel measurements are taken sequentially. Delay Time among those measurements is 1/3 of the Measurement

Mode

Value

mmc5603.MT_6_6ms

0b00

mmc5603.MT_3_5ms

0b01

mmc5603.MT_2_0ms

0b10

mmc5603.MT_1_2ms

0b11

property temperature : float

The processed temperature sensor value, returned in floating point C