KW134 Impact Testing

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);

}

Try setting the PRINT delay to either 20 or 50ms and see if that produces anything useful (the example notes that it should be 1/ODR) https://github.com/sparkfun/SparkFun_KX … adings.ino

I have added a loop to my code to view the actual speeds and analyzed it using no delay functions. The code is looping 500-600 times per second which is not fast enough to register impact testing. Are there any changes that I can make to my code or will I have to rewire the system?

Hey I have been recently troubleshooting this sensor for impact testing.

Have you made any progress since you’re last submission?

If not, I can provide a sketch I am using that is able to collect 1000 samples at 1000Hz using I2C (However I cannot make it run faster than what I would like).

General feedback from your original sketch would be the following:

utilize a variable to read the timer functions provided by Arduino (ergo millis() or micro()),

Serial functions take a lot longer than 1millisecond to complete,

the delay function should be avoided as it causes more problems than it solves.