Using the MMC5603 with Arduino involves wiring up the sensor to your Arduino-compatible microcontroller, installing the Adafruit_MMC56x3 library and running the provided example code.
Wiring
Wire as shown for a 5V board like an Uno. If you are using a 3V board, like an Adafruit Feather, wire the board's 3V pin to the MMC5603 VIN.
Here is an Adafruit Metro wired up to the MMC5603 using the STEMMA QT connector:
-
Board 5V to sensor VIN (red wire)
-
Board GND to sensor GND (black wire)
-
Board SCL to sensor SCL (yellow wire)
- Board SDA to sensor SDA (blue wire)
Here is an Adafruit Metro wired up using a solderless breadboard:
-
Board 5V to sensor VIN (red wire)
-
Board GND to sensor GND (black wire)
-
Board SCL to sensor SCL (yellow wire)
- Board SDA to sensor SDA (blue wire)
Library Installation
You can install the Adafruit MMC56x3 library for Arduino using the Library Manager in the Arduino IDE.
Click the Manage Libraries ... menu item, search for Adafruit MMC56x3, and select the Adafruit MMC56x3 library:
If asked about dependencies, click "Install all".
If the "Dependencies" window does not come up, then you already have the dependencies installed.
#include <Adafruit_MMC56x3.h> /* Assign a unique ID to this sensor at the same time */ Adafruit_MMC5603 mmc = Adafruit_MMC5603(12345); void setup(void) { Serial.begin(115200); while (!Serial) delay(10); // will pause Zero, Leonardo, etc until serial console opens Serial.println("Adafruit_MMC5603 Magnetometer Test"); Serial.println(""); /* Initialise the sensor */ if (!mmc.begin(MMC56X3_DEFAULT_ADDRESS, &Wire)) { // I2C mode /* There was a problem detecting the MMC5603 ... check your connections */ Serial.println("Ooops, no MMC5603 detected ... Check your wiring!"); while (1) delay(10); } /* Display some basic information on this sensor */ mmc.printSensorDetails(); } void loop(void) { // Get a new sensor event sensors_event_t event; mmc.getEvent(&event); // Display the results (magnetic vector values are in micro-Tesla (uT)) Serial.print("X: "); Serial.print(event.magnetic.x); Serial.print(" "); Serial.print("Y: "); Serial.print(event.magnetic.y); Serial.print(" "); Serial.print("Z: "); Serial.print(event.magnetic.z); Serial.print(" "); Serial.println("uT"); // Read and display temperature float temp_c = mmc.readTemperature(); Serial.print("Temp: "); Serial.print(temp_c); Serial.println(" *C"); // Delay before the next sample delay(100); }
Upload the sketch to your board and open up the Serial Monitor (Tools -> Serial Monitor) at 115200 baud. You should see the values from the embedded temperature sensor and magnetometer being printed out. You'll see the values change depending on the movement of the sensor.
Text editor powered by tinymce.