Simple test
Ensure your device works with this simple test.
examples/mmc56x3_simpletest.py
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4"""Display magnetometer data once per second"""
5
6import time
7
8import board
9
10import adafruit_mmc56x3
11
12i2c = board.I2C() # uses board.SCL and board.SDA
13# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
14sensor = adafruit_mmc56x3.MMC5603(i2c)
15
16while True:
17 mag_x, mag_y, mag_z = sensor.magnetic
18 temp = sensor.temperature
19
20 print(f"X:{mag_x:10.2f}, Y:{mag_y:10.2f}, Z:{mag_z:10.2f} uT\tTemp:{temp:6.1f}*C")
21 print("")
22 time.sleep(1.0)
Continuous mode test
Test using continuous mode.
examples/mmc56x3_continuous.py
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4"""Display magnetometer data very quickly using the continuous data capture mode"""
5
6import board
7
8import adafruit_mmc56x3
9
10i2c = board.I2C() # uses board.SCL and board.SDA
11# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
12sensor = adafruit_mmc56x3.MMC5603(i2c)
13
14sensor.data_rate = 10 # in Hz, from 1-255 or 1000
15sensor.continuous_mode = True
16
17while True:
18 mag_x, mag_y, mag_z = sensor.magnetic
19 print(f"X:{mag_x:10.2f}, Y:{mag_y:10.2f}, Z:{mag_z:10.2f} uT")
DisplayIO Simpletest
This is a simple test for boards with built-in display.
examples/mmc56x3_displayio_simpletest.py
1# SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries
2# SPDX-FileCopyrightText: 2024 Jose D. Montoya
3#
4# SPDX-License-Identifier: MIT
5
6import time
7
8import board
9from adafruit_display_text.bitmap_label import Label
10from displayio import Group
11from terminalio import FONT
12
13import adafruit_mmc56x3
14
15# Simple demo of using the built-in display.
16# create a main_group to hold anything we want to show on the display.
17main_group = Group()
18# Initialize I2C bus and sensor.
19i2c = board.I2C() # uses board.SCL and board.SDA
20sensor = adafruit_mmc56x3.MMC5603(i2c)
21
22# Create Label(s) to show the readings. If you have a very small
23# display you may need to change to scale=1.
24display_output_label = Label(FONT, text="", scale=2)
25
26# place the label(s) in the middle of the screen with anchored positioning
27display_output_label.anchor_point = (0, 0)
28display_output_label.anchored_position = (
29 4,
30 board.DISPLAY.height // 2 - 60,
31)
32
33# add the label(s) to the main_group
34main_group.append(display_output_label)
35
36# set the main_group as the root_group of the built-in DISPLAY
37board.DISPLAY.root_group = main_group
38
39# begin main loop
40while True:
41 # update the text of the label(s) to show the sensor readings
42 mag_x, mag_y, mag_z = sensor.magnetic
43 display_output_label.text = f"x: {mag_x:.1f}uT\ny: {mag_y:.1f} uT\nz: {mag_z:.1f} uT"
44 # wait for a bit
45 time.sleep(0.5)