Simple test¶
Ensure your device works with this simple test.
examples/mmc5603_simpletest.py¶
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("X:{0:10.2f}, Y:{1:10.2f}, Z:{2:10.2f} uT".format(mag_x, mag_y, mag_z))
temp = mmc.temperature
print("Temperature: {:.2f}C".format(temp))
print()
time.sleep(1.0)
# print(mmc.data_rate)
# mmc.data_rate = 10 # in Hz, from 1-255 or 1000
# mmc.continuous_mode = True
# print(mmc.data_rate)
#
# while True:
# mag_x, mag_y, mag_z = mmc.magnetic
# print("X:{0:10.2f}, Y:{1:10.2f}, Z:{2:10.2f} uT".format(mag_x, mag_y, mag_z))
# time.sleep(2)
Continuous Mode¶
Example showing the continuous mode
examples/mmc5603_continuous.py¶
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("X:{0:10.2f}, Y:{1:10.2f}, Z:{2:10.2f} uT".format(mag_x, mag_y, mag_z))
print()
time.sleep(0.5)
Measure time settings¶
Example showing the Measure time setting
examples/mmc5603_measure_time.py¶
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("x:{:.2f}uT, y:{:.2f}uT, z:{:.2f}uT".format(magx, magy, magz))
print()
time.sleep(0.5)
mmc.measure_time = measure_time