@@ -198,8 +198,18 @@ void StartADXL355() {
198
198
Serial.println (" Initializing sensor" );
199
199
adxl355.initializeSensor (range, odr_lpf, debug);
200
200
Serial.println (" Calibrating sensor" );
201
- adxl355.calibrateSensor (5 , debug);
201
+ adxl355.calibrateSensor (20 , debug); // This has been increased to make traces start closer to zero
202
202
Serial.println (" ADXL355 Accelerometer activated" );
203
+
204
+ bool bDiscardInitialADXLreadings = true ;
205
+ while ( bDiscardInitialADXLreadings ) {
206
+ adxstatus = adxl355.getStatus ();
207
+ if (adxstatus & Adxl355::STATUS_VALUES::FIFO_FULL) {
208
+ adxl355.readFifoEntries ( (long *)fifoOut ) ;
209
+ bDiscardInitialADXLreadings = false ;
210
+ }
211
+ }
212
+ Serial.println (" ADXL355 Accelerometer first samples discarded" );
203
213
}
204
214
else {
205
215
Serial.println (" Unable to get accelerometer" );
@@ -866,35 +876,29 @@ void loop() {
866
876
// Do some STA / LTA math here...
867
877
// ...
868
878
if ( StaLtaQue.isFull () ) {
869
- // // find offset
879
+ // ///////////////// find offset ////////////////
870
880
int queCount = StaLtaQue.getCount ( );
871
- // But why are the first two z samples bad ?
872
- // Start from 2 to compensate
873
- for (int idx = 2 ; idx < queCount; idx++) {
881
+
882
+ for (int idx = 0 ; idx < queCount; idx++) {
874
883
AccelReading AccelRecord;
875
884
if ( StaLtaQue.peekIdx ( &AccelRecord, idx) ) {
876
885
sample[0 ] = AccelRecord.x ;
877
886
sample[1 ] = AccelRecord.y ;
878
887
sample[2 ] = AccelRecord.z ;
879
- // But why are the first two z samples bad ?
880
- // Serial.printf(".sample[2] = %f ", sample[2]);
881
888
for (int j = 0 ; j < 3 ; j++) {
882
889
sampleSUM[j] += sample[j];
883
890
}
884
891
}
885
892
}
886
- // Serial.printf(".offset = ");
887
893
for (int j = 0 ; j < 3 ; j++) {
888
894
offset[j] = sampleSUM[j] / (QUE_len-2 );
889
- // Serial.printf( " %f ", offset[j]);
890
895
}
891
- // Serial.printf("\n");
892
-
893
- // // find lta
896
+
897
+ // ///////////////// find lta /////////////////
894
898
sampleSUM[0 ] = 0 ;
895
899
sampleSUM[1 ] = 0 ;
896
900
sampleSUM[2 ] = 0 ;
897
- for (int idx = 2 ; idx < LTA_len; idx++) {
901
+ for (int idx = 0 ; idx < LTA_len; idx++) {
898
902
AccelReading AccelRecord;
899
903
if ( StaLtaQue.peekIdx ( &AccelRecord, idx) ) {
900
904
sampleABS[0 ] = abs ( AccelRecord.x - offset[0 ] );
@@ -905,13 +909,11 @@ void loop() {
905
909
}
906
910
}
907
911
}
908
- // Serial.printf(".sum32abs = ");
909
912
for (int j = 0 ; j < 3 ; j++) {
910
913
ltav[j] = sampleSUM[j] / (LTA_len-2 );
911
- // Serial.printf( " %f ", sampleSUM[j]);
912
914
}
913
-
914
- // // find sta
915
+
916
+ // ////////////////// find sta ///////////////////////
915
917
sampleSUM[0 ] = 0 ;
916
918
sampleSUM[1 ] = 0 ;
917
919
sampleSUM[2 ] = 0 ;
@@ -932,12 +934,13 @@ void loop() {
932
934
if ( bPossibleEarthQuake==false ) {
933
935
if ( stalta[j] >= thresh ) {
934
936
// Whoa - STA/LTA algorithm detected some anomalous shaking
935
- Serial.printf (" %f = %f / %f (%i) s0\n " , stalta[j], stav[j], ltav[j], j );
937
+ Serial.printf (" STA/LTA = %f = %f / %f (%i)\n " , stalta[j], stav[j], ltav[j], j );
938
+ bPossibleEarthQuake = true ;
936
939
}
937
940
}
938
941
}
939
942
940
- // // find sta / lta for the other 31 samples but without doing the summing again
943
+ // // find STA/LTA for the other 31 samples but without doing the summing again
941
944
942
945
for (int idx = LTA_len+1 ; idx < QUE_len; idx++) {
943
946
AccelReading AccelRecord;
@@ -966,7 +969,7 @@ void loop() {
966
969
if ( bPossibleEarthQuake==false ) {
967
970
if ( stalta[j] >= thresh ) {
968
971
// Whoa - STA/LTA algorithm detected some anomalous shaking
969
- Serial.printf (" %f = %f / %f (%i)\n " , stalta[j], stav[j], ltav[j], j );
972
+ Serial.printf (" STA/LTA = %f = %f / %f (%i)\n " , stalta[j], stav[j], ltav[j], j );
970
973
bPossibleEarthQuake = true ;
971
974
}
972
975
}
0 commit comments