Simple test¶
Ensure your device works with this simple test.
import time
from machine import Pin, I2C
from micropython_mmc5603 import mmc5603
i2c = I2C(1, sda=Pin(2), scl=Pin(3)) # Correct I2C pins for RP2040
mmc = mmc5603.MMC5603(i2c)
while True:
mag_x, mag_y, mag_z = mmc.magnetic
print(f"X:{mag_x:.2f}, Y:{mag_y:.2f}, Z:{mag_z:.2f} uT")
temp = mmc.temperature
print(f"Temperature: {temp:.2f}°C")
print()
time.sleep(1.0)
Continuous Mode¶
Example showing the continuous mode
import time
from machine import Pin, I2C
from micropython_mmc5603 import mmc5603
i2c = I2C(1, sda=Pin(2), scl=Pin(3)) # Correct I2C pins for RP2040
mmc = mmc5603.MMC5603(i2c)
mmc.data_rate = 10 # in Hz, from 1-255 or 1000
mmc.continuous_mode = True
while True:
mag_x, mag_y, mag_z = mmc.magnetic
print(f"X:{mag_x:.2f}, Y:{mag_y:.2f}, Z:{mag_z:.2f} uT")
print()
time.sleep(0.5)
Measure time settings¶
Example showing the Measure time setting
import time
from machine import Pin, I2C
from micropython_mmc5603 import mmc5603
i2c = I2C(1, sda=Pin(2), scl=Pin(3)) # Correct I2C pins for RP2040
mmc = mmc5603.MMC5603(i2c)
mmc.measure_time = mmc5603.MT_3_5ms
while True:
for measure_time in mmc5603.measure_time_values:
print("Current Measure time setting: ", mmc.measure_time)
for _ in range(10):
magx, magy, magz = mmc.magnetic
print(f"X:{magx:.2f}, Y:{magy:.2f}, Z:{magz:.2f} uT")
print()
time.sleep(0.5)
mmc.measure_time = measure_time