ADXL345 Accelerometer on I2C Arduino Due

I have connected an ADXl345 to a due wired as suggested in this tutorial: Live Fast - Code Young: ADXL345 accelerometer breakout board + Arduino and Processing
and I have an issue with the data I receive. For some reason all I get is -1,-1,-1 for the data values. I had a similar issue when I tried it with SPI, and abandoned it because I don't have the ability to connect to the SPI pins on the Due. While I haven't checked tonight, I will connect this setup to my Arduino Uno and see if the problem persists (I have a hunch it won't.) If that is the case, are there any suggestions on what I should do to get it working on the Due?
Thank you for your help

I checked using an Uno, and was able to get accurate data, so I don't really have any idea why I get the data I do on the Due. Unfortunately I need the accelerometer to function on an Arduino Due. Can anyone elaborate on this issue? Thank you

It would be easier to help if you could post your code. Or are you directly copy and pasting from the tutorial you linked? Do you think it is possible that the issue is caused because the Due uses 32 bit int's?

I know you said you had to use i2c but the following SPI example works on the Due and may be of some help:

 /*
  Calibrate ADXL345
  
  Use this sketch to get offset and scaling factor to calibrate the ADXL345.
  Orient the sensor so that one of the six axes is aligned with gravity, type
  the character 'r' in the serial terminal to reset the min/max values, then
  slowly move the sensor around until the values stop increasing/decreasing.
  Use those values to calculate the proper scaling and offsets.
*/


// pins 4, 10, and 52 allow auto chip selection on the Due
#define ACCEL_SS_PIN  10 // SPI slave select pin for accel

// general SPI defines
#define READ   0x80
#define WRITE  0x00
#define MULTI  0x40
#define SINGLE 0x00

#include <SPI.h> // built in SPI library

uint8_t accel_buffer[6];
int16_t accel_raw[3];
int16_t accel_max[3] = {0,0,0};
int16_t accel_min[3] = {0,0,0};

void setup() {
  Serial.begin(115200);
  Serial.println("Serial communication initialized...");
  
  // initialize the SPI bus for the accelerometer
  SPI.begin(ACCEL_SS_PIN);
  SPI.setBitOrder(ACCEL_SS_PIN, MSBFIRST);
  SPI.setDataMode(ACCEL_SS_PIN, SPI_MODE3);
  // ADXL345 max clock speed is 5 MHz
  SPI.setClockDivider(ACCEL_SS_PIN, (F_CPU / 5000000L) + 1);
  
  // make sure that the device is connected
  SPI.transfer(ACCEL_SS_PIN, READ | SINGLE | 0x00, SPI_CONTINUE);
  uint8_t accel_name = SPI.transfer(ACCEL_SS_PIN, 0x00);
  
  if(accel_name != 0xE5) {
    Serial.println("ADXL345 not detected!");
    Serial.print(accel_name, HEX); Serial.println(" found, should be 0xE5");
    delay(1000);
  }
  
  // Register 0x2C: BW_RATE 
  // use 2X oversampling with 400 Hz ODR (0x0C)
  // 800 Hz ODR (0x0D) is also available
  SPI.transfer(ACCEL_SS_PIN, WRITE | SINGLE | 0x2C, SPI_CONTINUE);
  SPI.transfer(ACCEL_SS_PIN, 0x0C);
  
  // Register 0x2D: POWER_CTL
  // put into measurement mode (0x08)
  SPI.transfer(ACCEL_SS_PIN, WRITE | SINGLE | 0x2D, SPI_CONTINUE);
  SPI.transfer(ACCEL_SS_PIN, 0x08);
  
  // Register 0x31: DATA_FORMAT
  // full resolution (0x08) at range of +/- 16 g (0x03)
  SPI.transfer(ACCEL_SS_PIN, WRITE | SINGLE | 0x31, SPI_CONTINUE);
  SPI.transfer(ACCEL_SS_PIN, 0x08 | 0x03);
  
  delay(100);
}


void loop() {
  
  // multibyte burst read of data registers (from 0x32 to 0x37)
  SPI.transfer(ACCEL_SS_PIN, READ | MULTI | 0x32, SPI_CONTINUE);
  
  for(int i = 0; i < 5; i++) {
    accel_buffer[i] = SPI.transfer(ACCEL_SS_PIN, 0x00, SPI_CONTINUE);
  }
  accel_buffer[5] = SPI.transfer(ACCEL_SS_PIN, 0x00);
  
  // combine the raw data (ADXL345 sends LSB first by default)
  //             _________ MSB ________   _____ LSB _____
  accel_raw[0] = (accel_buffer[1] << 8) | accel_buffer[0];
  accel_raw[1] = (accel_buffer[3] << 8) | accel_buffer[2];
  accel_raw[2] = (accel_buffer[5] << 8) | accel_buffer[4];
  
  for(int i = 0; i < 3; i++) {
    if(accel_raw[i] > accel_max[i]) {
      accel_max[i] = accel_raw[i];
    }
    if(accel_raw[i] < accel_min[i]) {
      accel_min[i] = accel_raw[i];
    }
    
    Serial.print(accel_min[i], DEC); Serial.print("/");
    Serial.print(accel_max[i], DEC); Serial.print("\t");
  }
  Serial.println();
  
  // listen to serial for a reset signal (character 'r')
  if(Serial.available() > 0) {
    
    int val = Serial.read();
    
    if(val == ((int) 'r')) {
      for(int i = 0; i < 3; i++) {
        accel_min[i] = 0;
        accel_max[i] = 0;
      }
    }
  }
  
  delay(50);
}

I´m trying the code for SPI but it says FF found, what means that the accel is not conected, I´m using 10, 11, 12 and 13 pins, are they the correct ones?.

thanks
Roberto

Hi, not sure if this still relevant as three weeks have passed since your last post, but which pins are you using for data on the Due?