float time1,time2,time3,diff_time;
int16_t AX=0;
int16_t AY=0;
int16_t AZ=0;
int16_t GX=0;
int16_t GY=0;
int16_t GZ=0;
float aX_Old=0;
float aY_Old=0;
float aZ_Old=0;
//float test;
float diff_X=0;
float diff_Y=0;
float diff_Z=0;
//#include <ArduinoBLE.h>
#include <Arduino_LSM9DS1.h>
const float accelerationThreshold = 0.4; // threshold of significant in G's
const int numSamples = 119;
int samplesRead = numSamples;
void setup() {
Serial.begin(115200);
while (!Serial);
if (!IMU.begin()) {
Serial.println("Failed to initialize IMU!");
while (1);
}
// print the header
Serial.println("aX,aY,aZ,gX,gY,gZ");
}
void loop() {
float aX, aY, aZ, gX, gY, gZ;
// wait for significant motion
while (samplesRead == numSamples) {
if (IMU.accelerationAvailable()) {
// read the acceleration data
IMU.readAcceleration(aX, aY, aZ);
//IMU.readAcceleration(gX, gY, gZ);
diff_X=fabs(aX-aX_Old);
diff_Y=fabs(aY-aY_Old);
diff_Z=fabs(aZ-aZ_Old);
// check if it's above the threshold
if (diff_X >= accelerationThreshold && diff_Y >= accelerationThreshold && diff_Z >= accelerationThreshold ) {
// reset the sample read count
samplesRead = 0;
break;
}
}
}
// check if the all the required samples have been read since
// the last time the significant motion was detected
while (samplesRead < numSamples) {
// check if both new acceleration and gyroscope data is
// available && IMU.gyroscopeAvailable()
time1=millis();
if (IMU.accelerationAvailable() && IMU.gyroscopeAvailable()) {
// read the acceleration and gyroscope data
IMU.readAcceleration(aX, aY,aZ);
IMU.readGyroscope(gX, gY, gZ);
samplesRead++;
AX=(int16_t)(aX*100);
AY=(int16_t)(aY*100);
AZ=(int16_t)(aZ*100);
GX=(int16_t)(gX*100);
GY=(int16_t)(gY*100);
GZ=(int16_t)(gZ*100);
Serial.println(aX);(uint8_t*)
// print the data in CSV format*/
Serial.write((uint8_t)(AX >> 8)); Serial.write((uint8_t)(AX & 0xFF));
Serial.write((uint8_t)(AY >> 8)); Serial.write((uint8_t)(AY & 0xFF));
Serial.write((uint8_t)(AZ >> 8)); Serial.write((uint8_t)(AZ & 0xFF));
Serial.write((uint8_t)(GX >> 8)); Serial.write((uint8_t)(GX & 0xFF));
Serial.write((uint8_t)(GY >> 8)); Serial.write((uint8_t)(GY & 0xFF));
Serial.write((uint8_t)(GZ >> 8)); Serial.write((uint8_t)(GZ & 0xFF));
/*
Serial.print(aX, 3);
Serial.print(',');
Serial.print(aY, 3);
Serial.print(',');
Serial.print(aZ, 3);
Serial.print(',');
Serial.print(gX, 3);
Serial.print(',');
Serial.print(gY, 3);
Serial.print(',');
Serial.println(gZ, 3);*/
if (samplesRead == numSamples) {
// add an empty line if it's the last sample
Serial.println();
time2=millis();
diff_time=time2-time1;
Serial.println(diff_time);
}
}
}
aX_Old=aX;
aY_Old=aY;
aZ_Old=aZ;
}
Hi there, I am trying to increase the display of my IMU values through the serial port. The Serial.print function limits me.
I changed the header files for a 952Hz sampling rate of my gyroscope and accelerator.
Now i want to use Serial.write to increase the serial printing, unfortunatly the data are not readable in the serial port. I need to display the data.
Do you know how I could read my data in order to display it "-0.349,-0.461,1.442,9.399,-2.808,-6.226"?
Thank you for your help ![]()