A decade ago, 2D and 3D accelerometers were commonly used in devices to provide the direction, speed, and GPS localization of an object. An accelerometer is an electronic sensor that measures the acceleration forces acting on an object, typically to determine its position in space and monitor the object’s movement.
Since then, the 3D field has advanced considerably. For example, it’s now possible for such a device to not only assess the acceleration forces acting on an object but also of any objects near it (think of autonomous cars, which must take traffic lights, nearby buildings, other vehicles, and pedestrians into account).
What’s referred to as “nine degrees of freedom,” or 9DoF, now combines 3D acceleration with a 3D gyroscope and magnetometer readings — providing accurate readings of an object’s precise position in 3D space.
In this tutorial, we’ll learn how to interface a SparkFun 9DoF sensor stick with Arduino Uno. A SparkFun 9DoF stick can measure G-force accelerations from 2 to 16, between 245 to 2,000 degrees per second of angular rotation around the axis, and magnetism between 4 to 16 gauss. All the readings are provided along three axes.
Note: The sensor “communicates” with the external modules using an I2C interface. The default I2C address of the magnetometer is 0x1E. For the accelerometer and gyroscope, it’s 0x6B. The sensor board operates on 3.3 volts, which is powered by the Arduino NANO.
Specifically, the sensor is powered with 3.3V of the Arduino NANO’s power regulator output. Arduino NANO’s I2C pins are connected to the sensor’s I2C pins.
Here’s a circuit diagram of the sensor…
For this project, the wire and sensor (SparkFun) libraries are included in the code. A new instance of the sensor library is, therefore, created that acts as the “functions” of the sensor library.
It’s only necessary to declare a few global variables that are shared between the different functions. The variable declination is the angle between the magnetic north and the true north. Its value is fixed. Three functions are also declared. Their purpose is to obtain data from the board for each of the sensor modules.
Arduino NANO’s setup function serial port is activated at 9,600 bits per seconds. Then, the I2C interface starts and the I2C addresses (of each individual sensor) are passed to the board.
The control will remain in the sensor loop until the sensors are started without any fault.
In the loop function, the imu.xxxAvailable() instructions are continuously polling the sensors for updated data. When data is updated in a sensor’s internal memory, the imu.readxxxX() instructions then update the particular xX, xy, and xz variables. To extract the coordinate variables of each sensor, its particular function is called from the main loop.
To extract the coordinates for a sensor, its particular function is called. However, it’s important to understand what happens for each function.
Each sensor acquires its physical parameters as analog and then converts them to a digital reading. But, this digital value does not correspond to the SI unit of the parameter. So, to properly convert the digital value in an SI unit for a particular physical parameter, the imu.calcGyro(imu.gx) instructions must be called. You can also print the raw values. Simply uncomment the PRINT_RAW global variable and comment the PRINT_CALCULATED.
Upon opening the serial monitor at 9600bps, you should receive the results displayed below.
The roll, pitch, and yaw are angular movements in the x, y and z directions. With these parameters, it’s easy to locate an object’s position in space.
Where to purchase parts?