Sparkfun 9 DoF sensor stick problems.

Hi, I bought one of these: http://www.sparkfun.com/products/10183
which has an ADXL345 accelerometer that I am trying to communicate with over I2C. I wired it up to an Arduino like this:

+5V -> Vcc
0V -> Gnd
A4 -> SDA
A5 -> SCL

And my code so far is:

#include <Wire.h>

const int ACCEL_ADDRESS = 0x1D;
const int ACCEL_POWER_CTL = 0x2D;
const int ACCEL_DATAX0 = 0x32;
const int ACCEL_DATAX1 = 0x33;
const int ACCEL_DATAY0 = 0x34;
const int ACCEL_DATAY1 = 0x35;
const int ACCEL_DATAZ0 = 0x36;
const int ACCEL_DATAZ1 = 0x37;

const int MAGNO_ADDRESS = 0x1E;

const int GYRO_ADDRESS = 0x38;

void setup()
{
  Serial.begin(9600);
  
  Serial.println("Starting I2C.");
  Wire.begin();
  Serial.println("I2C started. Starting accelerometer.");
  Wire.beginTransmission(ACCEL_ADDRESS);
  Wire.send(ACCEL_POWER_CTL);
  Wire.send(0x08);
  Wire.endTransmission();
  Serial.println("Accelerometer starter. Looping.");
}


void loop()
{
  // X accel.
  Wire.beginTransmission(ACCEL_ADDRESS);
  Wire.send(ACCEL_POWER_CTL);
  Wire.endTransmission();
  Wire.requestFrom(ACCEL_ADDRESS, 1);
  while (!Wire.available());
  int highx = Wire.receive();
  Wire.beginTransmission(ACCEL_ADDRESS);
  Wire.send(ACCEL_DATAX1);
  Wire.endTransmission();
  Wire.requestFrom(ACCEL_ADDRESS, 1);
  while (!Wire.available());
  int lowx = Wire.receive();
  Serial.println((highx << 8) | lowx);
}

But I don't get any response from the device (it never gets past the first Wire.available() loop). Can anyone say what I am doing wrong? I read some mention of disabling pull-up resistors in twi.cpp which I also tried, but it made no difference, and I've also tried the driver from the FreeIMU library which didn't work either.

This is very annoying, especially as it cost about £60. Have I got a dud board? Any ideas?

Do you have the two pull-up resistors that I2C requires? If they aren't on the 9 DoF board you will have to add them to the A4 and A5 pins.

I thought you had to disable those... or do I need to disable the internal ones and add external ones to 3.3V? I don't even have a 3.3V source. :-/ And also if I previously ran it with the internal pull-ups enabled, will that have damaged the devices? If so that is pretty -ing annoying given that there is no warning about this anywhere on sparkfun, or the wire library, and that really shouldn't be the default.

Is there any way to bodge a 3.3V source, perhaps using a voltage divider? I'm not concerned about power usage.

I just checked the schematic and it includes pull-up resistors so that's OK.

The schematic shows 3.3v power going to the chips. Perhaps you should not connect it to +5v.

ADXL345 Supply voltage range: 2.0 V to 3.6 V

HMC5843:
AVDD Referenced to AGND 3.3v Max
DVDD Referenced to DGND 2.0v Max

ITG-3200:
Operating Voltage Range: 2.1v - 3.6v

Dammit. So basically all I had to do was modify twi.cpp so it didn't use the 5V pull-ups, and it would have been fine, but now the chips are dead?

It seems pretty damn stupid that they'd have a voltage regulator so you can run Vcc off 5V, but then not even tell you that you'll damage it if you connect it straight to the 5V arduino. And whoever wrote twi.cpp deserves some significant blame too... Code shouldn't break hardware by default.

No, they are not dead. Just disable the pullups (see my guide How to disable internal Arduino ATMEGA pullups on SDA and SCL with I2C bus ) and check that your connections are like these and you should be fine.

Also, it's perfectly fine to connect the power to 5V as that board has an integrated voltage regulator which will take care of lowering it to the 3V3 used by the sensors.

Regarding the pullup enabling in Wire, well.. I had already opened an issue on the issue tracker asking the developers to fix that.. but nobody gave it a s**t ... You may wanna comment there if you think I was right.

Thanks for the replies. Fabio, what makes you think they aren't dead, given that I connected them to the 5V pull-ups and the datasheet for the ADXL345 says SDA and SCL can't go above Vdd (3.3V) plus a tiny bit? And if they aren't dead, then I can't see why my code didn't work with the internal 5V pull-ups disabled (it seems the schematic shows 3.3V pull-ups built into the sensor board).

Also, I hooked it up to an oscilloscope. It seems like the address is sent, but the ACK bit isn't set by the ADXL345. Also note that it is 3.3V (vertical division is 2V).

what makes you think they aren't dead

Because I ran a triple breakout board IMU with your same sensors without LLC and with pullups enabled for about 5 months.. that was when I still was learning stuff.. about one year ago.. those three sensors still works perfectly. I'd say that you may shorten their life but a couple tests with the pullups on doesn't fry them.

What board are you using? Can you post a picture of your connections?

That is slightly reassuring. I'm using the RBBB (Really Bare-Bones Board) arduino. Here is a photo:

I really appreciate the help btw.

Do you see the blue LED on the 9dof stick light up? Your photo shows it off.

Yes it does. I have since connected it to a bus pirate, and it shows the two other chips (gyro and magnetometer) responding, but the accelerometer was not. So definitely a faulty part.

I emailed cool components and they said they would send me a replacement.

Hi all,

Couple of questions relating to the above which I hope aren't stupid questions, but please bare in mind that I'm still quite new to all this.

I have a 9DOF stick that I want to connect to my Arduino ADK, which as far as I can see is effectively the same as an Arduino Mega.

If Im understanding it right I need to connect the SDA and SCL to pins 20 and 21 on the Mega board.

I understand about disabling the pullup resisitors too (I think).

Where I'm confused is:

  1. Why would I want to connect the 9DOF stick to 5volt when I have a 3.3volt source on the Arduino board

and

  1. In the post by Fabio Varesano it appears to be suggested the SDA and SCL wires should be connected the 3.3volt rail using 2.2k resistors - but I don't understand why.

Thanks in advance.

Chris.

Nobody?

The 9DOF from Sparkfun has a 3.3v converter and 4.7k pullups resitors (see the schematic on Sparkfun site), so you can connect it to 5V and disable the pullups from the Arduino. I use the sensor stick for hours every day, never disabled the pullups and no problems. My feeling is that the board pullups + Arduino pullups = 2 resistors in serie but this might be totally wrong.

However, I experienced noisy accelerometer signals with 5V so I connect the board to 3.3v and the noise disappeared, I can't explain why.
I have 5 sticks and they all have the same accelerometer noise with 5v.

ChrisLong:

  1. Why would I want to connect the 9DOF stick to 5volt when I have a 3.3volt source on the Arduino board

Not all Arduino boards have a 3V3 power source. Eg: 16Mhz Pro Minis.

ChrisLong:
2) In the post by Fabio Varesano it appears to be suggested the SDA and SCL wires should be connected the 3.3volt rail using 2.2k resistors - but I don't understand why.

Because the sensors aren't 5V tolerant so they shouldn't connected to a 5V logic level. Since I2C is open drain the ATMEGA, even if running at 5V as in the Arduino, never drives the signal high. By using pullups to 3V3 your levels will range from 0V (logic LOW) to 3V3 (logic HIGH). 3V3 will be also seen as HIGH by the arduino since every voltage above 2.6V or near that is seen as HIGH.