MPU

Init()

Function:

Initialize the attitude sensor.

Syntax:

int Init()

Example:

#include "M5Atom.h"
void setup(){
    M5.begin(true, true, true); //Clear the serial buffer, set the serial baud rate to 115200; initialize I2C; initialize the LED matrix
}

SetGyroFsr()

Function:

Set the sensitivity of the gyroscope

Syntax:

void SetGyroFsr(Gscale scale)

parameter value
GFS_250DPS 0
GFS_500DPS 1
GFS_1000DPS 2
GFS_2000DPS 3

Example:

#include <M5Atom.h>

void setup(){
  M5.begin(true, false, true);
  M5.IMU.Init();
}

void loop(){
  M5.IMU.SetGyroFsr(M5.IMU.GFS_2000DPS);
  delay(100);
}

SetAccelFsr()

Function:

Set accelerometer sensitivity

Syntax:

void SetAccelFsr(Ascale scale)

parameter value
AFS_2G 0
AFS_4G 1
AFS_8G 2
AFS_16G 3

Example:

#include <M5Atom.h>

void setup(){
  M5.begin(true, false, true);
  M5.IMU.Init();
}

void loop(){
  M5.IMU.SetAccelFsr(M5.IMU.AFS_2G);
  delay(100);
}

getAccelAdc()

Function:

Read the raw data of the accelerometer.

Syntax:

void getAccelAdc(int16_t* ax, int16_t* ay, int16_t* az)

Example:

#include "M5Atom.h"

void setup(){
  M5.begin(true, false, true);
  M5.IMU.Init();
}

int16_t x,y,z;

void loop(){
  M5.IMU.getAccelAdc(&x,&y,&z);
  Serial.printf("Ax:%d Ay:%d Az:%d/n",x ,y,z);
  delay(100);
}

getGyroAdc()

Function:

Read the raw data of the Gyro.

Syntax:

void getGyroAdc(int16_t* ax, int16_t* ay, int16_t* az)

Example:

#include "M5Atom.h"

void setup(){
  M5.begin(true, false, true);
  M5.IMU.Init();
}

int16_t x,y,z;

void loop(){
  M5.IMU.getGyroAdc(&x,&y,&z);
  Serial.printf("Gx:%d Gy:%d Gz:%d/n",x ,y,z);
  delay(100);
}

getTempAdc()

Function:

Read the status of the button.

Syntax:

void getTempAdc(int16_t *t)

Example:

void M5Atom::update()
{
    M5.Btn.read();
}

getAccelData()

Function:

Read the value of a three-axis accelerometer.

Syntax:

void getAccelData(float* ax, float* ay, float* az)

Example:

#include "M5Atom.h"

void setup(){
  M5.begin(true, false, true);
  M5.IMU.Init();
}

float accX = 0.0F;
float accY = 0.0F;
float accZ = 0.0F;

void loop(){
  M5.IMU.getAccelData(&accX,&accY,&accZ);
  Serial.printf("accX,   accY,  accZ/n");
  Serial.printf("%5.2f  %5.2f  %5.2f G/n", accX, accY, accZ);
  delay(100);
}

getGyroData()

Function:

Read the value of a three-axis gyroscope.

Syntax:

void getGyroData(float* gx, float* gy, float* gz)

Example:

#include "M5Atom.h"

void setup(){
  M5.begin(true, false, true);
  M5.IMU.Init();
}

float gyroX = 0.0F;
float gyroY = 0.0F;
float gyroZ = 0.0F;

void loop(){
  M5.IMU.getGyroData(&gyroX,&gyroY,&gyroZ);
  Serial.printf("gyroX,  gyroY, gyroZ/n");
  Serial.printf("%6.2f %6.2f%6.2f o/s/n", gyroX, gyroY, gyroZ);
  delay(100);
}

getTempData()

Function:

Read the temperature of the sensor

Syntax:

void getTempData(float *t)

Example:

#include "M5Atom.h"

void setup(){
  M5.begin(true, false, true);
  M5.IMU.Init();
}

float temp = 0.0F;

void loop(){
  M5.IMU.getTempData(&temp);
  Serial.printf("Temperature : %.2f C/n", temp);
  delay(100);
}

getAttitude()

Function:

Read posture.

Syntax:

void getAttitude(double *pitch, double *roll)

Example:

#include "M5Atom.h"

void setup(){
  M5.begin(true, false, true);
  M5.IMU.Init();
}

double pitch, roll;
double r_rand = 180 / PI;

void loop(){
  M5.IMU.getAttitude(&pitch, &roll);
  double arc = atan2(pitch, roll) * r_rand + 180;
  double val = sqrt(pitch * pitch + roll * roll);
  Serial.printf("%.2f, %.2f, %.2f, %.2f/n", pitch, roll, arc, val);  //serial port output the formatted string
  delay(100);
}

getAhrsData()

Function:

Read posture

Syntax:

void getAhrsData(float *pitch,float *roll,float *yaw)

Example:

#include "M5Atom.h"

float pitch, roll, yaw; //Stores attitude related variables.  存储姿态相关变量

void setup(){
  M5.begin(true, false, true);
  M5.IMU.Init();
}

void loop(){
  M5.IMU.getAhrsData(&pitch,&roll,&yaw);
  Serial.printf("pitch:%.2f, roll:%.2f, yaw:%.2f", pitch,roll,yaw);
  delay(100);
}
On This Page