Hello community,
I've been trying to connect a TCA9548A multiplexer with multiple MPU920 sensors using I2C but I've been getting some errors trying to compile the code. I'm just trying to read the data of the sensors checking every channel of the multiplexer.
Here is the code:
#include "Wire.h"
#include "MPU9250.h"
#define TCAADDR 0x70
MPU9250 IMU(Wire,0x68);
int status
void tcaselect(uint8_t i) { //Change multiplexer channel
if (i > 7) return;
Wire.beginTransmission(TCAADDR);
Wire.write(1 << i);
Wire.endTransmission();
}
void setup() {
//INITIALIZE SERIAL MONITOR
Serial.begin(115200);
while(!Serial){}
//INITIALIZE COMMUNICATION
for (int x=0; x<=7; x++){ //Check status of every IMU connected in each channel
tcaselect(x);
status = IMU.begin
if (status < 0) {
Serial.println("IMU initialization unsuccessful");
Serial.println("Check IMU wiring");
Serial.print("Status: ");
Serial.println(status);
while(1) {}
}
}
}
void loop() {
for (int y=0; y<=7; y++){ //Read data of every IMU connected in each channel
tcaseselect(y)
IMU.readSensor();
Serial.print("Data IMU channel ");
Serial.print(y);
Serial.print(" :");
Serial.print("\t");
Serial.print("AccelX: ");
Serial.print(IMU.getAccelX_mss(),6);
Serial.print("\t");
Serial.print("AccelY: ");
Serial.print(IMU.getAccelY_mss(),6);
Serial.print("\t");
Serial.print("AccelX: ");
Serial.print(IMU.getAccelZ_mss(),6);
Serial.print("\t");
Serial.print("GyroX: ");
Serial.print(IMU.getGyroX_rads(),6);
Serial.print("\t");
Serial.print("GyroY: ");
Serial.print(IMU.getGyroY_rads(),6);
Serial.print("\t");
Serial.print("GyroZ: ");
Serial.print(IMU.getGyroZ_rads(),6);
}
}
The error messages I get while trying to compile are:
Test_MULTIPLEXER:4:16: error: expected initializer before 'tcaselect'
MPU9250 IMU(Wire,0x68);
^~~~~~~~
Test_MULTIPLEXER:7:1: error: expected initializer before 'void'
void tcaselect(uint8_t i) { //Change multiplexer channel
^~~~
C:\Users\User\Documents\Arduino\Test_MULTIPLEXER\Test_MULTIPLEXER.ino: In function 'void setup()':
Test_MULTIPLEXER:22:7: error: 'tcaselect' was not declared in this scope
tcaselect(x);
^~~~~~~~~
Test_MULTIPLEXER:23:7: error: 'status' was not declared in this scope
status = IMU.begin
^~~~~~
C:\Users\User\Documents\Arduino\Test_MULTIPLEXER\Test_MULTIPLEXER.ino:23:7: note: suggested alternative: 'static'
status = IMU.begin
^~~~~~
static
C:\Users\User\Documents\Arduino\Test_MULTIPLEXER\Test_MULTIPLEXER.ino: In function 'void loop()':
Test_MULTIPLEXER:38:7: error: 'tcaseselect' was not declared in this scope
tcaseselect(y)
^~~~~~~~~~~
Multiple libraries were found for "MPU9250.h"
Used: C:\Users\User\Documents\Arduino\libraries\MPU9250-master
Not used: C:\Users\User\Documents\Arduino\libraries\Bolder_Flight_Systems_MPU9250
Not used: C:\Users\User\Arduino\libraries\IMU
exit status 1
expected initializer before 'tcaselect'