Skip to content

Instantly share code, notes, and snippets.

@annem
Last active October 17, 2016 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save annem/c060dcae52e2cadcdae0d2f77031909d to your computer and use it in GitHub Desktop.
Save annem/c060dcae52e2cadcdae0d2f77031909d to your computer and use it in GitHub Desktop.
/*
Connect SCLK, MISO, MOSI, and CSB of ADXL362 to
SCLK, MISO, MOSI, and DP 10 of Arduino
(check http://arduino.cc/en/Reference/SPI for details)
*/
#include <SPI.h>
#include <ADXL362.h>
ADXL362 xl;
const int16_t slaveSelect = 10;
int16_t temp;
int16_t XValue, YValue, ZValue, Temperature;
void setup(){
Serial.begin(9600);
xl.begin(10); // Setup SPI protocol, issue device soft reset
//Change g range
// See page 33 of datasheet: http://www.analog.com/media/en/technical-documentation/data-sheets/ADXL362.pdf#page=34
digitalWrite(slaveSelect, LOW);
SPI.transfer(0x0A); // write
SPI.transfer(0x2C); // Reg 2C - Filter Control Register
SPI.transfer(0x53); // Reg 23 = 0x53 - switch range to +-4
//SPI.transfer(0x93); // Reg 23 = 0x53 - switch range to +-8
digitalWrite(slaveSelect, HIGH);
delay(100);
xl.beginMeasure(); // Switch ADXL362 to measure mode
Serial.println("Start Demo: Simple Read");
}
void loop(){
// read all three axis in burst to ensure all measurements correspond to same sample time
xl.readXYZTData(XValue, YValue, ZValue, Temperature);
Serial.print("XVALUE=");
Serial.print(XValue);
Serial.print("\tYVALUE=");
Serial.print(YValue);
Serial.print("\tZVALUE=");
Serial.print(ZValue);
Serial.print("\tTEMPERATURE=");
Serial.println(Temperature);
delay(100); // Arbitrary delay to make serial monitor easier to observe
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment