Hello guys,
im using Adafruit ADXL377 shield and having a small trouble.
Im using the following code to adquire values from X,Y and Z and too scale them to ‘g’s’:
void loop()
{
//Reset da array das coordenadas GPS
memset(message,0,sizeof(message));
readLocation();
int rawX = analogRead(A0);
int rawY = analogRead(A1);
int rawZ = analogRead(A2);
// Scale accelerometer ADC readings into common units
// Scale map depends on if using a 5V or 3.3V microcontroller
//float scaledX, scaledY, scaledZ; // Scaled values for each axis
scaledX = mapf(rawX, 0, 1023, -scale, scale);
scaledY = mapf(rawY, 0, 1023, -scale, scale);
scaledZ = mapf(rawZ, 0, 1023, -scale, scale);
Serial.print("X: ");
Serial.println(rawX);
Serial.print("Y: ");
Serial.println(rawY);
Serial.print("Z: ");
Serial.println(rawZ);
Serial.println();
// Print out scaled X,Y,Z accelerometer readings
Serial.print("X: ");
if(scaledX < 0) scaledX = -scaledX;
Serial.print(scaledX);
Serial.println(" g");
Serial.print("Y: ");
if(scaledY < 0) scaledY = -scaledY;
Serial.print(scaledY);
Serial.println(" g");
Serial.print("Z: ");
if(scaledZ < 0) scaledZ = -scaledZ;
Serial.print(scaledZ);
Serial.println(" g");
Serial.println();
}
float mapf(float x, float in_min, float in_max, float out_min, float out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
The measures looks ok. the only trouble is always the first measure gets a peak like:
X: 16.6g
Y: 14g
Z: 25g
Why is that happening ?