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.
int16_t XValue, YValue, ZValue, Temperature;
float XValueF, YValueF, ZValueF;
xl.begin(SS); // Setup SPI protocol, issue device soft reset
xl.beginMeasure(); // Switch ADXL362 to measure mode
// 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);
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.