Arduino 101 Curie IMU library

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

One of the most interesting feature of Arduino 101 is the possibility to use Curie IMU. The Curie IMU library enables an Arduino or Genuino 101 to read the output of the on-board IMU (Inertial Measurement Unit) containing an accelerometer and a gyroscope and elaborate the raw data coming from it. Also in this case I've used the Mgdwick filter in order to read the information coming from the device.

So let start including the curieIMU library and the Madgwick filter (you can download it from our: Download page)


                #include 
                Madgwick filter;
          

If you have specific issue configuring in your Arduino framework a library you can see here my tutorial

Now inizialize the Curie IMU library. This function must be called before any other function. Contemporary we inizialize the rate frequency of the gyro and of the accellerometer.
The data rate is also the sampling frequency and affects the bandwidth of the readings.


                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:

2 (+/- 2g)
4 (+/- 4g)
8 (+/- 8g)
16 (+/- 16g)

setGyroRange configure the angular measurement in grade per seconds. Possible values can be:

2000 (+/-2000°/s)
1000 (+/-1000°/s)
500 (+/-500°/s)
250 (+/-250°/s)
125 (+/-125°/s)

Now you need to store the data received from the IMU in the right dataset. For this, dd the following declaration line in your read function:


                
                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.
Once you have declared the right structure you can now retrieve data from IMU and store your parameters into the MagdWick filter:



                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).
Note that the formula of the function is adjusted to match the accelerometer range set with setAccelerometerRange.
The second function called 'convertRawGyro', transforms the raw data read from the gyroscope (gRaw) into a value expressed in degrees per second (°/s). Also in this case the formula is adjusted to match the gyroscope range set with setGyroRange.

once you have loaded the filter you can retrieve the data which will be already translated for you. To retrieve the right value you can use the following functions:


                    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());
            

Leave a Comment