Hi everyone, I wanna start of saying this is my first project that involves any coding which is the reason I am stuck. I have looked around everywhere trying to add pieces of code that does what I want my accelerometer to do, as well as having read the datasheet to death.
All I want to do right now is get good data from my ADXL355z evaluation board to my Arduino Due. Before I make my ADXL357Bez work together with a ATMEGA16AU microcontroller on a tiny PCB for downhole measurements on a laboratory scale drilling rig.
I am currently receiving a lot of data from the accelerometer, however it's not reading all movement (Especially X-axis). I'll add the code in case there are any glaring mistakes.
//Add the SPI library so we can communicate with the ADXL355 sensor
#include <SPI.h>
#include "ADXL355.h"
//Assign the Chip Select signal to pin 10.
int CS = 10;
//This buffer will hold values read from the ADXL355 registers.
char values[10];
//These variables will be used to hold the x,y and z axis accelerometer values.
int x,y,z;
byte buff;
void setup(){
//Initiate an SPI communication instance.
SPI.begin();
//The speed is set by the setClockDivider() function, which divides the master clock (84MHz on Due) down to a frequency between 42MHz (/2) and X (/128).
SPI.setClockDivider(2);
//Configure the SPI connection for the ADXL355. The timing scheme follows the clock polarity (CPOL) = 0 and clock phase (CPHA) = 0 and is therefore SPI mode 0.
SPI.setDataMode(SPI_MODE0);
//Sets the order of the bits shifted out of and into the SPI bus, either LSBFIRST (least-significant bit first) or MSBFIRST (most-significant bit first).
SPI.setBitOrder(MSBFIRST);
//Create a serial connection to display the data on the terminal.
Serial.begin(9600);
//Set up the Chip Select pin to be an output from the Arduino.
pinMode(CS, OUTPUT);
//Before communication starts, the Chip Select pin needs to be set high.
digitalWrite(CS, HIGH);
//Measurement mode
digitalWrite(CS, LOW);
SPI.transfer(POWER_CTL);
SPI.transfer(0x00);
digitalWrite(CS, HIGH);
delay(50);
//Put the ADXL355 into Measurement Mode by writing 0 to the POWER_CTL register.
//digitalWrite(POWER_CTL, 0x00); //Measurement mode
}
void loop(){
digitalWrite(CS, LOW);
values[0] = SPI.transfer(DATAX3);
digitalWrite(CS, HIGH);
delay(10);
//
digitalWrite(CS, LOW);
values[1] = SPI.transfer(DATAX2);
digitalWrite(CS, HIGH);
delay(50);
//
digitalWrite(CS, LOW);
values[2] = SPI.transfer(DATAY3);
digitalWrite(CS, HIGH);
delay(50);
//
digitalWrite(CS, LOW);
values[3] = SPI.transfer(DATAY2);
digitalWrite(CS, HIGH);
delay(50);
//
digitalWrite(CS, LOW);
values[4] = SPI.transfer(DATAZ3);
digitalWrite(CS, HIGH);
delay(50);
//
digitalWrite(CS, LOW);
values[5] = SPI.transfer(DATAZ2);
digitalWrite(CS, HIGH);
delay(50);
//The x value is stored in values[0] and values[1].
x = ((int)values[0]<<8)|(int)values[1];
//The Y value is stored in values[2] and values[3].
y = ((int)values[2]<<8)|(int)values[3];
//The Z value is stored in values[4] and values[5].
z = ((int)values[4]<<8)|(int)values[5];
Serial.print(x, DEC);
Serial.print(',');
Serial.print(y, DEC);
Serial.print(',');
Serial.println(z, DEC);
//delay(100);
}
All addresses should be included in the ADXL355.h file.
Here's a picture of some data from the serial monitor: ADXL355z data - Album on Imgur
Link to datasheet: ADXL355 pdf, ADXL355 Description, ADXL355 Datasheet, ADXL355 view ::: ALLDATASHEET :::
There's a good chance I have missed something glaringly obvious like bit data, clock divider or how I read data, but I am at a loss and could use all input I can get.
Help?