ADXL345 Accelerometer Readings Stuck

The situation:

The GY-85 board has 3 chips; ITG3205 (gyro) + ADXL345 (accel) + HMC5883L (magno).

The Arduino UNO R3 communicates to the chips via I2C using the Wire.h library on pins An4 (SDA) + An5 (SDL).
The gyro & magno chip are reading well using examples found online. (Sweet!)

The problem:

The accelerometer seems to be communicating via the I2C fine.
When the address is changed from 0x53 the communication fails.
When the wiring is made bad, that too is detected.

I am using the <ADXL345.h> library with this example code:

//Arduino 1.0+ Only!

#include <Wire.h>
#include <ADXL345.h>


ADXL345 adxl; //variable adxl is an instance of the ADXL345 library

void setup(){
  Serial.begin(9600);
  adxl.powerOn();
  
  //set activity/ inactivity thresholds (0-255)
  adxl.setActivityThreshold(75); //62.5mg per increment
  adxl.setInactivityThreshold(75); //62.5mg per increment
  adxl.setTimeInactivity(10); // how many seconds of no activity is inactive?
 
  //look of activity movement on this axes - 1 == on; 0 == off 
  adxl.setActivityX(1);
  adxl.setActivityY(1);
  adxl.setActivityZ(1);
 
  //look of inactivity movement on this axes - 1 == on; 0 == off
  adxl.setInactivityX(1);
  adxl.setInactivityY(1);
  adxl.setInactivityZ(1);
 
  //look of tap movement on this axes - 1 == on; 0 == off
  adxl.setTapDetectionOnX(0);
  adxl.setTapDetectionOnY(0);
  adxl.setTapDetectionOnZ(1);
 
  //set values for what is a tap, and what is a double tap (0-255)
  adxl.setTapThreshold(50); //62.5mg per increment
  adxl.setTapDuration(15); //625?s per increment
  adxl.setDoubleTapLatency(80); //1.25ms per increment
  adxl.setDoubleTapWindow(200); //1.25ms per increment
 
  //set values for what is considered freefall (0-255)
  adxl.setFreeFallThreshold(7); //(5 - 9) recommended - 62.5mg per increment
  adxl.setFreeFallDuration(45); //(20 - 70) recommended - 5ms per increment
 
  //setting all interupts to take place on int pin 1
  //I had issues with int pin 2, was unable to reset it
  adxl.setInterruptMapping( ADXL345_INT_SINGLE_TAP_BIT,   ADXL345_INT1_PIN );
  adxl.setInterruptMapping( ADXL345_INT_DOUBLE_TAP_BIT,   ADXL345_INT1_PIN );
  adxl.setInterruptMapping( ADXL345_INT_FREE_FALL_BIT,    ADXL345_INT1_PIN );
  adxl.setInterruptMapping( ADXL345_INT_ACTIVITY_BIT,     ADXL345_INT1_PIN );
  adxl.setInterruptMapping( ADXL345_INT_INACTIVITY_BIT,   ADXL345_INT1_PIN );
 
  //register interupt actions - 1 == on; 0 == off  
  adxl.setInterrupt( ADXL345_INT_SINGLE_TAP_BIT, 1);
  adxl.setInterrupt( ADXL345_INT_DOUBLE_TAP_BIT, 1);
  adxl.setInterrupt( ADXL345_INT_FREE_FALL_BIT,  1);
  adxl.setInterrupt( ADXL345_INT_ACTIVITY_BIT,   1);
  adxl.setInterrupt( ADXL345_INT_INACTIVITY_BIT, 1);
}

void loop(){
  
  //Boring accelerometer stuff   
  int x, y, z;  
  adxl.readAccel(&x, &y, &z); //read the accelerometer values and store them in variables  x,y,z

  // Output x,y,z values - Commented out
  Serial.print(x);
  Serial.print(y);
  Serial.println(z);

  
  //Fun Stuff!    
  //read interrupts source and look for triggerd actions
  
  //getInterruptSource clears all triggered actions after returning value
  //so do not call again until you need to recheck for triggered actions
   byte interrupts = adxl.getInterruptSource();
  
  // freefall
  if(adxl.triggered(interrupts, ADXL345_FREE_FALL)){
    Serial.println("freefall");
    //add code here to do when freefall is sensed
  } 
  
  //inactivity
  if(adxl.triggered(interrupts, ADXL345_INACTIVITY)){
    Serial.println("inactivity");
     //add code here to do when inactivity is sensed
  }
  
  //activity
  if(adxl.triggered(interrupts, ADXL345_ACTIVITY)){
    Serial.println("activity"); 
     //add code here to do when activity is sensed
  }
  
  //double tap
  if(adxl.triggered(interrupts, ADXL345_DOUBLE_TAP)){
    Serial.println("double tap");
     //add code here to do when a 2X tap is sensed
  }
  
  //tap
  if(adxl.triggered(interrupts, ADXL345_SINGLE_TAP)){
    Serial.println("tap");
     //add code here to do when a tap is sensed
  } 

}

The readings come through to the serial port as:

activity
-512-512-373
activity
-512-512-370
activity
-512-512-371
activity
-512-512-371
activity
-512-512-374
activity
-512-512-372
activity
-512-512-376
activity
-512-512-372
activity
-512-512-371
activity
-512-512-372
activity
-512-512-373
activity
-512-512-374
activity
-512-512-372
activity
-512-512-372

No matter what I do, what examples I use, or how I move the sensor round… the output never changes from -512 (for the first two readings) and -373 randomly flickers up/down by 1 or 2 . Activity always reads Activity.

I’ve tried altering the adxl.set_bw(ADXL345_BW_3); from ADXL345_BW_3 to ADXL345_BW_1600 - No change.

Can anyone come up with ideas / things to try??

What library do you use? Where is the link to it?

I have tested mainly with the library at: https://github.com/landis/arduino/blob/master/libraries/Bildr_adxl345/examples/ADXL345_Example/ADXL345_Example.ino

I've also tested with the Adafruit library: https://github.com/adafruit/Adafruit_ADXL345

Interestingly the two libraries give similar results in that the first two values (x & y) are 'stuck' at their (I assume) extreme low values and the z value does not really change.

Adafruit output below

Accel Raw: -20.08  -20.08  -16.08
Accel Raw: -20.08  -20.08  -16.08
Accel Raw: -20.08  -20.08  -16.08
Accel Raw: -20.08  -20.08  -16.16
Accel Raw: -20.08  -20.08  -16.08
Accel Raw: -20.08  -20.08  -16.08
Accel Raw: -20.08  -20.08  -16.08
Accel Raw: -20.08  -20.08  -16.16
Accel Raw: -20.08  -20.08  -16.16
Accel Raw: -20.08  -20.08  -16.24
Accel Raw: -20.08  -20.08  -16.08
Accel Raw: -20.08  -20.08  -16.16
Accel Raw: -20.08  -20.08  -16.24
Accel Raw: -20.08  -20.08  -16.08
Accel Raw: -20.08  -20.08  -16.24

I'm starting to wonder if the chip is bad. I thought I'd throw it out there in case someone has seen it before and can help.

Interestingly the two libraries give similar results in that the first two values (x & y) are 'stuck' at their (I assume) extreme low values and the z value does not really change.

This is quite interesting as the two library use different addresses for the chip (bildr: 0x1D, adafruit: 0x53). The chip uses both addresses, the right one is selected by applying Vcc or GND to a pin. The only schematics I found for a GY85 module shows the address pin grounded, which should result in an address of 0x53. In this case only the Adafruit library should give correct results.. Can you check how your module is wired?

The wiring is good. Its really simple and has power (5v) and Gnd, then SDA to An4 and SDL to An5 as per Wire.h I have also tried 3.3V as the board accepts both voltages. Results are the same.

I changed the Adafruit from Address 0x1D to 0x53 as the pin is grounded for sure. I confirmed the address with an I2C scanner.

If anyone else was wondering what the chip addresses are for the GY-85 board they are..

  • ITG3205 = 0x68
  • ADXL345 = 0x53
  • HMC5883L = 0x1E

Hi

Thanks for code and explanation! Code works fine if i power the MCU and ADXL with USB(from computer) but if i power the mcu and adxl both with 3V from battery then reading fluctuating with any movement.

To find the flow i checked the voltage from battery and it's almost constant to 3V only.

Could you please help me finding the root cause of this problem.

~Som