IMU

Init

Functionality:

Initializes the attitude sensor.

Function Prototype:

int Init()

Usage 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

Functionality:

Sets the gyroscope sensitivity.

Function Prototype:

void SetGyroFsr(Gscale scale)

Parameter Corresponding Value
GFS_250DPS 0
GFS_500DPS 1
GFS_1000DPS 2
GFS_2000DPS 3

Usage 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

Functionality:

Sets the accelerometer sensitivity.

Function Prototype:

void SetAccelFsr(Ascale scale)

Parameter Corresponding Value
AFS_2G 0
AFS_4G 1
AFS_8G 2
AFS_16G 3

Usage 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

Functionality:

Reads the raw data from the accelerometer.

Function Prototype:

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

Usage 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

Functionality:

Reads the raw data from the gyroscope.

Function Prototype:

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

Usage 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

Functionality:

Reads the temperature from the sensor.

Function Prototype:

void getTempAdc(int16_t *t)

Usage Example:

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

getAccelData

Functionality:

Reads the values of the three-axis accelerometer.

Function Prototype:

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

Usage 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

Functionality:

Reads the values of the three-axis gyroscope.

Function Prototype:

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

Usage 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

Functionality:

Reads the temperature from the sensor.

Function Prototype:

void getTempData(float *t)

Usage 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

Functionality:

Reads the attitude (pitch and roll).

Function Prototype:

void getAttitude(double *pitch, double *roll)

Usage 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

Functionality:

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

Function Prototype:

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

Usage 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