Go Down

Topic: ADXL345 i2c PROBLEMS (Read 7 times) previous topic - next topic

aerosam

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.
http://codeyoung.blogspot.com/2009/11/adxl345-accelerometer-breakout-board.html

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

Fabio Varesano

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..

aerosam

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

Fabio Varesano

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

aerosam

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

Fabio Varesano

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.

aerosam

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)

Fabio Varesano

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

aerosam

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

Fabio Varesano

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..

wayneft

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()
Code: [Select]
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
cbi(PORTC,5);
cbi(PORTC,4);


I2C GPS Shield

Checkout my Open Source GPS Tracker on Kickstarter

wayneft

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.

Code: [Select]

#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);
}
I2C GPS Shield

Checkout my Open Source GPS Tracker on Kickstarter

Fabio Varesano

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: http://www.varesano.net/blog/fabio/new-homebrew-diy-breakout-board-pcb-adxl345-accelerometer

wayneft

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. 
I2C GPS Shield

Checkout my Open Source GPS Tracker on Kickstarter

Fabio Varesano

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..

Go Up