How to connect two AltImu-10 v6 via i2c?

I am working with 2 Pololu Altimu-10 V6 connected to the same ESP32 board. Both of them are connected via i2c protocol and have different addresses. The addresses are 0x1C and 0x1E.

I have this code to calibrate the magneometer of one. How can I change it to measure both of them??

I dont’t know how to specify the address of each one:

#include <Wire.h>
#include <LIS3MDL.h>

LIS3MDL mag;
LIS3MDL::vector<int16_t> running_min = {32767, 32767, 32767}, running_max = {-32768, -32768, -32768};

char report[80];

void setup(){
  Serial.begin(9600);
  Wire.begin();

  if (!mag.init()){
    Serial.println("Failed to detect and initialize magnetometer!");
    while (1);
  }

  mag.enableDefault();
}

void loop()
{
  mag.read();

  running_min.x = min(running_min.x, mag.m.x);
  running_min.y = min(running_min.y, mag.m.y);
  running_min.z = min(running_min.z, mag.m.z);

  running_max.x = max(running_max.x, mag.m.x);
  running_max.y = max(running_max.y, mag.m.y);
  running_max.z = max(running_max.z, mag.m.z);

  snprintf(report, sizeof(report), "min: {%+6d, %+6d, %+6d}   max: {%+6d, %+6d, %+6d}",
    running_min.x, running_min.y, running_min.z,
    running_max.x, running_max.y, running_max.z);
  Serial.println(report);

  delay(100);
}

I tried adding this:

if(!mag1.init(device_LIS3MDL, sa1_low)){
  Serial.println("Failed to detect and initialize magnetometer 1!");
  while (1);
}
if(!mag2.init(device_LIS3MDL, sa1_high)){
  Serial.println("Failed to detect and initialize magnetometer 2!");
  while (1);
}

but I got this error: 'device_LIS3MDL' was not declared in this scope

Hello.

The device_LIS3MD, sa1_low, and sa1_high variables you are using as arguments for the init() function are only declared in the LIS3MDL class and not in your main code, so you need to direct your program where to find those. That will look like this for mag1:

mag1.init(LIS3MDL::device_LIS3MDL, LIS3MDL::sa1_low)

and for mag2:

mag2.init(LIS3MDL::device_LIS3MDL, LIS3MDL::sa1_high)

- Patrick

1 Like

Thanks!! Now I want to read the data from both IMUS. When I was using just one of them, I used the file MinIMU9AHRS (GitHub - pololu/minimu-9-ahrs-arduino: Arduino program for building an AHRS with a Pololu MinIMU-9) . In order to read both of them, which would be the best way to do it?

Unfortunately, we do not have an example program or reference for how to read and interpret data from two IMUs, and I do not have any specific suggestions for that.

- Patrick