9DoF Sensor Stick Interfacing with Arduino uno

ABOUT THE PROJECT:

“Degrees Of Freedom” or “DOF” is a number of axis and sensors combined for balancing a plane, a helicopter or a robot.

  • 3DOF : This could be a 3-axis accelerometer or it could be a 3-axis gyroscope.
  • 6DOF : This is mostly a 3-axis accelerometer combined with a 3-axis gyroscope.
    Examples:

    • To control a remote control (RC) plane or helicopter or a self-balancing robot, both the information of the accelerometer and gyro are needed.
    • An another example of 6DOF is a combination of an accelerometer and a magnetometer for a tilt-compensated compass.
    • Many game controllers, phones, and tablets contain a 6DOF sensor for motion information.
  • 9DOF : This is mostly a 6DOF, combined with a magnetometer (compass).
  • 10DOF : This could be a 9DOF, combined with a baryonic pressure sensor. The baryonic (or absolute pressure) sensor can be used as an indication of the height.
  • 11DOF : This could be the 10DOF, combined with a GPS module.

Multiple sensors in a chip or on a board.

A 9DOF module, for example, could be a circuit board with three sensors. But some chips have an accelerometer and a gyro inside. In that case, only that sensor and a magnetometer are needed.


ABOUT THE SENSOR

Description: The SparkFun 9DoF Sensor Stick is an easy-to-use 9 Degrees of Freedom IMU. The Sensor Stick deftly utilizes the LSM9DS1 motion-sensing system-in-a-chip, the same IC used in the SparkFun 9DoF IMU Breakout. It houses a 3-axis accelerometer, 3-axis gyroscope, and 3-axis magnetometer – nine degrees of freedom (9DoF) in a single IC!

The onboard LSM9DS1 is equipped with a digital interface, but even that is flexible. The biggest difference between the two boards, besides the slimmed down 0.9″x0.4″ footprint, is the number of broken-out pins, with the Sensor Stick featuring only four for quick setup and ease of use.

The LSM9DS1 is one of only a handful of ICs that can measure three key properties of movement – angular velocity, acceleration and heading – in a single IC. By measuring these three properties, you can gain a great deal of knowledge about an object’s movement and orientation. The LSM9DS1 measures each of these movement properties in three dimensions. That means it produces nine pieces of data: acceleration in x/y/z, angular rotation in x/y/z, and magnetic force in x/y/z.

Each sensor in the LSM9DS1 supports a wide spectrum of ranges: the accelerometer’s scale can be set to ± 2, 4, 8, or 16g, the gyroscope supports ± 245, 500, and 2000°/s, and the magnetometer has full-scale ranges of ± 4, 8, 12, or 16 gauss.

Features:

  • 3 acceleration channels, 3 angular rate channels, 3 magnetic field channels
  • ±2/±4/±8/±16g linear acceleration full scale
  • ±4/±8/±12/±16 gauss magnetic full scale
  • ±245/±500/±2000dps angular rate full scale
  • I2C serial interface
  • Operating Voltage: 3.3V

SparkFun 9DoF Sensor Stick

Documents:

imageedit_1_7493397999

file-pdf-icon

DATASHEET OF 9DoF Stick (clickable image)

PIN CONFIGURATION

SparkFun 9DoF Sensor Stick

SOFTWARE REQUIRED

ARDUINO IDE (for windows)

SCHEMATICS

schematics-and-layouts-icon

9DoF Stick (CLICKABLE IMAGE)

ARDUINO SOURCE CODE

arduino-icon-2

  1. #include <Wire.h>
  2. #define GYROADDR 0x68
  3. #define COMPASSADDR 0x1e
  4. #define ACCELADDR 0x53
  5. union XYZBuffer {
  6.   struct {
  7.     short x,y,z;
  8.   } value;
  9.   byte buff[6];
  10. };
  11. void changeEndian(union XYZBuffer *xyz) {
  12.   for (int i=0;i<6;i+=2) {
  13.     byte t=xyz->buff[i];
  14.     xyz->buff[i]=xyz->buff[i+1];
  15.     xyz->buff[i+1]=t;
  16.   }
  17. }
  18. // Generically useful reading into a union type
  19. void readXYZ(int device,union XYZBuffer *xyz) {
  20.   Wire.requestFrom(device, 6);
  21.   long start=millis();
  22.   while (!Wire.available() && (millis()start)<100);
  23.   if (millis()start<100) {
  24.     for (int i=0;i<6;i++)
  25.       xyz->buff[i]=Wire.read();
  26.   }
  27. }
  28. void setupAccel(int device) {
  29.   // Check ID to see if we are communicating
  30.   Wire.beginTransmission(device);
  31.   Wire.write(0x00); // One Reading
  32.   Wire.endTransmission();
  33.   Wire.requestFrom(device,1);
  34.   while (!Wire.available());
  35.   byte ch=Wire.read();
  36.   Serial.print(“Accel id is 0x”);
  37.   Serial.println(ch,HEX);
  38.   // Should output E5
  39.   // Page 16
  40.   Wire.beginTransmission(device);
  41.   Wire.write(0x2d);
  42.   Wire.write(0x08);
  43.   Wire.endTransmission();
  44.   Wire.beginTransmission(device);
  45.   Wire.write(0x38);
  46.   Wire.write(0x84);
  47.   Wire.endTransmission();
  48. }
  49. void readAccel(int device,union XYZBuffer *xyz) {
  50.   Wire.beginTransmission(device);
  51.   Wire.write(0x32); // One Reading
  52.   Wire.endTransmission();
  53.   readXYZ(device,xyz);
  54. }
  55. void setupCompass(int device) {
  56.   // Check ID to see if we are communicating
  57.   Serial.print(“Compass id is “);
  58.   Wire.beginTransmission(device);
  59.   Wire.write(10); // One Reading
  60.   Wire.endTransmission();
  61.   Wire.requestFrom(device,2);
  62.   while (!Wire.available());
  63.   char ch=Wire.read();
  64.   Serial.print(ch);
  65.   ch=Wire.read();
  66.   Serial.println(ch);
  67.   // Should output H4  
  68. // Page 18
  69.   Wire.beginTransmission(device);
  70.   Wire.write(0x00); Wire.write(0x70);
  71.   Wire.endTransmission();
  72.   Wire.beginTransmission(device);
  73.   Wire.write(0x01); Wire.write(0xA0);
  74.   Wire.endTransmission();
  75.   Wire.beginTransmission(device);
  76.   Wire.write(0x02); Wire.write(0x00); //  Reading
  77.   Wire.endTransmission();
  78.   delay(6);
  79. }
  80. void readCompass(int device,union XYZBuffer *xyz) {
  81.   readXYZ(device,xyz);
  82.   changeEndian(xyz);
  83.   Wire.beginTransmission(device);
  84.   Wire.write(0x03);
  85.   Wire.endTransmission();
  86. }
  87. void setupGyro(int device) {
  88.   // Check ID to see if we are communicating
  89.   Wire.beginTransmission(device);
  90.   Wire.write(0x00); // One Reading
  91.   Wire.endTransmission();
  92.   Wire.requestFrom(device,1);
  93.   while (!Wire.available());
  94.   byte ch=Wire.read();
  95.   Serial.print(“Gyro id is 0x”);
  96.   Serial.println(ch,HEX);
  97.   // Should output 69
  98. }
  99. void readGyro(int device,union XYZBuffer *xyz) {
  100.   // page 20
  101.   Wire.beginTransmission(device);
  102.   Wire.write(0x1d);
  103.   Wire.endTransmission();
  104.   readXYZ(device,xyz);
  105.   changeEndian(xyz);
  106. }
  107. void pad(int width,int number) {
  108.   int n=abs(number);
  109.   int w=width;
  110.   if (number<0) w–;
  111.   while (n>0) {
  112.     w–;
  113.     n/=10;
  114.   }
  115.   if (number==0) w–;
  116.   for (int i=0;i<w;i++) Serial.print(‘ ‘);
  117. }
  118. void output(union XYZBuffer xyz) {
  119. //  pad(6,xyz.value.x);
  120.   Serial.print(xyz.value.x);
  121.   Serial.print(‘,’);
  122. //  pad(6,xyz.value.y);
  123.   Serial.print(xyz.value.y);
  124.   Serial.print(‘,’);
  125. //  pad(6,xyz.value.z);
  126.   Serial.print(xyz.value.z);
  127. }
  128. void setup()
  129. {
  130.   Serial.begin(9600);  // start serial for output
  131.   Wire.begin();        // join i2c bus (address optional for master)
  132.   setupCompass(COMPASSADDR);
  133.   setupAccel(ACCELADDR);
  134.   setupGyro(GYROADDR);
  135. }
  136. void loop()
  137. {
  138.   union XYZBuffer compass,gyro,accel;
  139.   int l1,l2,l3,l4;
  140.   l1=analogRead(0);
  141.   l2=analogRead(1);
  142.   l3=analogRead(2);
  143.   l4=analogRead(3);
  144.   readAccel(ACCELADDR,&accel);
  145.   readCompass(COMPASSADDR,&compass);
  146.   readGyro(GYROADDR,&gyro);
  147.   Serial.print(“A,”);
  148.   output(accel);
  149.   Serial.print(“,C,”);
  150.   output(compass);
  151.   Serial.print(“,G,”);
  152.   output(gyro);
  153.   Serial.print(“,L,”);
  154.   Serial.print(l1);
  155.   Serial.print(“,”);
  156.   Serial.print(l2);
  157.   Serial.print(“,”);
  158.   Serial.print(l3);
  159.   Serial.print(“,”);
  160.   Serial.print(l4);
  161.   Serial.println();
  162. }

HAPPY INTERFACING:)

SHUBHAM GUPTA-TECEX

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s