So with the communities help I am doing better. This code seems to work and is useful.
// This #include statement was automatically added by the Particle IDE.
#include <adxl362.h>
//#include "adxl362.h"
//#include <adxl362/adxl362.h>
//#include "adxl362/adxl362.h"
ADXL362 xl;
int16_t temp;
int16_t XValue, YValue, ZValue, Temperature;
float XValueF, YValueF, ZValueF;
void setup(){
xl.begin(SS); // Setup SPI protocol, issue device soft reset
xl.beginMeasure(); // Switch ADXL362 to measure mode
}
void loop(){
// read all three axis in burst to ensure all measurements correspond to same sample time
xl.readXYZTData(XValue, YValue, ZValue, Temperature);
// Convert to m/^s
XValueF = XValue/100.1;
YValueF = YValue/100.1;
ZValueF = ZValue/100.1;
Temperature = Temperature / 14.5;
Particle.publish("Temp="+String(Temperature, DEC)+" °C", String("x=" + String(XValueF, DEC)+", y=" + String(YValueF, DEC)+", z=" + String(ZValueF, DEC)), 60, PRIVATE);
delay(1000);
}
.
I get these results which seem good, x and y respond to motion and z stays constant at about -9 m/s^2
..
Two strange things:
- If I change my code to integer division
XValueF = XValue/100;
YValueF = YValue/100;
ZValueF = ZValue/100;
I get this strange result
Is that a particle bug or expected behavior for integer division to a float?
.
#2. The other issue is that printing values to 2 decimal places seems very old fashion and confusing. Could the Particle team just make some easier method such as
String myString = String(myFloat, DEC, 2); // for printing 2 decimal places
Just a suggestion, I am sure I can figure out the whole (snprintf, sprintf, Serial.println(longVal, 2), String(f).toCharArray(buf,10) ) standard ways of printing 2 decimal places.