Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

LIS3MDL #7053

guoquan1963 started this conversation in General
LIS3MDL #7053
Jul 28, 2022 · 0 comments
Discussion options

Hi,
I am using I2C to read sensor data from LIS3MDL and it works fine. See the code below...
I have the following issues:

  1. If I change I2C pin definition or remove it, it still works. Can you tell where I can change I2C pin definition?
  2. If I want to the second I2C, how can initialize it?
  3. When I try to set Pin definition in .begin function, it stops working?
  4. 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);
}

You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /