Use this forum to chat about hardware specific topics for the ESP8266 (peripherals, memory, clocks, JTAG, programming)

User avatar
By damire bran
#93648 Last 3 days i'v been working on esp01 and mpu9250, tried so much libraries, library changes, code changes, at the point that i come, while imu connected to pin 0 and 2 with basic codes like getting acc, gyr and mag values with dmp, it cant gets mag values. (with out dmp you can get mag values at lower hz).

Let me explain with an example:
Code: Select all#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:
Image
Image
Image
Image
Image
Last edited by damire bran on Tue Feb 15, 2022 3:30 pm, edited 1 time in total.
User avatar
By oswe
#93997 yep,
not everything functions under the core arduino prepared for esp8266.
i had problems with oled ssd1306 and solved it by hand implementing the handshake directly from wire.h
read the datasheet from mpu and try to initialize the very beginning see if you can get a response by your own.