I am using an Arduino Uno with this KX134 Qwiic accelerometer to measure the g forces upon impact. It has been mounted to the wooden block that will be dropped and configured to the Arduino using I2C connections. The delay in the Arduino code has been set to delay(1); // Equal to 5000 Hz. Upon the object striking the solid surface, there is no increase in the amount of g force displayed in the Serial window or Serial plotter. I assume the data is not transferring fast enough for the fast impact. Do I need a faster Arduino, is I2C not fast enough for impact testing. What can I check to make this work?
#include <Wire.h>
#include “SparkFun_Qwiic_KX13X.h”
//QwiicKX132 kxAccel;
QwiicKX134 kxAccel; // Uncomment this if using the KX134 - check your board
//if unsure.
outputData myData; // This will hold the accelerometer’s output.
float MAX=0;
void setup() {
while(!Serial){
delay(50);
}
Serial.begin(115200);
Serial.println(“Welcome.”);
Wire.begin();
Serial.println(“SPI BEGIN”);
if( !kxAccel.begin()){
Serial.println(“Could not communicate with the the KX13X. Freezing.”);
while(1);
}
else
Serial.println(“Ready.”);
if( !kxAccel.initialize(DEFAULT_SETTINGS)){ // Loading default settings.
Serial.println(“Could not initialize the chip.”);
while(1);
}
else
Serial.println(“Initialized…”);
// kxAccel.setRange(KX132_RANGE16G);
kxAccel.setRange(KX134_RANGE16G); // For a larger range uncomment
}
void loop() {
//Display Values to user
myData = kxAccel.getAccelData();
Serial.print("X: ");
Serial.print(myData.xData, 4);
Serial.print("g ");
Serial.print(" Y: ");
Serial.print(myData.yData, 4);
Serial.print("g ");
Serial.print(" Z: ");
Serial.print(myData.zData, 4);
Serial.print("g ");
float Val = sqrt(myData.xDatamyData.xData+myData.yDatamyData.yData+myData.zData*myData.zData);
if (Val>MAX)
{
MAX=Val;}
Serial.print("MAX: ");
Serial.println(MAX);
Serial.print("g ");
delay(1);
}