Dear Forum-users,
in my project I want to connect multiple BNO055 sensors to my Arduino mega. However, the BNO055 can also take two different addresses on the I2C bus (0x28 and 0x29) which can be changed by pulling the address pin HIGH or LOW. So, as a start, I had the idea to connect the address pins of the sensors to I/O pins and change them in a loop and read only one sensor at a time. For checking, if the BNO055 can change its address during runtime I wrote this little sketch
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BNO055.h>
#include <utility/imumaths.h>
int delayTime = 1000;
int OutPin = 8;
Adafruit_BNO055 bno = Adafruit_BNO055(4, BNO055_ADDRESS_A);
void setup() {
pinMode(OutPin,OUTPUT);
digitalWrite(OutPin,LOW);
Serial.begin(9600);
bno.setExtCrystalUse(true);
// calibrate sensor
Serial.println("Calibrate the first sensor!");
sensors_event_t event;
while (!bno.isFullyCalibrated())
{
bno.getEvent(&event);
Serial.print("X: ");
Serial.print(event.orientation.x, 4);
Serial.print("\tY: ");
Serial.print(event.orientation.y, 4);
Serial.print("\tZ: ");
Serial.print(event.orientation.z, 4);
uint8_t system, gyro, accel, mag = 0;
bno.getCalibration(&system, &gyro, &accel, &mag);
Serial.print("CALIBRATION: Sys=");
Serial.print(system, DEC);
Serial.print(" G=");
Serial.print(gyro, DEC);
Serial.print(" A=");
Serial.print(accel, DEC);
Serial.print(" M=");
Serial.println(mag, DEC);
delay(delayTime);
}
Serial.println("Sensor 1 is fully calibrated!");
}
void loop() {
// first address 0x28
digitalWrite(OutPin,LOW);
bno = Adafruit_BNO055(4, BNO055_ADDRESS_A);
sensors_event_t event;
bno.getEvent(&event);
Serial.println("First address:");
Serial.print("X: ");
Serial.print(event.orientation.x, 4);
Serial.print("\tY: ");
Serial.print(event.orientation.y, 4);
Serial.print("\tZ: ");
Serial.print(event.orientation.z, 4);
uint8_t system, gyro, accel, mag = 0;
bno.getCalibration(&system, &gyro, &accel, &mag);
Serial.print("CALIBRATION: Sys=");
Serial.print(system, DEC);
Serial.print(" G=");
Serial.print(gyro, DEC);
Serial.print(" A=");
Serial.print(accel, DEC);
Serial.print(" M=");
Serial.println(mag, DEC);
delay(delayTime);
// second address 0x29
digitalWrite(OutPin,HIGH);
bno = Adafruit_BNO055(4, BNO055_ADDRESS_B);
bno.getEvent(&event);
Serial.println("Second address:");
Serial.print("X: ");
Serial.print(event.orientation.x, 4);
Serial.print("\tY: ");
Serial.print(event.orientation.y, 4);
Serial.print("\tZ: ");
Serial.print(event.orientation.z, 4);
bno.getCalibration(&system, &gyro, &accel, &mag);
Serial.print("CALIBRATION: Sys=");
Serial.print(system, DEC);
Serial.print(" G=");
Serial.print(gyro, DEC);
Serial.print(" A=");
Serial.print(accel, DEC);
Serial.print(" M=");
Serial.println(mag, DEC);
delay(delayTime);
}
Although the principle is really simple, it seems that the change of address somehow is not working. Has anyone any experience with this? I would appreciate any help. Or is the only way to get multiple sensors working with a multiplexer?
Thanks in advance.