This page describes how to use the curie IMU accellerometer sensor built into Arduino 101
If you need additional specific information about this topic or if you want to look it personally please write an email
#include
Madgwick filter;
If you have specific issue configuring in your Arduino framework a library you can see here my tutorial
CurieIMU.begin();
CurieIMU.setGyroRate(25);
CurieIMU.setAccelerometerRate(25);
CurieIMU.setAccelerometerRange(2);
CurieIMU.setGyroRange(250);
Note that the last two functions are configuring the Accellerometer range. It is a value multiple of g (Gravity force). Possible values can be:
int aix, aiy, aiz;
int gix, giy, giz;
float ax, ay, az;
float gx, gy, gz;
A value will be used to store accellerometer values and G values to store Gyroscope ones.
CurieIMU.readMotionSensor(aix, aiy, aiz, gix, giy, giz);
// convert from raw data to gravity and degrees/second units
ax = convertRawAcceleration(aix);
ay = convertRawAcceleration(aiy);
az = convertRawAcceleration(aiz);
gx = convertRawGyro(gix);
gy = convertRawGyro(giy);
gz = convertRawGyro(giz);
// update the filter, which computes orientation
filter.updateIMU(gx, gy, gz, ax, ay, az);
where the two conversion functions are:
float convertRawAcceleration(int aRaw) {
// since we are using 2G range
// -2g maps to a raw value of -32768
// +2g maps to a raw value of 32767
float a = (aRaw * 2.0) / 32768.0;
return a;
}
float convertRawGyro(int gRaw) {
// since we are using 250 degrees/seconds range
// -250 maps to a raw value of -32768
// +250 maps to a raw value of 32767
float g = (gRaw * 250.0) / 32768.0;
return g;
}
The first function called 'convertRawAcceleration', transforms the raw data read from the accelerometer (aRaw) into a value expressed in mg (thousandths of g).
Yaw: %.2lf filter.getYaw()
Pitch: %.2lf filter.getPitch()
Roll: %.2lf filter.getRoll())
To support you better I have already entered the %value used in C to writ this value into a string. so if you want to write this value into a string you will be able to use the classic
sprintf function. So, for example if you want to print the Yaw value into an array of char (simply to display it in your oled screen) you will need to format the string in this way:
sprintf(StringToOled,"%.2lf", filter.getYaw());