Pages: 1 [2]   Go Down
Author Topic: ADXL345 i2c PROBLEMS  (Read 7372 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 1
Posts: 41
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Logged

Torino, Italy
Offline Offline
Sr. Member
****
Karma: 2
Posts: 309
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

 smiley-confuse
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello; i havent read the whole thread; so maybe i'm repeataing something.
im reading this tutorial:
http://codeyoung.blogspot.com/2009/11/adxl345-accelerometer-breakout-board.html

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:
Code:
#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:
Quote
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, smiley-cool) the sensor will be in sleep mode, and will give zero readings!!
So the device must be waked up before use.

Hope this helps.
Logged

Pages: 1 [2]   Go Up
Jump to: