How to get an IMU MPU6886 work at M5Paper?



  • I tried to get an M5 Stack MPU6886 to work on my M5Paper Unit. But without success.

    What did I do?

    Connected the IMU MPU6886 to Port A.

    modified the example Code from M5 to the following

    #include <M5EPD.h>
    #include "time.h"
    
    #ifdef __cplusplus
    extern "C"
    {
      #include "IMU_6886.h"
    }
    #endif
    
    IMU_6886 imu6886;
    
    float accX = 0;
    float accY = 0;
    float accZ = 0;
    
    float gyroX = 0;
    float gyroY = 0;
    float gyroZ = 0;
    
    char string_buff[40];
    
    float temp = 0;
    
    void setup() {
      // put your setup code here, to run once:
      M5.begin();
      imu6886.Init(25, 32);
    
      
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
      imu6886.getGyroData(&gyroX,&gyroY,&gyroZ);
      Serial.print("gyroX: ");
      Serial.println(gyroX);
      imu6886.getAccelData(&accX,&accY,&accZ);
      Serial.print("accX: ");
      Serial.println(accX);
      imu6886.getTempData(&temp);
      Serial.print("Temp: ");
      Serial.println(temp);
      delay(1000);
    }
    

    At the first line I changed M5EPD.h instead of M5Stack.h and changed I2C Port to 25/32

    The same within IMU_6886.cpp .

    Comparing M5EPD.h to M5Stack.h, the M5EPD has no I2C Class Reference to CommUtil .
    So I added these two lines into M5EPD.h together with an #include "utility/CommUtil.h" at the beginning of the code.

        Button BtnR = Button(M5EPD_KEY_RIGHT_PIN, true, 10);
    
        // I2C
        CommUtil I2C = CommUtil();
    
        M5EPD_Driver EPD = M5EPD_Driver();
    

    CommUtil.h and CommUtil.cpp I copied from M5Stack/src/utility to the corresponding path of M5EPD.
    Within CommUtil.cpp I changed the include also to ../M5EPD.h".

    After doing these steps the Compiling process ends without any errors and I can upload the sketch to the unit.

    Looking at the serial monitor it does not display any valid values. Only 25 Temperature but it's not changing and the other values are zero.

    Doeas anyone have an example code for IMU6886 running together with M5 Paper or can give me some hints to get the example code for m5Stack working on M5Paper?

    Regards Herb



  • I switched over to this library https://github.com/tanakamasayuki/I2C_MPU6886

    There is no modification of the EPD Library necessary. Now it works with there example code.