Hello,
I am trying to use an M5StickC plus with a hat sensor (TOF), a grove sensor (TOF), and the internal IMU. Using the code below I’m able to get data from both the Hat and Grove sensors running using Wire1. However, the IMU no longer functions with the Wire1.begin call as written.
I’m new to Arduino. Is there a better way to get both Hat and Grove working simultaneously that avoids the need for Wire1? Any ideas on how to get this trio of sensors up and running?
FWIW I had originally prototyped this in micropython and had all three sensors working; latency was killer however and arduino is much much faster (like > 10x).
Thx, PD
#include <VL53L0X.h>
#include <Wire.h>
#include <M5StickCPlus.h>
VL53L0X sensor;
VL53L0X sensor2;
void setup() {
Wire.begin(0, 26, 100000UL); // for I2C of HAT connection
Wire1.begin(32, 33, 100000UL); // for I2C of grove connection
M5.begin(); // starts serial 115200
sensor.setTimeout(500);
while (!sensor.init()) {
Serial.println("Failed to detect and initialize sensor!");
delay(250);
}
sensor.startContinuous();
sensor2.setBus(&Wire1);
sensor2.setTimeout(500);
while (!sensor2.init()) {
Serial.println("Failed to detect and initialize sensor2!");
delay(250);
}
sensor2.startContinuous();
delay(100);
int IMUinit = M5.IMU.Init();
Serial.print("IMU init return val: ");
Serial.print(IMUinit); // <- -1 means it's not working..
Serial.println();
}
void loop() {
uint16_t distance1 = sensor.readRangeContinuousMillimeters();
uint16_t distance2 = sensor2.readRangeContinuousMillimeters();
Serial.print(distance1);
Serial.print(" ");
Serial.print(distance2);
if (sensor2.timeoutOccurred()) {
Serial.print(" TIMEOUT");
}
Serial.println();
}