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
2 posts - 2 participants