pdf-icon

IMU

Init

Description:

Initializes 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

Description:

Sets the gyroscope sensitivity.

Syntax:

void SetGyroFsr(Gscale scale)

Parameter Corresponding 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

Description:

Sets the accelerometer sensitivity.

Syntax:

void SetAccelFsr(Ascale scale)

Parameter Corresponding 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

Description:

Reads the raw data from 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

Description:

Reads the raw data from the gyroscope.

Syntax:

void getGyroAdc(int16_t* gx, int16_t* gy, int16_t* gz)

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

Description:

Reads the temperature from the sensor.

Syntax:

void getTempAdc(int16_t *t)

Example:

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

getAccelData

Description:

Reads the values of the 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

Description:

Reads the values of the 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

Description:

Reads the temperature from 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

Description:

Reads the attitude (pitch and roll).

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

Description:

Reads the attitude (pitch, roll, and yaw).

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