ADXL345 i2c PROBLEMS

Hi everyone.

I just got my ADXL345 board from sparkfun and started trying to get the accelerometer readings.
I have an Arduino uno, and followed the steps outlined in this blog.

I find some very odd problems
If i remove the writeTo lines in setup(), i get the output as 0 0 0 on the serial monitor.
If i add the writeTo lines in setup(), i get nothing on the serial monitor.

I have been banging my head on the table, for what is wrong =(. In one of the numerous permutations and combinations of commenting, uncommenting code and removing and replacing the sensor from the breadboard, i got it to give non [0 0 0].
Pls help

The code on that website worked for me just fine. So, I guess you might have some issues with your connections. Please post a picture of your connections so that we can have a look at your wires and see if there's something wrong..

Hi Fabio

I am unable to upload any attachment to the forum.
I get the strange error,The attachments upload directory is not writable. Your attachment or avatar cannot be saved.
So i put the pics up on image-shack. Here is the link
http://img132.imageshack.us/img132/1292/00006ax.jpg
http://img819.imageshack.us/img819/9756/00007as.jpg

Thanks
Sam

It looks like the SDA and SCL lines are swapped.. SDA should go into A4 and SCL should go into A5

That's how it is connected.
It looks otherwise in the picture, but SCL(is't pin)->A5 and SDA(2nd pin)->A/4
Is there a way to check if the sensor is working? I hope i haven't fried it by something i did yesterday?

Thanks
Sam

Then the connections looks good.

With a multimeter, I'd check the voltages between Vcc and GND, GND and CS, GND and SDO when everything is connected as the pictures and the arduino is connected to the PC. You should get: 3.3V, 3.3V, 0V

Another test is to set the multimeter in resistance mode and check the resistance between GND and VCC when you disconnect everything from the board. You should get something around 150 Ohm.

All the voltages seem ok.
When i remove all power from the board and check the resistance between Gnd and Vcc, i get OL(i guess that's open loop or infinitely high resistance)

that's not good.. you should get 150ohm or something.. be careful on selecting the correct scale in the multimeter..

Rechecked again, by taking the breakout-board off the bread-board.
I get 287 Ohms

Well, that's a good value.. than I don't really know what else to suggest.. last shot: change the resistors from 10K Ohm to 4.7K or 2.2K .. check that the wires you are using actually convey current by disconnecting them and check their resistance with the multimeter..

You might want to try posting the code you are using. I realize you are following that link but you may have made some changes along the way that could have changed the code.

While I've never used this accelerometer I know many people have and I've read some people have no problem and others have lots of problems. I'm wondering if it has to do with the way people are wiring this up to the Arduino. The ADXL345 is not a 5 volt tolerant device however most people aren't using logic level converters when converting the 3.3 volt logic (assuming the unit is powered by the Arduino 3.3 V pin) to the 5 volt IO of the Arduino. 3.3v logic should work on the Arduino as long as your 3.3 v supply doesn't drop out too much or your 5v supply is not too much above 5 volts (the logic levels are based off a percentage of the supply voltage). That being said you you are actually using 2 sets of pullup resistors in your circuit. The first obvious set is the pair of resistors on your breadboard tied to 3.3 volts. The second, not so obvious, is the pair of internal pullup resistors in the Arduino that are tied to 5 volts. You in essence are pulling up to two separate voltages (probably not the best idea). You can try disabling the internal pull up resistors on the Arduino to see if it works just insert this code in your setup function after you call wire.begin()

#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
cbi(PORTC,5);
cbi(PORTC,4);

Looking over the datasheet, the device has a DeviceID register which will report back a value of 0xE5. So I suggest starting off with some simple commands first to make sure you are even communicating with the accelerometer. The below code will poll the DEVICEID register and display it on serial monitor every 2 seconds. Run the code and let us know what you get.

#include "Wire.h"

#define DEVICE (0x53)
byte byte1 = 0;


void setup(){
  Wire.begin();
  #ifndef cbi
  #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
  #endif
  cbi(PORTC,5);
  cbi(PORTC,4);
  Serial.begin(115200);
  
}

void loop(){
  Wire.beginTransmission(DEVICE);
  Wire.send(0x00);
  Wire.endTransmission();
  Wire.requestFrom(DEVICE,1);
  byte1 = Wire.receive();
  Serial.println(byte1,HEX);
  delay(2000);
}

Yeah, a logic level converter may be a good idea.. However, I used your same connections and not disabled the internal pullups with the same device for more than 6 months and everything still works great. I didn't know that Wire enabled the internal pullups at that time..

Basically, that was the connection I was using: varesano.net -

Agreed, it should work. However when you run into problems like he is having (appears to be wired correctly and coded correctly), sometimes the "shoulds" and "probablys" add up and keep it from functioning properly. It will be interesting to see what this turns out to be in the end.

Yeah, it may be also a bad breakout board.. I don't think Sparkfun test their boards so this could happen.
I've seen many people with problems with the HMC5843 with Sparkfun boards lately..

I found the mistake, Like an idiot I had commented out the line
readFrom(DEVICE, regAddress, TO_READ, buff);, in my previous debugging attempts and didn't check to uncomment it
Everything works fine now. Sorry for wasting your time.

:~

Oh no, I'm new with arduino and have the same issue, that my ADXL345 only shows 0 0 0 for x y z.

I tried several tutorials like http://www.babelduck.com/index.php/en/reference/user-manuals/1427-adxl345-3-axis-accelerometer-sensor-module-product-manual and http://bildr.org/2011/03/adxl345-arduino/ but with all of these my accelerometer seems to deliver only nulls...

It's brand new and it's hard to believe, that it's broken. Wiring was always like it should.

Anyone a further idea?

Thank you so much!

Hello; i havent read the whole thread; so maybe i'm repeataing something.
im reading this tutorial:

and says something that recalled your problem to me: His code writes three bytes to the device before asking for a reading, to take it out from sleep mode (which will give zero readings). We are talking about I2C communication.

See this:

#include <Wire.h>
#define DEVICE (0x53)    //ADXL345 device address
#define TO_READ (6)        //num of bytes we are going to read each time (two bytes for each axis)

byte buff[TO_READ] ;    //6 bytes buffer for saving data read from the device
char str[512];                      //string buffer to transform data before sending it to the serial port

void setup()
{
  Wire.begin();        // join i2c bus (address optional for master)
  Serial.begin(9600);  // start serial for output
  
  //Turning on the ADXL345
  writeTo(DEVICE, 0x2D, 0);      
  writeTo(DEVICE, 0x2D, 16);
  writeTo(DEVICE, 0x2D, 8);
}

Look it up. then, the author then explains:

Most of the code is pretty self-explanatory, so I'll explain only the code after the //Turning on the ADXL345 comment.
As you can see we are writing three different values to register 0x2D. 0x2D is the Power Control register of the ADXL345 (see datasheet). We first reset the power control register, then put the sensor in standby mode, and last we are putting it in to measure mode. We're doing the writes one after another because that's what the datasheet recommends. We could simply do the last write also. If you don't turn on the fourth bit on (writeTo(DEVICE, 0x2D, 8)) the sensor will be in sleep mode, and will give zero readings!!

So the device must be waked up before use.

Hope this helps.

I just tried playing with this ADXL3 I2C module. have used the program and circuit described here:

for some reason, i'm getting a good read from x and y, but z read is constant and equals to 511.

i'm using arduino nano, SDA is connected to A4, SCL connected to A5.

Any idea why is that and how to fix it?