I’m having problems developing a sketch so that I may grab data using the following:
I have successfully logged data using the following setups:
My problems arise when I attempt to add the two IMUs to the I2C Mux Breakout. I’ve made multiple attempts to solve the errors on my own, but I’m currently at a standstill and not sure what to do next.
The code from my most recent attempt:
#include <Wire.h>
#include <SparkFun_I2C_Mux_Arduino_Library.h>
#include "SparkFun_VL53L1X.h"
#include "SparkFun_ISM330DHCX.h"
QWIICMUX myMux;
SFEVL53L1X **distanceSensor;
SparkFun_ISM330DHCX myISM;
// Structs for X,Y,Z data
sfe_ism_data_t accelData;
sfe_ism_data_t gyroData;
#define MUX_ADDR 0x70 //7-bit unshifted default I2C Address
#define NUMBER_OF_SENSORS 4
#define NUMBER_OF_TOF_SENSORS 2
#define NUMBER_OF_IMU_SENSORS 2
void setup()
{
Serial.begin(115200);
Serial.println("Double ToF and IMU v03 Setup");
Wire.begin();
//Create set of pointers to the ToF class
distanceSensor = new SFEVL53L1X *[NUMBER_OF_TOF_SENSORS];
//Assign pointers to instances of the ToF class
for (int x = 0; x < NUMBER_OF_TOF_SENSORS; x++)
distanceSensor[x] = new SFEVL53L1X(Wire);
if (myMux.begin() == false)
{
Serial.println("Mux not detected. Freezing...");
while (1)
;
}
Serial.println("Mux detected");
byte currentPortNumber = myMux.getPort();
Serial.print("CurrentPort: ");
Serial.println(currentPortNumber);
//Create set of pointers to the IMU class
myISM = new SparkFun_ISM330DHCX *[NUMBER_OF_IMU_SENSORS];
//Assign pointers to instances of the IMU class
for (int x = 2; x < NUMBER_OF_IMU_SENSORS; x++)
myISM[x] = new SparkFun_ISM330DHCX(Wire);
if (myMux.begin() == false)
{
Serial.println("Mux not detected. Freezing...");
while (1)
;
}
Serial.println("Mux detected");
byte currentPortNumber = myMux.getPort();
Serial.print("CurrentPort: ");
Serial.println(currentPortNumber);
//Initialize all the sensors
bool initSuccess = true;
for (byte x = 0; x < NUMBER_OF_TOF_SENSORS; x++)
{
myMux.setPort(x);
if (distanceSensor[x]->begin() != 0) //Begin returns 0 on a good init
{
Serial.print("Sensor ");
Serial.print(x);
Serial.println(" did not begin! Check wiring");
initSuccess = false;
}
else
{
//Configure each sensor
distanceSensor[x]->setIntermeasurementPeriod(1000);
distanceSensor[x]->setDistanceModeShort();
distanceSensor[x]->startRanging(); //Write configuration bytes to initiate measurement
Serial.print("Sensor ");
Serial.print(x);
Serial.println(" configured");
}
}
for (byte x = 2; x < NUMBER_OF_IMU_SENSORS; x++)
{
myMux.setPort(x);
if (myISM[x]->begin() != 0) //Begin returns 0 on a good init
{
Serial.print("Sensor ");
Serial.print(x);
Serial.println(" did not begin! Check wiring");
initSuccess = false;
}
else
{
//Configure each sensor
myISM.setDeviceConfig();
myISM.setBlockDataUpdate();
// Set the output data rate and precision of the accelerometer
myISM.setAccelDataRate(ISM_XL_ODR_416Hz);
myISM.setAccelFullScale(ISM_2g);
// Set the output data rate and precision of the gyroscope
myISM.setGyroDataRate(ISM_GY_ODR_416Hz);
myISM.setGyroFullScale(ISM_125dps);
// Turn on the accelerometer's filter and apply settings.
myISM.setAccelFilterLP2();
myISM.setAccelSlopeFilter(ISM_LP_ODR_DIV_100);
// Turn on the gyroscope's filter and apply settings.
myISM.setGyroFilterLP1();
myISM.setGyroLP1Bandwidth(ISM_XTREME);
Serial.print("Sensor ");
Serial.print(x);
Serial.println(" configured");
}
}
if (initSuccess == false)
{
Serial.print("Freezing...");
while (1)
;
}
Serial.println("Mux Shield online");
}
void loop()
{
for (byte x = 0 ; x < NUMBER_OF_SENSORS ; x++)
{
enableMuxPort(x); //Tell mux to connect to this port, and this port only
if (accel.available())
{
accel.read();
Serial.print("Accel ");
Serial.print(x);
Serial.print(": ");
Serial.print(accel.cx, 2);
Serial.print(" ");
Serial.print(accel.cy, 2);
Serial.print(" ");
Serial.print(accel.cz, 2);
Serial.print(" ");
Serial.println(); // Print new line every time.
}
else myISM.checkStatus();
{
myISM.getAccel(&accelData);
myISM.getGyro(&gyroData);
Serial.print("Accelerometer: ");
Serial.print("X: ");
Serial.print(accelData.xData);
Serial.print(" ");
Serial.print("Y: ");
Serial.print(accelData.yData);
Serial.print(" ");
Serial.print("Z: ");
Serial.print(accelData.zData);
Serial.println(" ");
Serial.print("Gyroscope: ");
Serial.print("X: ");
Serial.print(gyroData.xData);
Serial.print(" ");
Serial.print("Y: ");
Serial.print(gyroData.yData);
Serial.print(" ");
Serial.print("Z: ");
Serial.print(gyroData.zData);
Serial.println(" ");
}
disableMuxPort(x); //Tell mux to disconnect from this port
}
delay(1000); //Wait for next reading
}
I get the following output when I attempt to verify.
The full error as follows:Compilation error: no match for ‘operator=’ (operand types are ‘SparkFun_ISM330DHCX’ and ‘SparkFun_ISM330DHCX**’)
C:\Users\IMG\Documents\Arduino\Customized Arduino Code\Double_ToF_IMU_v03\Double_ToF_IMU_v03.ino: In function ‘void setup()’:
C:\Users\IMG\Documents\Arduino\Customized Arduino Code\Double_ToF_IMU_v03\Double_ToF_IMU_v03.ino:46:58: error: no match for ‘operator=’ (operand types are ‘SparkFun_ISM330DHCX’ and ‘SparkFun_ISM330DHCX**’)
myISM = new SparkFun_ISM330DHCX *[NUMBER_OF_IMU_SENSORS];
^
In file included from C:\Users\IMG\Documents\Arduino\Customized Arduino Code\Double_ToF_IMU_v03\Double_ToF_IMU_v03.ino:4:
c:\Users\IMG\Documents\Arduino\libraries\SparkFun_6DoF_ISM330DHCX\src/SparkFun_ISM330DHCX.h:7:7: note: candidate: ‘SparkFun_ISM330DHCX& SparkFun_ISM330DHCX::operator=(const SparkFun_ISM330DHCX&)’
class SparkFun_ISM330DHCX : public QwDevISM330DHCX
^~~~~~~~~~~~~~~~~~~
c:\Users\IMG\Documents\Arduino\libraries\SparkFun_6DoF_ISM330DHCX\src/SparkFun_ISM330DHCX.h:7:7: note: no known conversion for argument 1 from ‘SparkFun_ISM330DHCX**’ to ‘const SparkFun_ISM330DHCX&’
c:\Users\IMG\Documents\Arduino\libraries\SparkFun_6DoF_ISM330DHCX\src/SparkFun_ISM330DHCX.h:7:7: note: candidate: ‘SparkFun_ISM330DHCX& SparkFun_ISM330DHCX::operator=(SparkFun_ISM330DHCX&&)’
c:\Users\IMG\Documents\Arduino\libraries\SparkFun_6DoF_ISM330DHCX\src/SparkFun_ISM330DHCX.h:7:7: note: no known conversion for argument 1 from ‘SparkFun_ISM330DHCX**’ to ‘SparkFun_ISM330DHCX&&’
C:\Users\IMG\Documents\Arduino\Customized Arduino Code\Double_ToF_IMU_v03\Double_ToF_IMU_v03.ino:50:10: error: no match for ‘operator’ (operand types are ‘SparkFun_ISM330DHCX’ and ‘int’)
myISM = new SparkFun_ISM330DHCX(Wire);
^
C:\Users\IMG\Documents\Arduino\Customized Arduino Code\Double_ToF_IMU_v03\Double_ToF_IMU_v03.ino:50:44: error: no matching function for call to ‘SparkFun_ISM330DHCX::SparkFun_ISM330DHCX(TwoWire&)’
myISM = new SparkFun_ISM330DHCX(Wire);
^
In file included from C:\Users\IMG\Documents\Arduino\Customized Arduino Code\Double_ToF_IMU_v03\Double_ToF_IMU_v03.ino:4:
c:\Users\IMG\Documents\Arduino\libraries\SparkFun_6DoF_ISM330DHCX\src/SparkFun_ISM330DHCX.h:12:3: note: candidate: ‘SparkFun_ISM330DHCX::SparkFun_ISM330DHCX()’
SparkFun_ISM330DHCX() {};
^~~~~~~~~~~~~~~~~~~
c:\Users\IMG\Documents\Arduino\libraries\SparkFun_6DoF_ISM330DHCX\src/SparkFun_ISM330DHCX.h:12:3: note: candidate expects 0 arguments, 1 provided
c:\Users\IMG\Documents\Arduino\libraries\SparkFun_6DoF_ISM330DHCX\src/SparkFun_ISM330DHCX.h:7:7: note: candidate: ‘constexpr SparkFun_ISM330DHCX::SparkFun_ISM330DHCX(const SparkFun_ISM330DHCX&)’
class SparkFun_ISM330DHCX : public QwDevISM330DHCX
^~~~~~~~~~~~~~~~~~~
c:\Users\IMG\Documents\Arduino\libraries\SparkFun_6DoF_ISM330DHCX\src/SparkFun_ISM330DHCX.h:7:7: note: no known conversion for argument 1 from ‘TwoWire’ to ‘const SparkFun_ISM330DHCX&’
c:\Users\IMG\Documents\Arduino\libraries\SparkFun_6DoF_ISM330DHCX\src/SparkFun_ISM330DHCX.h:7:7: note: candidate: ‘constexpr SparkFun_ISM330DHCX::SparkFun_ISM330DHCX(SparkFun_ISM330DHCX&&)’
c:\Users\IMG\Documents\Arduino\libraries\SparkFun_6DoF_ISM330DHCX\src/SparkFun_ISM330DHCX.h:7:7: note: no known conversion for argument 1 from ‘TwoWire’ to ‘SparkFun_ISM330DHCX&&’
C:\Users\IMG\Documents\Arduino\Customized Arduino Code\Double_ToF_IMU_v03\Double_ToF_IMU_v03.ino:60:8: error: redeclaration of ‘byte currentPortNumber’
byte currentPortNumber = myMux.getPort();
^~~~~~~~~~~~~~~~~
C:\Users\IMG\Documents\Arduino\Customized Arduino Code\Double_ToF_IMU_v03\Double_ToF_IMU_v03.ino:41:8: note: ‘byte currentPortNumber’ previously declared here
byte currentPortNumber = myMux.getPort();
^~~~~~~~~~~~~~~~~
C:\Users\IMG\Documents\Arduino\Customized Arduino Code\Double_ToF_IMU_v03\Double_ToF_IMU_v03.ino:92:14: error: no match for ‘operator’ (operand types are ‘SparkFun_ISM330DHCX’ and ‘byte’ {aka ‘unsigned char’})
if (myISM->begin() != 0) //Begin returns 0 on a good init
^
C:\Users\IMG\Documents\Arduino\Customized Arduino Code\Double_ToF_IMU_v03\Double_ToF_IMU_v03.ino: In function ‘void loop()’:
C:\Users\IMG\Documents\Arduino\Customized Arduino Code\Double_ToF_IMU_v03\Double_ToF_IMU_v03.ino:141:5: error: ‘enableMuxPort’ was not declared in this scope
enableMuxPort(x); //Tell mux to connect to this port, and this port only
^~~~~~~~~~~~~
C:\Users\IMG\Documents\Arduino\Customized Arduino Code\Double_ToF_IMU_v03\Double_ToF_IMU_v03.ino:143:9: error: ‘accel’ was not declared in this scope
if (accel.available())
^~~~~
C:\Users\IMG\Documents\Arduino\Customized Arduino Code\Double_ToF_IMU_v03\Double_ToF_IMU_v03.ino:143:9: note: suggested alternative: ‘access’
if (accel.available())
^~~~~
access
C:\Users\IMG\Documents\Arduino\Customized Arduino Code\Double_ToF_IMU_v03\Double_ToF_IMU_v03.ino:185:5: error: ‘disableMuxPort’ was not declared in this scope
disableMuxPort(x); //Tell mux to disconnect from this port
^~~~~~~~~~~~~~
C:\Users\IMG\Documents\Arduino\Customized Arduino Code\Double_ToF_IMU_v03\Double_ToF_IMU_v03.ino:185:5: note: suggested alternative: ‘disableLoopWDT’
disableMuxPort(x); //Tell mux to disconnect from this port
^~~~~~~~~~~~~~
disableLoopWDT
exit status 1
Compilation error: no match for ‘operator=’ (operand types are ‘SparkFun_ISM330DHCX’ and ‘SparkFun_ISM330DHCX**’)
I also attempt to use run the two IMUs with the I2C Mux Breakout but failed in that attempt as well.
My next step is to review additional tutorials on writing Arduino sketches, but I’d appreciate any direction on how to correct my mistake(s) in the meantime.