You should be able to hold the sensor flat and still, record the number on the axis with the largest magnitude, and then divide each axis with that number after getting the readings. Now you'll have all the readings normalized to gravity, so just multiply the readings by 9.8 after dividing them.
The value I recorded was -261.0 on the z-axis, so I'll divide each axis by its magnitude and then multiply by 9.8
#include <Wire.h>
#include "BMA250.h"
BMA250 accel_sensor;
int x, y, z;
#if defined(ARDUINO_ARCH_SAMD)
#define SerialMonitorInterface SerialUSB
#else
#define SerialMonitorInterface Serial
#endif
void setup() {
SerialMonitorInterface.begin(115200);
Wire.begin();
SerialMonitorInterface.print("Initializing BMA...");
// Set up the BMA250 acccelerometer sensor
accel_sensor.begin(BMA250_range_2g, BMA250_update_time_64ms);
}
void loop() {
accel_sensor.read();//This function gets new data from the acccelerometer
// Get the acceleration values from the sensor and store them into global variables
// (Makes reading the rest of the program easier)
x = accel_sensor.X;
y = accel_sensor.Y;
z = accel_sensor.Z;
if (x == -1 && y == -1 && z == -1) {
SerialMonitorInterface.print("ERROR! NO BMA250 DETECTED!");
}
else {
showSerial();
}
delay(250);
}
void showSerial() {
SerialMonitorInterface.print("X = ");
SerialMonitorInterface.print((x / 261.0f) * 9.8f);
SerialMonitorInterface.print(" Y = ");
SerialMonitorInterface.print((y / 261.0f) * 9.8f);
SerialMonitorInterface.print(" Z = ");
SerialMonitorInterface.println((z / 261.0f) * 9.8f);
}
You could simplify the conversion math by combining the constant values: 9.8/261.0 = 0.0375. Now I can convert each axis this way:
void showSerial() {
SerialMonitorInterface.print("X = ");
SerialMonitorInterface.print(x * 0.0375f);
SerialMonitorInterface.print(" Y = ");
SerialMonitorInterface.print(y * 0.0375f);
SerialMonitorInterface.print(" Z = ");
SerialMonitorInterface.println(z * 0.0375f);
}