Let me explain with an example:
#include <SparkFunMPU9250-DMP.h>
//#include <Wire.h>
#define SerialPort Serial
MPU9250_DMP imu;
void setup()
{
delay(2000);
SerialPort.begin(115200);
// Wire.begin(2, 0);
// Wire.setClock(400000);
if (imu.begin() != INV_SUCCESS)
{
while (1)
{
SerialPort.println("Unable to communicate with MPU-9250");
SerialPort.println("Check connections, and try again.");
SerialPort.println();
delay(5000);
}
}
imu.setSensors(INV_XYZ_GYRO | INV_XYZ_ACCEL | INV_XYZ_COMPASS);
SerialPort.println("o- sensors turned on.");
delay(50);
imu.setGyroFSR(2000); // Set gyro to 2000 dps
imu.setAccelFSR(2); // Set accel to +/-2g
imu.setLPF(5); // Set LPF corner frequency to 5Hz
imu.setSampleRate(100); // Set sample rate to 10Hz
SerialPort.println("o- sample rate set.");
delay(50);
imu.setCompassSampleRate(100); // Set mag rate to 10Hz
SerialPort.println("o- compass sample rate set.");
delay(50);
}
void loop()
{
delay(100);
if ( imu.dataReady() )
{
imu.update(UPDATE_ACCEL | UPDATE_GYRO | UPDATE_COMPASS);
printIMUData();
}
}
void printIMUData(void)
{
float accelX = imu.calcAccel(imu.ax);
float accelY = imu.calcAccel(imu.ay);
float accelZ = imu.calcAccel(imu.az);
float gyroX = imu.calcGyro(imu.gx);
float gyroY = imu.calcGyro(imu.gy);
float gyroZ = imu.calcGyro(imu.gz);
float magX = imu.calcMag(imu.mx);
float magY = imu.calcMag(imu.my);
float magZ = imu.calcMag(imu.mz);
SerialPort.println("Accel: " + String(accelX) + ", " +
String(accelY) + ", " + String(accelZ) + " g");
SerialPort.println("Gyro: " + String(gyroX) + ", " +
String(gyroY) + ", " + String(gyroZ) + " dps");
SerialPort.println("Mag: " + String(magX) + ", " +
String(magY) + ", " + String(magZ) + " uT");
SerialPort.println("Time: " + String(imu.time) + " ms");
SerialPort.println();
}
In this code if we use it with arduino uno it works perfectly, when it comes to esp01, i added that wire library and wire begin lines to select pin 0 and 2 because esp01 doesnt have 4 and 5 on board by default, it gives output of acc and gyro but seems like cant connect to mag (MPU9250 (or MPU6500 w/ AK8963 on the auxiliary bus) to that) gives output all zeroes.
Like i said i tried so much different libraries (not only me i asked to people that knows to software that tried to help much didnt worked out), its not because of 9250's libs i think, its something wrong with esp01's libs on platformio or arduino (tried both).
Things i've tried:
- - changing esp01
- changing mpu 9250
- it works with 2 mpu6250 on same pin connection while same time with different mpu adresses.
- it works with 9250 while its on 6500 mode (mag disabled)
- it works on arduino versions same library and same code
- it works on esp01's different pins that i soldered on board (pics and description below (a))
- it works to get all values without dmp to write them to serial print (but cmon it works dmp on different pins, different mpus and with same libs)
- HAS TO BE something wrong with esp01's desing or library for arduino framework (if it is who should I contact for this problem?)
((a): also tried to solder wire esp01's chip's gpio pin 4 and 5 and connected that mpu9250 with same code and libs and it worked.)
Wiring schematic, serial logs, connection pictures included: