#define M5STACK_MPU6886 #include float accX = 0.0F; // Define variables for storing inertial sensor data float accY = 0.0F; float accZ = 0.0F; void setup(){ M5.begin(); //Init M5Core. M5.Power.begin(); //Init Power module. M5.IMU.Init(); //Init IMU sensor. M5.Lcd.setTextSize(2); //Set the font size. } void loop() { M5.IMU.getAccelData(&accX,&accY,&accZ); //Stores the triaxial accelerometer. // Accelerometer output is related M5.Lcd.setCursor(0, 120); M5.Lcd.printf("accX, accY, accZ"); M5.Lcd.setCursor(0, 140); M5.Lcd.printf("%5.2f %5.2f %5.2f G", accX, accY, accZ); static uint16_t result; static float temp; Wire.beginTransmission(0x5A); // Send Initial Signal and I2C Bus Address 发送初始信号和I2C总线地址 Wire.write(0x07); // Send data only once and add one address automatically. 只发送一次数据,并自动添加一个地址。 Wire.endTransmission(false); // Stop signal 停止信号 Wire.requestFrom(0x5A, 2); // Get 2 consecutive data from 0x5A, and the data is stored only. 从0x5A中获取2个连续的数据,并且只存储这些数据。 result = Wire.read(); // Receive DATA 接收数据 result |= Wire.read() << 8; // Receive DATA 接收数据 temp = result * 0.02 - 273.15; M5.Lcd.setCursor(20, 170); M5.Lcd.printf("Temp:%.3f",temp); delay(100); // Delay 100ms }