1
General Discussion / Re: Sequential filenames on the SD Card
« on: July 21, 2021, 04:10:55 AM »
Hello,
A clear example for indexed filenames can be found in the example project “Rocket Altimeter Logger”.
See https://tinycircuits.com/blogs/learn/130916679-rocket-altimeter-logger
under “Step two”, Altimeter_Datalogger.ino.
I have extended this principle to three digits in the following code part (only the first part of the .ino file) for a GPS application.
In this case it relates to a .txt file, but the indexing for .csv is the same.
See below.
Regards,
Willem
A clear example for indexed filenames can be found in the example project “Rocket Altimeter Logger”.
See https://tinycircuits.com/blogs/learn/130916679-rocket-altimeter-logger
under “Step two”, Altimeter_Datalogger.ino.
I have extended this principle to three digits in the following code part (only the first part of the .ino file) for a GPS application.
In this case it relates to a .txt file, but the indexing for .csv is the same.
See below.
Regards,
Willem
Code: [Select]
// Setup, Monitoring and Logging of ZOE GNSS:
// - U-blox ZOE-M8B GPS through HW UART (Serial)
// - Monitoring on SerialMonitorInterface of TinyZero
// - Logging on microSD card
//
// version 01: 29-11-2020
//
// version GPS_Monitor_ZOE_a
//
// Essential for ZOE GPS board application:
// - Secure ZOE GPS: SAFEBOOT_N and RESET_N to high to avoid problems
//
// version with NMEA GGA,GSA (2x), GSV (2 sets)and VTG at 1 Hz, GPS and GLONASS
//
//
//
// HWUART (Serial, 9600 baud -> 57600 baud)
//
// assumption: default GPS configuration at startup, so no settings in a battery buffered memory
// assumption: no I2C communication with GPS
// Monitoring and/or Logging
//
//
// - GNSSxxx.txt for text logging during setup (both UBX and NMEA) and NMEA strings afterwards. NMEA strings also readible with VisualGPSView
//
// - File is written in blocks of 512 bytes (after setup) from TinyZero to minimize micro SD waiting time
// - File numbers are automatically increased
// - File is opened in setup, but not closed, so last part of logging can be missed
//
//
#include <SD.h>
#define SerialMonitorInterface SerialUSB
const int chipSelect = 10;
int cardPresent,wG;
File GPSFile;
unsigned int i_skip1 = 0,b1_length;
int sd1_room=0;
// string to buffer output datafile
String buffer1 = "";
char Dat2File[]="GNSS999.txt";
char hold[]="999";
// The GPS connection is realized with a hardware serial port
#define Gps_serial Serial
void setup()
{
// Secure ZOE GPS: SAFEBOOT_N and RESET_N to high to avoid problems
pinMode(A2, OUTPUT);
pinMode(A3, OUTPUT);
digitalWrite(A2, HIGH);
digitalWrite(A3, HIGH);
int incomingByte = 0;// for incoming serial hex data
char incomingChar;// for incoming serial char data
int ubx;
Gps_serial.begin(9600);//will be set to higher baudrate lateron
SerialMonitorInterface.begin(115200);
// reserve 2kByte for buffer to cope with long waiting time of microSD card
buffer1.reserve(2048);
SerialMonitorInterface.print("Initializing SD card...");
// see if the card is present and can be initialized:
if (SD.begin(chipSelect)) {
SerialMonitorInterface.println("card initialized.");
cardPresent = true;
} else {
SerialMonitorInterface.println("Card failed, or not present");
cardPresent = false;
}
//So you can find different trials easier//
if (cardPresent) {
while(SD.exists((char*)Dat2File)){
hold[2]+=1;
if(hold[2]>9+48){
hold[1]+=1;
hold[2]=(0+48);
}
if(hold[1]>9+48){
hold[0]+=1;
hold[1]=(0+48);
}
if(hold[0]>9+48){
hold[0]=(0+48);
}
Dat2File[6]=hold[2];
Dat2File[5]=hold[1];
Dat2File[4]=hold[0];
}
}
if (cardPresent) {
GPSFile = SD.open((const char*)Dat2File, FILE_WRITE);
}
while (!SerialMonitorInterface && millis() < 5000); //This will wait until the Serial Monitor is opened or until 5 seconds has passed
// changing a number of u-blox M8 GPS configuration settings
..... etc ......