Storing data on the nano ble with tiny learning machine

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

The two most popular options for saving sensor data are to send it out the serial port to be saved in a file on a PC (use a terminal program like PuTTY or Teraterm), or use an SD card module.

The inexpensive Sparkfun OpenLog can also be used to save arbitrary serial data on an SD card.

For short range data transfer, BLE could be used, but would a lot of trouble to set up for many different variables.

I can not have it plugged into a PC as it is for a model rocket. I do not have the SD card module. Is there a way I can store it on the computer until I can plug it into a PC?

You could store the data in arrays in dynamic memory, but 256 kB is not much.

The program would have to contain code for transferring the array data to the PC, and if power is lost for one millisecond, while removing the package from the rocket and connecting it to the PC, all data will be instantly lost.

It is almost certainly not worth your time and effort to go that route.

const unsigned long dataCollectionDuration = 5000; 
delay(100);

It looks like you are trying to store 50 data points. If all the data at a point were packed into a struct, how many bytes need storing at each point. How fast can the IMU be read?

There is1 MB of non volatile flash storage you can use on the Nano BLE Sense

You may be able to use KV store or one of the file storing api's to place it in flash. KVStore.h is quite simple to use, but it is designed for shorter key value pairs and I'm not clear on how much of the available Non Volatile Storage space it can use. If you have a struct called dataSaved, it can be stored with
kv_set(Key3, (uint8_t*)&dataSaved, sizeof(dataSaved), 0);
It will be an experiment to go with 500 keys and see what you can do.

https://os.mbed.com/docs/mbed-os/v5.15/apis/kvstore.html
https://os.mbed.com/docs/mbed-os/v6.12/apis/data-architecture.html

Data storage model rocket is not a simple task. Have you researched what has been done by others?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.