neo utilizzatore di accelerometro ADXL345

ciao
vi scrivo per sapere se c'è qualcuno che ha avuto modo di cimentarsi con l'uso del sensore ADXL345, ci lavoro da qualche giorno, con questo sketch

/*
I2C comunication
 read acceleration value
 
 CS pin 3v3
 SDA pin SDA +10k to 3v3
 SDO pin GND
 SCL pin SCL +10k to 3v3
 3v3 VCC
 GND GND
 */

#include <Wire.h>
#define DEVICE (0x53)    //ADXL345 device address
#define TO_READ (2)        //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

int regAddress;
int x, y, z;

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);

  regAddress = 0x32;    //first axis-acceleration-data register on the ADXL345

}

void loop()
{  
  readFrom(DEVICE, regAddress, TO_READ, buff); //read the acceleration data from the ADXL345

  //each axis reading comes in 10 bit resolution, ie 2 bytes.  Least Significat Byte first!!
  //thus we are converting both bytes in to one int
  x = (((int)buff[1]) << 8) | buff[0];   
  y = (((int)buff[3])<< 8) | buff[2];
  z = (((int)buff[5]) << 8) | buff[4];

  /*  //we send the x y z values as a string to the serial port
   sprintf(str, "%d %d %d", x, y, z);  
   Serial.print(str);
   Serial.write(10);
   
   delay(15);//It appears that delay is needed in order not to clog the port
   */
  //Print the results to the terminal.
    Serial.println("buff[1] << 8, BIN");
  Serial.println(buff[1] << 8, BIN);
  Serial.println("buff[0], BIN"); 
  Serial.println(buff[0], BIN); 
  

  Serial.println("buff[1] << 8 | buff[0], BIN");
  Serial.println(buff[1] << 8 | buff[0], BIN);
  
  Serial.println("x, BIN"); 
  Serial.println(x, BIN); 
 Serial.println("x, DEC"); 
  Serial.println(x, DEC);
  /*  Serial.print('\t');
   
   Serial.print(y * 0.00390625, DEC);
   Serial.print('\t');
   
   Serial.print(z * 0.00390625, DEC);
   Serial.print('\t');
   
   Serial.println("m/sec2");   */
  delay(20);//It appears that delay is needed in order not to clog the port 

}

void writeTo(int device, byte address, byte val) {
  Wire.beginTransmission(device); //start transmission to device 
  Wire.write(address);        // send register address
  Wire.write(val);        // send value to write
  Wire.endTransmission(); //end transmission
}

void readFrom(int device, byte address, int num, byte buff[]) {
  Wire.beginTransmission(device); //start transmission to device 
  Wire.write(address);        //sends address to read from
  Wire.endTransmission(); //end transmission

    Wire.beginTransmission(device); //start transmission to device (initiate again)
  Wire.requestFrom(device, num);    // request 6 bytes from device

  int i = 0;
  while(Wire.available())    //device may send less than requested (abnormal)
  { 
    buff[i] = Wire.read(); // receive a byte
  //  Serial.print(i);
  //  Serial.print('\t');
  //  Serial.println(buff[i], BIN);

    i++;
  }
  Wire.endTransmission(); //end transmission
}

non ho avuto grossi problemi, mettendo dei serial qua e la ho avuto modo capire qualcosa, quello che non capisco è l'utilizzo di << e |, dal reference ho capito come funzionano, ma se provo ad applicare allo sketch non capisco perchè ottengo altri risultati, sicuramente sbaglio io, avete qualche indicazione.

Grazie
Stefano

ciao
sono riuscito, finalmente, a comprendere le operazioni che vengono eseguite in questo codice, ma i valori che restituisce sono errati, ho letto che devo fare una calibrazioni, ho seguito alcune guide me ancora nessun risultato, nessuno ha fatto esperienze con questo sensore, nella sezione megatopic si parla di quadricotteri, ma non ho trovato suggerimenti

Stefano

Stefano, perché hai aperto due diversi Topic per lo stesso problema? Bloccane uno dei due o segnalalo spontaneamente ai MOD altrimenti fai cross-posting ed è fuori regolamento.

Ciao
Se ti riferisci al post nella sezione Hardware, quello è un altro problema, ero convinto si potesse fare, mi spiace se sto facendo confusione, ho provato a cancellare questo ma il forum non me lo consente.

Stefano