BNO055 (Mutiplexing)

I'm trying to use BNO055 to record the accelerations. When I use only one BNO055, it works well. However I want to use four BNO055s at the same time, so I use a Multiplexer to achieve it.

It sometimes works. But sometimes it works in the beginning and then some (or all) of the BNO055's accelerations become 0, even all sensors stop working.

Is there any problem in my code?

THANKS.

※This is my first post Sorry if there are some stupid mistakes~~

CODE:

//UNO + 4BNO055
#include <Wire.h>
#include <I2Cdev.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BNO055.h>
#include <utility/imumaths.h>


Adafruit_BNO055 bno_0 = Adafruit_BNO055(55);
Adafruit_BNO055 bno_1 = Adafruit_BNO055(55);
Adafruit_BNO055 bno_2 = Adafruit_BNO055(55);
Adafruit_BNO055 bno_3 = Adafruit_BNO055(55);

//Adafruit_BNO055 bno = Adafruit_BNO055(55);


#define OUTPUT_READABLE_ACCELGYRO

//#define OUTPUT_BINARY_ACCELGYRO

#define LED_PIN 13
bool blinkState = false;

//Mux control pins
int s0 = 5;
int s1 = 6;

//Mux in "SIG" pin
int SIG_pin = 0;

const int MPU=0x68;

void setup() {
  
    pinMode(s0, OUTPUT); 
    pinMode(s1, OUTPUT); 
    
  
    // join I2C bus (I2Cdev library doesn't do this automatically)
    #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
        Wire.begin();
    #elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
        Fastwire::setup(400, true);
    #endif

    // initialize serial communication
    // (9699 chosen because it works as well at 8MHz as it does at 16MHz, but
    // it's really up to you depending on your project)
    Serial.begin(9600);
    Serial.println("CLEARSHEET");
    //Serial.println("LABEL,Time,Timer,x1,y1,z1");
    Serial.println("LABEL,Time,Timer,x0,y0,z0,x1,y1,z1,x2,y2,z2,x3,y3,z3");
   
    // ================= MPU: 0 =================
    digitalWrite(s0, LOW);
    digitalWrite(s1, LOW);
    delay(5);
    /*
    Wire.begin();
    Wire.beginTransmission(MPU);
    Wire.write(0x6B);  // PWR_MGMT_1 register
    Wire.write(0);     // set to zero (wakes up the MPU-6050)
    Wire.endTransmission(true);
    */
    //delay(15);
    bno_0.begin();
    Serial.println("Testing device connections #0 ...");
    //Serial.println(bno.testConnection() ? "MPU6050 connection #0 successful" : "MPU6050 connection #0 failed");
    delay(5);
    
    // ================= MPU: 1 =================
    digitalWrite(s0, HIGH);
    digitalWrite(s1, LOW);
    delay(5);
    /*
    Wire.begin();
    Wire.beginTransmission(MPU);
    Wire.write(0x6B);  // PWR_MGMT_1 register
    Wire.write(0);     // set to zero (wakes up the MPU-6050)
    Wire.endTransmission(true);
    */
    //delay(15);
    bno_1.begin();
    Serial.println("Testing device connections #1 ...");
    //Serial.println(bno_1.testConnection() ? "MPU6050 connection #1 successful" : "MPU6050 connection #1 failed");
    delay(5);
    
    // ================= MPU: 2 =================
    digitalWrite(s0, LOW);
    digitalWrite(s1, HIGH);
    delay(5);
    /*
    Wire.begin();
    Wire.beginTransmission(MPU);
    Wire.write(0x6B);  // PWR_MGMT_1 register
    Wire.write(0);     // set to zero (wakes up the MPU-6050)
    Wire.endTransmission(true);
    */
    //delay(15);
    bno_2.begin();
    Serial.println("Testing device connections #2 ...");
    //Serial.println(bno_2.testConnection() ? "MPU6050 connection #2 successful" : "MPU6050 connection #2 failed");
    delay(5);
    
    // ================= MPU: 3 =================
    digitalWrite(s0, HIGH);
    digitalWrite(s1, HIGH);
    delay(5);
    /*
    Wire.begin();
    Wire.beginTransmission(MPU);
    Wire.write(0x6B);  // PWR_MGMT_1 register
    Wire.write(0);     // set to zero (wakes up the MPU-6050)
    Wire.endTransmission(true);
    */
    //delay(15);
    bno_3.begin();
    Serial.println("Testing device connections #3 ...");
    //Serial.println(bno_3.testConnection() ? "MPU6050 connection #3 successful" : "MPU6050 connection #3 failed");
    delay(5);


    // configure Arduino LED for
    
    pinMode(LED_PIN, OUTPUT);
    bno_0.setExtCrystalUse(true);
    bno_1.setExtCrystalUse(true);
    bno_2.setExtCrystalUse(true);
    bno_3.setExtCrystalUse(true);
}

void loop() {

    imu::Vector<3> lacc;
    // ================= BNO: 0 =================
    digitalWrite(s0, LOW);
    digitalWrite(s1, LOW);
    delay(15);
    lacc = bno_0.getVector(Adafruit_BNO055::VECTOR_LINEARACCEL);
    Serial.print( (String) "DATA,TIME,TIMER," + lacc.x() + "," + lacc.y() + "," + lacc.z());
    
    delay(15);
    
    // ================= BNO: 1 =================
    digitalWrite(s0, HIGH);
    digitalWrite(s1, LOW);
    delay(15);
    lacc = bno_1.getVector(Adafruit_BNO055::VECTOR_LINEARACCEL);
    Serial.print( (String) "," + lacc.x() + "," + lacc.y() + "," + lacc.z());
    delay(15);

    // ================= BNO: 2 =================
    digitalWrite(s0, LOW);
    digitalWrite(s1, HIGH);
    delay(15);
    lacc = bno_2.getVector(Adafruit_BNO055::VECTOR_LINEARACCEL);
    Serial.print( (String) "," + lacc.x() + "," + lacc.y() + "," + lacc.z());
    
    delay(15);
    
    // ================= BNO: 3 =================
    digitalWrite(s0, HIGH);
    digitalWrite(s1, HIGH);
    delay(15);
    lacc = bno_3.getVector(Adafruit_BNO055::VECTOR_LINEARACCEL);
    Serial.println( (String) "," + lacc.x() + "," + lacc.y() + "," + lacc.z());
    
    delay(15);
   
    // blink LED to indicate activity
    blinkState = !blinkState;
    digitalWrite(LED_PIN, blinkState);
}

Testing1.ino (5.05 KB)

This won't work. The library doesn't know it is supposed to switch the multiplexer inputs. I did not look beyond that point.

    bno_0.setExtCrystalUse(true);
    bno_1.setExtCrystalUse(true);
    bno_2.setExtCrystalUse(true);
    bno_3.setExtCrystalUse(true);

My approach would be to use 4x$2 ebay Pro Mini clones, one for each IMU, and combine the data later.

Please don't use the I2Cdev or the FastWire library, they are not better than the normal Arduino Wire library.
Why have you included that ? Adafruit does not include that in their examples.

Use of Strings leads to memory problems and program crashes on 8-bit Arduinos.

( (String) "DATA,TIME,TIMER," + lacc.x() + "," + lacc.y() + "," + lacc.z())