The following is the code I have so far. I am trying to set it to save the data as it collects it. How do I do this? I have the ardunio nano BLE 33 sense that comes in the tiny learning machine package. I know the usual library EEPROM.h doesn't work with the nano. I do not have an external SD card to use.
#include <Arduino_LSM9DS1.h>
#include <Arduino_LPS22HB.h>
const int thresholdValue = 2; // Threshold value for sensor input to start data collection
const unsigned long dataCollectionDuration = 5000; // Data collection duration in milliseconds (5 seconds in this example)
unsigned long dataCollectionStartTime = 0; // Variable to store the start time of data collection
bool dataCollectionStarted = false; // Flag to indicate if data collection has started
void setup() {
Serial.begin(9600); // Initialize serial communication
while(!Serial);
Serial.println("Started");
//: Initialization of Accelerometer
if(!IMU.begin()) {
Serial.println("Failed to initialize IMU!");
while(1);
}
//: Initialization of Barometer
if(!BARO.begin()) {
Serial.println("Failed to initialize pressure sensor!");
while(1);
}
Serial.print("Accelerometer sample rate = ");
Serial.print(IMU.accelerationSampleRate());
Serial.println(" Hz");
Serial.println();
Serial.println("Acceleration in g's");
Serial.println("X\tY\tZ");
}
void loop() {
// Read the sensor input
float x, y, z;
if(IMU.accelerationAvailable()) {
IMU.readAcceleration(x, y, z);}
// Check if the sensor value is greater than or equal to the threshold
if (abs(z) >= thresholdValue) {
if (!dataCollectionStarted) {
dataCollectionStarted = true;
dataCollectionStartTime = millis(); // Record the start time
Serial.println("Data collection started");
}
// If data collection has started and the set duration hasn't elapsed, proceed with recording data
else if (millis() - dataCollectionStartTime <= dataCollectionDuration) {
Serial.print('\t');
Serial.print(x);
Serial.print('\t');
Serial.print(y);
Serial.print('\t');
Serial.println(z);
//: Reading Barometer Pressure:
float pressure = BARO.readPressure();
//: Printing Pressure Sensor Value:
Serial.print("Pressure =");
Serial.print(pressure);
Serial.print(" kPa ");
//: Converting Pressure to Altitude in Feet
float altft = (1-pow(((pressure*1000)/(101325)),(1/5.255)))*200000.45;
float altm = altft*0.3048;
Serial.print(" Altitude [m] ");
Serial.print(altm);
}
}
// If the set duration has elapsed, stop data collection
if (dataCollectionStarted && millis() - dataCollectionStartTime > dataCollectionDuration) {
dataCollectionStarted = false;
Serial.println("Data collection stopped");
}
delay(100);
}