AltIMU-10 v4 programming

Hi im using the altimu-10 v4 sensor to display pitch and roll on the serial monitor. I obtained an example code which reads the accelerometer and magnetometer giving raw values. I only need the accelerometer data but i am unable to understand where i should apply the mathematical formula to convert acceleration to pitch and roll and display it. Any idea guys?
Ill attach my codes.

Roll angle= [atan2(y_acceleration, sqrt(sq(x_acceleration) + sq(z_acceleration)))] * (360/2pi)

Pitch angle= [atan2(x_acceleration, sqrt(sq(y_acceleration) + sq(z_acceleration)))] * (360/2pi)


#include <Wire.h>
#include <LSM303.h>

LSM303 compass;

char report[80];

void setup()
{
Serial.begin(9600);
Wire.begin();
compass.init();
compass.enableDefault();
}

void loop()
{
compass.read();

snprintf(report, sizeof(report), "A: %6d %6d %6d M: %6d %6d %6d",
compass.a.x, compass.a.y, compass.a.z,
compass.m.x, compass.m.y, compass.m.z);
Serial.println(report);

delay(100);
}
Last edited on
Topic archived. No new replies allowed.