AltIMU-10 v4 with arduino

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)

Serial.Accelerometer.ino (1.92 KB)

If pitch and roll are the angles with reference to the horizontal/vertical (i’m not sure), the issue is as follows:

Chip measures the acceleration in the trhee axis.

If the chip is not exactly upwards position acceleration (say “gravity” in the axis direction) in X axis and/or Y axis are not zero, and they are proportional to the (sine of the) angle that the axis makes to the initial position.

By applying trigonometrics the formula you are using derives.

Best regards