Hi guys, i have connected to an accelerometer (ADXL362) to an arduino leonardo. My connection is followed this reference: SPI - Arduino Reference.
I have successfully got the X,Y and Z data with the following code:
include <ADXL362.h>
#include <SPI.h>
//Objects and Defines
ADXL362 xl;
#define teamID 1
//Variables
int XOffset, YOffset, ZOffset;
long packetCount=0;
void setup(){
xl.begin(); // Setup SPI protocol, issue device soft reset
xl.beginMeasure(); // Switch ADXL362 to measure mode
delay(5); //delay to allow readings to settle before offset definition
XOffset=xl.readXData();
YOffset=xl.readYData();
ZOffset=xl.readZData();
Serial.begin(9600); //Opens serial port at 9600 bauds
Serial1.begin(9600);
while(!Serial){ // waits for the serial port to open before proceeding
}
}
void loop(){
String dataString = "PSTART";
dataString += ",";
dataString += String(teamID);
dataString += ",";
dataString += String(packetCount);
dataString += ",";
dataString += xl.readXData()-XOffset;
dataString += ",";
dataString += xl.readYData()-YOffset;
dataString += ",";
dataString += xl.readZData()-ZOffset;
dataString += ",PEND";
Serial.println(dataString);
Serial1.println(dataString);
packetCount++;
delay(300);
}
However, the X, Y and Z values are in random values, not in term of g. Therefore, can anyone tell me what code i need to convert the values into g (gravity)?
Thanks a lotttttt.