I am currently using a ESP-32s WROOM dev board v1.1 as a control module. I have connected this to a MPU9250/6500 as an IMU, using the following connections:
As code for the ESP-32s WROOM dev board v1.1 i have used the Arduino IDE 2.2.1 (ALKS ESP32 as board) with the following code:
#include "MPU9250.h"
// an MPU9250 object with the MPU-9250 sensor on I2C bus 0 with address 0x68
MPU9250 IMU(Wire, 0x68);
int status;
void setup() {
// serial to display data
Serial.begin(115200);
while (!Serial) {}
// start communication with IMU
status = IMU.begin();
if (status < 0) {
Serial.println("IMU initialization unsuccessful");
Serial.println("Check IMU wiring or try cycling power");
Serial.print("Status: ");
Serial.println(status);
while (1) {}
}
}
void loop() {
// read the sensor
IMU.readSensor();
// display the data
Serial.print(IMU.getAccelX_mss(), 6);
Serial.print("\t");
Serial.print(IMU.getAccelY_mss(), 6);
Serial.print("\t");
Serial.print(IMU.getAccelZ_mss(), 6);
Serial.print("\t");
Serial.print(IMU.getGyroX_rads(), 6);
Serial.print("\t");
Serial.print(IMU.getGyroY_rads(), 6);
Serial.print("\t");
Serial.print(IMU.getGyroZ_rads(), 6);
Serial.print("\t");
Serial.print(IMU.getMagX_uT(), 6);
Serial.print("\t");
Serial.print(IMU.getMagY_uT(), 6);
Serial.print("\t");
Serial.print(IMU.getMagZ_uT(), 6);
Serial.print("\t");
Serial.println(IMU.getTemperature_C(), 6);
delay(100);
}
This is code from the turtorial here using the metioned library (which I have installed). Now, when I this code is run on the ESP32, the following result is returned in the Serial Monitor:
IMU initialization unsuccessful
Check IMU wiring or try cycling power
Status: -1
This is obviously a problem, and this is why i am asking for help. Because if i understand this correctly, the ESP32 can't connect to the MPU9250/6500. (And yes i have checked the wiring is correct)
I tried the following:
- Replace all wires in the circut
- Test all the wires' conductivity
- Replace the wire from the computer to the ESP32
- Use another computer to program the ESP32
- Replace the ESP-32s WROOM dev board v1.1 with a ESP-32S WROOM dev board v1
- Replace the ESP-32s WROOM dev board v1.1 with an Arduino Uno
- Replace the MPU9250/6500
- Many different tutorials, indcluding but not limited to the following: https://www.youtube.com/watch?v=mzwovYcozvI, https://www.youtube.com/watch?v=yhz3bRQLvBY, https://www.youtube.com/watch?v=V4NdsBjUAO0, https://www.youtube.com/watch?v=dXcF-Uqa-gw
- Crying
I figured it out. So it turns out that initializing the I2C-protocol using the
Wire.begin()
, for some reason doesn't use the standard SDA- and SCL-pins. To do that you have to initialize the I2C-communication using the lineWire.begin(21, 22)
, which sets the SDA- and SCL-pins to 21 and 22. To implement this you do:in the start of the code. And the following in setup: