Connecting to Sparkfun’s 9DOF “Sensor Stick”: I2C access to ADXL345, ITG-3200, and HMC5843

[Update 24 Aug 2012: This post gives good detail about how to communicate with the sensors on the 9DoF Sensor Stick, but if you want a cleaner solution (that has been updated for Arduino 1.0), have a look at this post.]

Accelerometers are fun, but I want something more.  So I picked up a “sensor stick” from Sparkfun.

Sparkfun’s 9DOF sensor stick. Image courtesy of Sparkfun Electronics is CC by NC-SA 3.0

It has an ADXL345 accelerometer (datasheet) , an ITG-3200 gyroscope (datasheet), and an HMC5843 magnetometer (datasheet).  When still, the accelerometer can read the local gravitational field and the magnetometer can read the local magnetic field.  As long as I’m not at a magnetic pole, this is enough to give me an external frame of reference and know exactly how my sensor is positioned in space.  When the device is spinning, the gyro can help me separate translational acceleration from rotational acceleration as well as help me keep a running estimate of my sensor’s orientation even when I can’t trust the acceleration.  A system that does this is called an Attitude and Heading Reference System [AHRS].

I’m just getting into the Mathematics of how to use all of this data, and it is going to be good fun.  For today I’m going to talk about a much simpler problem: how do you connect to this board, initialize it, and read data from it.

Reading nine analog measurements directly would require nine analog pins, something we don’t have.  Instead, we will access these sensors using I2C, a two-wire protocol that allows us to put up to 112 devices on one bus.  This makes the wiring simple and the programming just a touch more tedious.

There are loads of great introductions to I2C on the web.  I may add to them one day, but for now, use your favorite search engine and learn about it if you don’t already know.

Building the Circuit

First things first, I soldered wires to my sensor stick instead of the plugable headers I usually work with.  I figured it would be more flexible if I wanted to stick it on a ski or sew it into my clothing later.  This is what my stick looks like:

My sensor stick, prepped and ready to go.

Thanks to I2C, our circuit is dead simple.  We just need the following connections to get this going on an Arduino Uno:

  1. Sensor stick VCC -> Arduino 3.3V
  2. Sensor stick GND -> Arduino GND
  3. Sensor stick SDA -> Arduino A4 (Arduino’s SDA, or data line)
  4. Sensor stick SCL  -> Arduino A5  (Arduino’s SCL, or clock line)

Here’s a Fritzing diagram in case the words are too complicated…

Once the circuit is put together, you are ready to start programming.

Reading data from the sensor stick

In order to access the sensor stick, we will need to

  1. know the 7-bit I2C addresses for each of our sensors
  2. know the addresses of each register we need to access on each sensor
  3. know how to initialize the sensors to make sure they are recording data, configured as we want them, and not sitting in power save mode.
  4. start reading data

Steps 1-3 require spending some quality time with the datasheets (linked above) and the schematic of the sensor stick so you know which pins are being pulled to GND, etc. Or you can just copy my code below.

I’ll walk through code for steps 1-3 for each of the three sensors before putting it all together in a simple data collection loop.

All I2C access will be done using the Wire library, so put this line at the top of your sketch:

#include <Wire.h>

I also use these two utility functions to interact with the I2C bus throughout the code.  This is really all there is to I2C on Arduino if your needs are simple.  These methods are based on ones I found on Keith Neufeld’s blog.

void i2c_write(int address, byte reg, byte data) {
  // Send output register address
  Wire.beginTransmission(address);
  Wire.send(reg);
  // Connect to device and send byte
  Wire.send(data); // low byte
  Wire.endTransmission();
}

void i2c_read(int address, byte reg, int count, byte* data) {
 int i = 0;

 // Send input register address
 Wire.beginTransmission(address);
 Wire.send(reg);
 Wire.endTransmission();
 // Connect to device and request bytes
 Wire.beginTransmission(address);
 Wire.requestFrom(address,count);
 while(Wire.available()) // slave may send less than requested {
   char c = Wire.receive(); // receive a byte as character
   data[i] = c;
   i++;
 }
 Wire.endTransmission();
}

Accessing the ADXL345 accelerometer

Per the datasheet, the 8-bit address for the ADXL345 is 0x3A unless pin 12 is pulled to GND, then it is 0xA6.  A quick look at the schematic shows that pin 12 is indeed pulled low, so our address is 0xA6.  (Don’t ask how long I kept trying and failing to use 0x3A!)

The Wire library just wants a 7-bit address, so we right shift and add this line to our code:

#define  ADXL345_ADDRESS (0xA6 >> 1)

There are a couple of register addresses we need to access:

//There are 6 data registers, they are sequential starting 
//with the LSB of X.  We'll read all 6 in a burst and won't
//address them individually
#define ADXL345_REGISTER_XLSB (0x32)

 //Need to set power control bit to wake up the adxl345
 #define ADXL_REGISTER_PWRCTL (0x2D)
 #define ADXL_PWRCTL_MEASURE (1 << 3)

With these definitions in place, this is how we initialize the ADXL345 on startup:

void init_adxl345() {
  byte data = 0;

  i2c_write(ADXL345_ADDRESS, ADXL_REGISTER_PWRCTL, ADXL_PWRCTL_MEASURE);

  //Check to see if it worked!
  i2c_read(ADXL345_ADDRESS, ADXL_REGISTER_PWRCTL, 1, &data);
  Serial.println((unsigned int)data);
}

Once the accelerometer is initialized we can read the data.  It comes to us in a chunk of 6 bytes: the least significant byte of X, the most significant byte of X, the least significant byte of Y, the most significant byte of Y, and so on.  Here’s the code.

int accelerometer_data[3];

void read_adxl345() {
 byte bytes[6];
 memset(bytes,0,6);

 //read 6 bytes from the ADXL345
 i2c_read(ADXL345_ADDRESS, ADXL345_REGISTER_XLSB, 6, bytes);

 //now unpack the bytes
 for (int i=0;i<3;++i) {
 accelerometer_data[i] = (int)bytes[2*i] + (((int)bytes[2*i + 1]) << 8);
 }
}

Accessing the ITG-3200 gyro

Perusing the datasheet and schematic like we did above, we find that the ITG-3200 has 8-bit address 0xD0.  To get reasonable data from it, we must also initialize the scale and digital low-pass filter.  This is critical: the default value for the scale on startup is 0b00, a reserved value!  Here are the definitions we need:

#define ITG3200_ADDRESS (0xD0 >> 1)
//request burst of 6 bytes from this address
#define ITG3200_REGISTER_XMSB (0x1D)
#define ITG3200_REGISTER_DLPF_FS (0x16)
#define ITG3200_FULLSCALE (0x03 << 3)
#define ITG3200_42HZ (0x03)

And here is the initialization function

void init_itg3200() {
  byte data = 0;

  //Set DLPF to 42 Hz (change it if you want) and
  //set the scale to "Full Scale"
  i2c_write(ITG3200_ADDRESS, ITG3200_REGISTER_DLPF_FS, ITG3200_FULLSCALE | ITG3200_42HZ);

  //Sanity check! Make sure the register value is correct.
  i2c_read(ITG3200_ADDRESS, ITG3200_REGISTER_DLPF_FS, 1, &data);

  Serial.println((unsigned int)data);
}

Once initialized, we can use the following function to capture the data.  Notice that the most-significant and least-significant bits come in a different order than they did with the ADXL345.

int gyro_data[3];

void read_itg3200() {
  byte bytes[6];
  memset(bytes,0,6);

  //read 6 bytes from the ITG3200
  i2c_read(ITG3200_ADDRESS, ITG3200_REGISTER_XMSB, 6, bytes);  //now unpack the bytes
  for (int i=0;i<3;++i) {
  gyro_data[i] = (int)bytes[2*i + 1] + (((int)bytes[2*i]) << 8);
  }
}

Accessing the HMC5843

Now let’s do the same work for our magnetometer, the HMC5843.  The trick with this one is that by default it starts in a single measurement mode.  If you don’t change that, you’ll just keep getting the same reading over and over.

#define HMC5843_ADDRESS (0x3C >> 1)
//First data address of 6 is XMSB.  Also need to set a configuration register for
//continuous measurement
 #define HMC5843_REGISTER_XMSB (0x03)
 #define HMC5843_REGISTER_MEASMODE (0x02)
 #define HMC5843_MEASMODE_CONT (0x00)

The initialization just sets the measurement mode.

void init_hmc5843() {
  byte data = 0;
  //set up continuous measurement
  i2c_write(HMC5843_ADDRESS, HMC5843_REGISTER_MEASMODE, HMC5843_MEASMODE_CONT);

  //Sanity check, make sure the register value is correct.
  i2c_read(HMC5843_ADDRESS, HMC5843_REGISTER_MEASMODE, 1, &data);
  Serial.println((unsigned int)data);
}

With this done, we can now read the data registers,  almost exactly like we did for the gyro.

int magnetometer_data[3];
void read_itg3200() {
 byte bytes[6];
 memset(bytes,0,6);

  //read 6 bytes from the HMC5843
 i2c_read(HMC5843_ADDRESS, HMC5843_REGISTER_XMSB, 6, bytes);

  //now unpack the bytes
 for (int i=0;i<3;++i) {
 magnetometer_data[i] = (int)bytes[2*i + 1] + (((int)bytes[2*i]) << 8);
 }
}

Putting it all together

First let’s perform all of the initialization we need on setup:

 void setup() {
  Wire.begin();
  Serial.begin(9600);

  for(int i = 0; i < 3; ++i) {
    accelerometer_data[i] = magnetometer_data[i] = gyro_data[i] = 0;
  }

  init_adxl345();
  init_hmc5843();
  init_itg3200();
}

Now that all of the hard work is done, a simple little loop can hum away and report all of your raw data for you:

 void loop() {
   read_adxl345();

   Serial.print("ACCEL: ");
   Serial.print(accelerometer_data[0]);
   Serial.print("\t");
   Serial.print(accelerometer_data[1]);
   Serial.print("\t");
   Serial.print(accelerometer_data[2]);
   Serial.print("\n");

   read_hmc5843();

   Serial.print("MAG: ");
   Serial.print(magnetometer_data[0]);
   Serial.print(",");
   Serial.print(magnetometer_data[1]);
   Serial.print(",");
   Serial.print(magnetometer_data[2]);
   Serial.print("\n");

   read_itg3200();

   Serial.print("GYRO: ");
   Serial.print(gyro_data[0]);
   Serial.print("\t");
   Serial.print(gyro_data[1]);
   Serial.print("\t");
   Serial.print(gyro_data[2]);
   Serial.print("\n");

   //Sample at 10Hz
   delay(100); }

Of course once you run this and play with it for a while, you’re going to ask “Now how do I calibrate these things?”  

Well, the Gauss-Newton method I’ve been beating on in my earlier posts works great for the ADXL345 (of course) and the HMC5843.  For the gyro it’s a different story and I’m working on it.

I’ll try to get a full sensor stick sketch with calibration up some time soon too.  In the mean time, have fun checking your attitude.

UPDATE: If you want a quick and easy way to visualize your raw data to make sure it is reasonable and perhaps do a quick “hand calibration” (not that I’d ever do such a thing 🙂 then have a look at this post and try out the gnuplot scripts.  Here’s what my magnetometer data looked like after spinning the stick around haphazardly for a while:

Four views of raw magnetometer data collected from the Sparkfun sensor stick

It is very close to an ellipsoid, and I was able to run this raw data through my Gauss-Newton octave scripts (described in the accelerometer calibration series)  to calibrate the magnetometer beautifully.

 

This entry was posted in Electronics, How To and tagged , , , , , , , , , . Bookmark the permalink.

41 Responses to Connecting to Sparkfun’s 9DOF “Sensor Stick”: I2C access to ADXL345, ITG-3200, and HMC5843

  1. bob hinkle says:

    Thank your for this. I converted it to java for me to use and i’m looking forward to testing it out soon.

  2. Sanjay says:

    Hello, i have used your coding but for some reason serial monitor only will run the code when the sensor is not plugged into pin A4 and A5. and on the arduino the little led that says TX only blinks when the sensor is unplugged. So i have no idea what it going on. I need to get this working for a school project, so i was wondering if you would be able to help!
    Thanks in advance!

    • Hmmm, I haven’t seen anything like that. Are you using an Arduino Uno or something else? I’d need to see the circuit to make an informed reply, if you give me some details I’ll take a crack at it.

      Of course by now you’ve probably figured it out. Sorry I was a bit slow, I was on the road.

  3. kjyoo1989KJ says:

    Amazing! Thank you so much, Mr. Schmidt!
    Would you mind suggesting some projects that can make use of the sensor stick?

    KJ

    • My pleasure KJ, I’m glad it is useful.

      Here are a few projects I’m toying with (some will appear in later posts):

      (0) Inertial navigation. Use these sensors to figure out exactly how your device has moved through space. Use least-squares (or something else) to combine this estimate with GPS data to smooth and improve the quality of your datation data.

      (1) Use a Sensor Stick + Arduino + OpenLog combination to make a handheld datalogger. I carry this with me when I’m skiing (plus a GPS too) and analyze my technique afterwards. The data analysis still needs some work.

      (2) Sensor Stick + Arduino + Bluetooth lets me make real time graphs of the sensor data on a laptop or mobile device. This can be synchronized with video or still photos for more accurate movement analysis.

      (3) In the gym, if you provide an interface to specify the weight you are lifting, you can measure power output — something that can be more interesting than just weight lifted.

      (4) Put an LED array in my ski gloves that tell me in real time how long and how much acceleration I undergo when turning. The right glove reports right turns, the left glove reports left turns. This keeps my inside hand up so I can see it and let’s me see if there is any asymmetry. You could do a similar thing for gait analysis of runners and walkers: do they do the same things on both feet?

      (5) Combined with Bluetooth it gives you an interesting way to interact with software on your phone/tablet/laptop. You can manipulate 3D objects naturally. Of course your mobile devices already have sensors like these in them.

      I’m pretty stuck on the skiing movement analysis angle, but just start playing with it and I’m sure you’ll get plenty of ideas.

  4. robodoc says:

    Wire.send() and Wire.receive() were deprecated in Arduino 1.0, just need to replace them with Wire.read() and Wire.write() for your read and write functions.

  5. Leo says:

    This page was hugely useful to me a couple of months ago. I had to read the same sensor stick using Labview and the clear and well explained code really helped me. Your effort is very much appreciated.

  6. Will says:

    Hello,

    I am (or will be) a senior mechanical engineering student and plan to build a quadcopter for my senior project. I bought the imu stick because it should be a perfect sensor to track nutation ( we will look into dead reckoning as well but that is a different story). However I have almost no experience working with a arduino and am not sure if the code you posted needs to be oriented in any way on the sketch. Is there any way this code should be oriented on the sketch pad?

    And thanks for the great post

    • It’s been a while, but I think you can just copy the code fragments from the post in order into a new sketch and it will work. If I get the time to throw a full sketch together I’ll put it online and post a link.

      Glad you found the post useful!

      • Will says:

        Yeah thats what I tried to do but I get an error in the ic2_write finction. I replaced all the wire.send and wire.receive with wire.read and wire.write and I get an error. I guess the read() function can not take parameters. Im using arduino 1.0 btw.

        And thanks for the quick repply

        -Will

    • Yes, another sign that it’s been too long since I wrote this. I never moved to arduino 1.0 b/c there never was a good day to go break everything I’d gotten working. I will update the post and upload a full sketch when I get this going on 1.0 (or whatever is current by then). Sorry that probably won’t be soon enough to help.

      If you figure it out, I’d love to hear.

      • Updated and working code:

        #include

        void i2c_write(int address, byte reg, byte data) {
        // Send output register address
        Wire.beginTransmission(address);
        Wire.write(reg);
        // Connect to device and send byte
        Wire.write(data); // low byte
        Wire.endTransmission();
        }

        void i2c_read(int address, byte reg, int count, byte* data) {
        int i = 0;

        // Send input register address
        Wire.beginTransmission(address);
        Wire.write(reg);
        Wire.endTransmission();
        // Connect to device and request bytes
        Wire.beginTransmission(address);
        Wire.requestFrom(address,count);
        while(Wire.available()) // slave may send less than requested
        {
        char c = Wire.read(); // receive a byte as character
        data[i] = c;
        i++;
        }
        Wire.endTransmission();
        }

        #define ADXL345_ADDRESS (0xA6 >> 1)

        //There are 6 data registers, they are sequential starting
        //with the LSB of X. We’ll read all 6 in a burst and won’t
        //address them individually
        #define ADXL345_REGISTER_XLSB (0x32)

        //Need to set power control bit to wake up the adxl345
        #define ADXL_REGISTER_PWRCTL (0x2D)
        #define ADXL_PWRCTL_MEASURE (1 << 3)

        void init_adxl345() {
        byte data = 0;

        i2c_write(ADXL345_ADDRESS, ADXL_REGISTER_PWRCTL, ADXL_PWRCTL_MEASURE);

        //Check to see if it worked!
        i2c_read(ADXL345_ADDRESS, ADXL_REGISTER_PWRCTL, 1, &data);
        Serial.println((unsigned int)data);
        }

        int accelerometer_data[3];

        void read_adxl345() {
        byte bytes[6];
        memset(bytes,0,6);

        //read 6 bytes from the ADXL345
        i2c_read(ADXL345_ADDRESS, ADXL345_REGISTER_XLSB, 6, bytes);

        //now unpack the bytes
        for (int i=0;i<3;++i) {
        accelerometer_data[i] = (int)bytes[2*i] + (((int)bytes[2*i + 1]) <> 1)
        //request burst of 6 bytes from this address
        #define ITG3200_REGISTER_XMSB (0x1D)
        #define ITG3200_REGISTER_DLPF_FS (0x16)
        #define ITG3200_FULLSCALE (0x03 << 3)
        #define ITG3200_42HZ (0x03)

        void init_itg3200() {
        byte data = 0;

        //Set DLPF to 42 Hz (change it if you want) and
        //set the scale to "Full Scale"
        i2c_write(ITG3200_ADDRESS, ITG3200_REGISTER_DLPF_FS, ITG3200_FULLSCALE | ITG3200_42HZ);

        //Sanity check! Make sure the register value is correct.
        i2c_read(ITG3200_ADDRESS, ITG3200_REGISTER_DLPF_FS, 1, &data);

        Serial.println((unsigned int)data);
        }

        int gyro_data[3];

        void read_itg3200() {
        byte bytes[6];
        memset(bytes,0,6);

        //read 6 bytes from the ITG3200
        i2c_read(ITG3200_ADDRESS, ITG3200_REGISTER_XMSB, 6, bytes); //now unpack the bytes
        for (int i=0;i<3;++i) {
        gyro_data[i] = (int)bytes[2*i + 1] + (((int)bytes[2*i]) <> 1)
        //First data address of 6 is XMSB. Also need to set a configuration register for
        //continuous measurement
        #define HMC5843_REGISTER_XMSB (0x03)
        #define HMC5843_REGISTER_MEASMODE (0x02)
        #define HMC5843_MEASMODE_CONT (0x00)

        void init_hmc5843() {
        byte data = 0;
        //set up continuous measurement
        i2c_write(HMC5843_ADDRESS, HMC5843_REGISTER_MEASMODE, HMC5843_MEASMODE_CONT);

        //Sanity check, make sure the register value is correct.
        i2c_read(HMC5843_ADDRESS, HMC5843_REGISTER_MEASMODE, 1, &data);
        Serial.println((unsigned int)data);
        }

        int magnetometer_data[3];

        void read_hmc5843() {
        byte bytes[6];
        memset(bytes,0,6);

        //read 6 bytes from the HMC5843
        i2c_read(HMC5843_ADDRESS, HMC5843_REGISTER_XMSB, 6, bytes);

        //now unpack the bytes
        for (int i=0;i<3;++i) {
        magnetometer_data[i] = (int)bytes[2*i + 1] + (((int)bytes[2*i]) << 8);
        }
        }

        void setup() {
        Wire.begin();
        Serial.begin(9600);

        for(int i = 0; i < 3; ++i) {
        accelerometer_data[i] = magnetometer_data[i] = gyro_data[i] = 0;
        }

        init_adxl345();
        init_hmc5843();
        init_itg3200();
        }

        void loop() {
        read_adxl345();

        Serial.print("ACCEL: ");
        Serial.print(accelerometer_data[0]);
        Serial.print("\t");
        Serial.print(accelerometer_data[1]);
        Serial.print("\t");
        Serial.print(accelerometer_data[2]);
        Serial.print("\n");

        read_hmc5843();

        Serial.print("MAG: ");
        Serial.print(magnetometer_data[0]);
        Serial.print(",");
        Serial.print(magnetometer_data[1]);
        Serial.print(",");
        Serial.print(magnetometer_data[2]);
        Serial.print("\n");

        read_itg3200();

        Serial.print("GYRO: ");
        Serial.print(gyro_data[0]);
        Serial.print("\t");
        Serial.print(gyro_data[1]);
        Serial.print("\t");
        Serial.print(gyro_data[2]);
        Serial.print("\n");

        //Sample at 10Hz
        delay(100); }

  7. bereket says:

    hi everybody my name is bereket i am from eritrea i am building a quadrotor for my final project can u by any chance post the calibration of the 9 dof sensor stick coz i have no idea what so ever?????

    • The code I linked to in some of my previous posts can do the job of calibrating the magnetometer and accelerometer on the stick with fairly straightforward modifications. In particular you need to change the initial guess at the calibration parameters to make it more reasonable. The ADXL345 is 0-centered where the ADXL335 is centered at 512 and the sensitivities are different.

      I have not written a sketch to calibrate this live. I calibrated by hand using the octave scripts linked to in this post. I haven’t developed strong opinions on gyro calibration, but the parameters from the datasheet look pretty good for this one.

      I will post a full calibration sketch when I write one, but it will be a while.

    • It took a while, but you can find some code to calibrate the magnetometer and accelerometer here: https://chionophilous.wordpress.com/2012/08/28/sensorlib-using-calibration/

      Still need to work on the gyro.

  8. M says:

    I think I found an error with the code, at least with respect to the HMC5843 magnetometer.

    The i2C_write and i2c_read should not use the same address 0x3C (read identifier). It should be 0x3D (write identifier).

  9. M says:

    I should say, the i2c_write should use 0x3C and the i2c_read should use 0x3D

    • Working with the Wire library, you only use 7-bit addresses. The library sets the data direction bit for you (or that’s what I hear, I haven’t looked under the hood). Notice that I right-shifted 0x3C by 1 to get a 7-bit address.

      If that still looks wrong, let me know. As it is, it appears to work; but that doesn’t mean it’s not wrong.

  10. Swat says:

    Hello,
    You’ve mentioned using Sensor Stick + Arduino + Bluetooth to make real time graphs of the sensor data on a laptop or mobile device. I’m new to this, It’ll be great if you could tell me which bluetooth module you used and how to send it to a mobile device. – Thanks

    • I’ve been using sparkfun’s BlueSMiRF Gold to open a serial connection to stream the data a laptop. On the laptop I have a processing sketch store the data and draw real time graphs or other visualizations.

      The trickiest part of that whole process is just making sure you’re using the right baud rate everywhere (the RN-41 defaults to 115200, most code defaults to 9600) and getting the pairing right (the pairing key for the RN-41 is ‘1234’).

      As for talking to a mobile device, I haven’t done that yet. I don’t think android will be a problem — it should work roughly like the PC setup I sketched above. OTOH I don’t expect good things from iOS.

      I hope to post some of this stuff within the next month — I’ve been focused on other projects lately.

  11. I’ve modified this code a bit, made it Arduino 1.0 compatible, and wrapped it in a library that you can access (or contribute to!) here: https://github.com/rolfeschmidt/muCSense

    I’m working on adding calibration to the library, hopefully that will be in place soon.

  12. Pingback: SensorLib: Introduction and Example | Chionotech

  13. Pingback: SensorLib: Using Calibration | Chionotech

  14. Alceu says:

    I am having the same problem as Sanjay: for some reason serial monitor only will run the code when the sensor is not plugged into pin A4 and A5. If I use any other Analogic Pins, such as A0 and A1, the serial monitor will run the code but the sensors will always send o as data. I’m the same code posted at this article (with the update of wire.write() and wire.read()) and an Arduino UNO. The cables are conected exactly as the Firtzing Diagram. I have no idea of what is the problem.

    Thanks in advance.

    • Rabin says:

      This SparkFun 9 DOF sensor stick is the 12 C interface .. So If you are using arduino Uno, Only A4 and A5 supports the 12C interface which is SDA and SCL pin. In other words other pins doesn’t work, which is to be expected.

  15. Nixfindus says:

    Good Job!
    The Stick is now still running and Send the Datas to my Computer.
    Thank you!

    Have you some news about the Calibration or have anyone an Link for an easy Tutorial?

  16. srajasek says:

    I am trying to use two ADXL345 with Arduino board and communicate via I2C, so far I tried communicating with one ADXL345 with arduino,, everything works but when I try with two I am just reading Zero’s. Can any one help me with the code and wiring.
    Thanks!

  17. Pingback: Accelerometer, Gyroscope and IMU Sensors - Tutorials - Into Robotics

  18. very good guide how to use IMU, gyro and accelerometer sensors. I add this tutorial on my article where a long list with sensors and tutorials about how to interface and programming accelerometer, gyro and IMU sensors http://www.intorobotics.com/accelerometer-gyroscope-and-imu-sensors-tutorials/

  19. chethan says:

    hello sir ,im getting follwoing error when complied can i get solution for this ?
    core.a(main.cpp.o): In function `main’:
    C:\Documents and Settings\Administrator\Desktop\Desktop\arduino-1.0.1-windows\arduino-1.0.1\hardware\arduino\cores\arduino/main.cpp:11: undefined reference to `setup’
    C:\Documents and Settings\Administrator\Desktop\Desktop\arduino-1.0.1-windows\arduino-1.0.1\hardware\arduino\cores\arduino/main.cpp:14: undefined reference to `loop’

  20. Blaze says:

    Hi, May I know how you can convert the raw data of the acceleration from the voltage range to m/s^2 ?

    Thanks in advance

  21. Ahmed Mohamed says:

    Hey …..

    I am using a 9DOF sensor stick + Arduino Uno with the code above and it works perfectly.

    Know i would like to display the results in a way that if i move/rotate the sensor i would see something like a cube moving/rotating.

    If you know please let me know ….. thanks and keep this great work going on.

  22. Joe says:

    Hi, i want to plot the accelerometer data in 3-axis using processing IDE can any one help

  23. robottr says:

    whats the point of blue cable on the sensor?

  24. Kalle says:

    First of all, thanks for a great tutorial! I’ve bought the sensor stick, and an arduino nano (almost identical specs as the uno, but smaller), and now I’m trying to connect things. I’m comparing to this post: http://www.scoutuav.com/2011/12/13/low-cost-arduino-based-auto-stabilizing-system/ , which uses another but related sensor, and there it is stressed that the sensor stick runs at 3.3 volts, whereas the arduino runs at 5 volts, and thus a level converter is necessary. In your case, you don’t use one. Can you motivate why it is not necessary?

  25. Hey! Has anyone made experience with this code on an Arduino Due? I´m new to Arduino and the outputs are only giving me zeroes and I have no Idea why :/!

    Thanks,

    Michael

  26. nevermind… got it working :3 … used SDA1 and SCL1. after using SDA and SCL it was working. Great work man!

  27. Hey there, it´s me again! Even though I got it working to get some values, I only get values from the range around 0-1000 and then it jumps directly to some values around 65xxx. Did you encounter this problems? I don´t get any values between 1000 and 65000

  28. krivicpero says:

    Hello nice post!

    Arduino digital pins specify I/O voltage of 5V, while all the sensors on SensorStick work with 3.3V? Why are you sure that in your setup they wont go to somke?

    • Yes, there’s a little corner cutting here. You could try something like this, use a 3.3V board from the start, or take your chances. My old sensor stick is still running fine after a few years of on-and-off use. Honestly I can’t remember whether I had a good reason to think it would be OK or if I just figured I’d replace the parts if I fried them.

Leave a comment