Arduino Nano only don't initialize all IMU sensors.

Hi

I have three sensors BNO055(Accelerometers), a multiplexer TCA9584A and an Arduino Nano connected to PC by USB.

My problem is that not always all the sensors are displaying information. At init, sometimes all but sometimes only one or two, display information trought Serial Port.

This is my code, I have atached in an image the output of the Serial Monitor.

#include "BNO055.h"
#include <Wire.h>
#include "I2CMux.h"


#define I2CMux_ADDR 0x70 
#define A 0X28  //I2C address selection pin LOW
#define B 0x28  //                          HIGH
#define C 0x28  // 



BNO055 mySensor(A);
BNO055 mySensorB(B);
BNO055 mySensorC(C);

I2CMux mux(I2CMux_ADDR);

String line;
char space = ' ';
//float sensibilidad = 0.10;

byte incomingByte = 0;   // for incoming serial data

void setup()

{
  
  Wire.begin();
  line.reserve(64);
  Serial.begin(115200);
        
    
      //INITIALIZING SENSORS

    mySensor.init();
          delay(500);
   
    mySensorB.init();
          delay(500);
  
    mySensorC.init();
          delay(500);
  
    pinMode(5, OUTPUT); // RESET BUTTON
    
  

}


void loop(){

       

  mux.switchToBus(0);

      mySensor.readQuat();
    
    
         
 
      
mux.switchToBus(1);

     mySensorB.readQuat();

         
     

     
mux.switchToBus(2);

     mySensorC.readQuat();

     
                 
         
                
          String sensorA = "SensorA:";
          String quat0 = (String)mySensor.quat.q0;
          String quat1 = (String)mySensor.quat.q1;
          String quat2 = (String)mySensor.quat.q2;
          String quat3 = (String)mySensor.quat.q3;

                 
          String sensorB= "SensorB:";
           String quat0B = (String)mySensorB.quat.q0;
          String quat1B = (String)mySensorB.quat.q1;
          String quat2B = (String)mySensorB.quat.q2;
          String quat3B = (String)mySensorB.quat.q3;

          
              String sensorC = "SensorC:";
          String quat0C = (String)mySensorC.quat.q0;
          String quat1C = (String)mySensorC.quat.q1;
          String quat2C = (String)mySensorC.quat.q2;
          String quat3C = (String)mySensorC.quat.q3;
          
         line = sensorA;
         line += space;
         line += quat0; 
         line += space;
         line += quat1; 
         line += space;
         line += quat2; 
         line += space;
         line += quat3; 
         line += space;

         line += sensorB;
         line += space;
         line += quat0B;
         line += space; 
         line += quat1B;
         line += space; 
         line += quat2B;
         line += space; 
         line += quat3B; 
         line += space; 
         
          line += sensorC;
         line += space;
         line += quat0C;
         line += space; 
         line += quat1C;
         line += space; 
         line += quat2C;
         line += space; 
         line += quat3C; 
         line += space; 

         

        
         Serial.println(line);
         Serial.flush(); 
}

Thanks everybody

BNO055 serial problem.JPG

Very bad idea to use String .

When the Arduino is connected to a PC, for a certain amount of time it is waiting for code to be uploaded to it before it will start running code.

ieee488:
Very bad idea to use String .

When the Arduino is connected to a PC, for a certain amount of time it is waiting for code to be uploaded to it before it will start running code.

Why is a bad idea? what I have to use instead? Thank you, I am a big newbie on arduino.

Btw, problem solved!

You have to switch every bus not only reading, also in initializing every sensor.

    for(int i=0; i<5;i++){
      mux.switchToBus(i);
      sensors[i].init();
    }

Thanks :slight_smile: