LIS3MDL #7053
guoquan1963
started this conversation in
General
LIS3MDL
#7053
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I am using I2C to read sensor data from LIS3MDL and it works fine. See the code below...
I have the following issues:
Thanks,
Christie
// Includes.
#include <LIS3MDLSensor.h>
#include <Wire.h>
#define SerialPort Serial
#define I2C2_SCL 36 // I2C on LIM3MDL
#define I2C2_SDA 33 // I2C on LIM3MDL
//#define I2C2_SCL 31 // I2C on LSM9dS1
//#define I2C2_SDA 37 // I2C on LSM9dS1
TwoWire dev_i2c(0x1C); // I2C Address on LSM9dS1 MAG
LIS3MDLSensor Magneto(&dev_i2c);
void setup() {
// Initialize serial for output.
SerialPort.begin(115200);
dev_i2c.begin();
// Initialize components.
Magneto.begin();
Magneto.Enable();
}
void loop() {
// Read magnetometer.
int32_t magnetometer[3];
uint8_t mag_ID;
Magneto.ReadID(&mag_ID);
SerialPort.println(mag_ID);
Magneto.GetAxes(magnetometer);
// Output data.
SerialPort.print("Mag[mGauss]: ");
SerialPort.print(magnetometer[0]);
SerialPort.print(" ");
SerialPort.print(magnetometer[1]);
SerialPort.print(" ");
SerialPort.println(magnetometer[2]);
delay(1000);
}
Beta Was this translation helpful? Give feedback.
All reactions