-
Notifications
You must be signed in to change notification settings - Fork 7.7k
LIS3MDL #7053
-
Hi,
I am using I2C to read sensor data from LIS3MDL and it works fine. See the code below...
I have the following issues:
- If I change I2C pin definition or remove it, it still works. Can you tell where I can change I2C pin definition?
- If I want to the second I2C, how can initialize it?
- When I try to set Pin definition in .begin function, it stops working?
- How to set I2C speed, like 100KHz?
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.