Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Messages - JKaechler42

Pages: 1
General Discussion / Sequential filenames on the SD Card
« on: July 16, 2021, 10:31:59 PM »
I am working up a sketch to log data for model rocket flights. I have a TinyZero with the accelerometer. I have the accelerometer working, plus temperature and milliseconds.  I have an SD card module on order, and I need to work out the code to create a .CSV filename with sequential numbers.  I dont much care about the numbers, so much as I care about not overwriting the data from the previous flight the next time the unit is powered on.  And I want a separate CSV file for each flight.

Can anyone point me at a guide for how to program such a thing?  Or better yet a sample of code from someones project where the accomplish the same thing?


Code: [Select]
//Model Rocket Data Logger - Built on TinyCircuits TinyZero with Accelerometer
//Accelerometer data in values of 'G', Temperature in 'C', Pressure, and time stored on SD card as a .CSV file
#include <Wire.h>         // For I2C communication with sensor
#include "BMA250.h"       // For interfacing with the accel. sensor
#include <SPI.h>
#include <SD.h>

// Accelerometer sensor variables for the sensor and its values
BMA250 accel_sensor;
int x, y, z, runtime;
int AccelX, AccelY, AccelZ;
double temp;
String dataString = "";
char filename[16];
const int chipSelect = 10;

//////////////////////////////////////Setup Section////////////////////////////////////////////////////////////////////////////
void setup() {
digitalWrite(LED_BUILTIN, HIGH);

dataString += " Milliseconds , Accel Z , Accel X , Accel Y , Temp , Pressure";
// Set up the BMA250 acccelerometer sensor
accel_sensor.begin(BMA250_range_16g, BMA250_update_time_64ms);

////////////////////////////////////Data Wrangling//////////////////////////////////////////////////////////////////////////////
void loop() {;//This function gets new data from the acccelerometer
float  x = accel_sensor.X;
float  y = accel_sensor.Y;
float  z = accel_sensor.Z;
temp = ((accel_sensor.rawTemp * 0.5) + 24.0);
float AccelX = (x/32);
float AccelY = (y/32);
float AccelZ = (z/32);
float runtime = millis();

//////////////////////////////////Output Section///////////////////////////////////////////////////////////////////////////////
SerialUSB.print("  Temperature(C) = "); SerialUSB.print(temp); SerialUSB.print("     Seconds: "); SerialUSB.println(runtime/100);
SerialUSB.print (" X Accel: "); SerialUSB.print(AccelX); SerialUSB.print (" Y Accel: "); SerialUSB.print(AccelY); SerialUSB.print (" Z Accel: "); SerialUSB.println(AccelZ);   

Pages: 1
SMF spam blocked by CleanTalk