The CSVEditor library is a powerful and flexible tool for handling CSV files on an SD card. It provides a simple and efficient way to read, write, and manage CSV files in your Arduino projects.
- Easy Initialization: Initialize the library with the filename, chip select pin, and debug mode.
- Read and Write Operations: Easily write data or headers to the CSV file. Read the last row or the header of the CSV file.
- File Size Management: Automatically checks and handles the file size. If the file size exceeds the maximum limit, it creates a new file, writes the header and last row to the new file, and renames the old and new files.
- Debugging Support: If debug mode is enabled, the library will print helpful debug messages to the Serial monitor.
This is the constructor for creating a new CSVEditor object. It takes three parameters:
fileName
: The name of the CSV file.chipSelectPin
: The chip select pin for the SD card module.debug
: A boolean indicating whether debug mode is enabled.
This is the destructor for the CSVEditor object. It ensures that the file is closed when the object is destroyed.
This function writes a header to the CSV file. It only writes the header if the file does not already exist.
This function writes a string of data to the CSV file. Each call to this function will append the data to a new line in the file.
This function reads and returns the last row of data from the CSV file.
This function checks the size of the CSV file. If the file size exceeds MAX_FILE_SIZE
, it creates a new file, writes the header and last row to the new file, and renames the old and new files.
This function reads and returns the header of the CSV file.
This function opens the CSV file in the specified mode (FILE_READ
or FILE_WRITE
). It returns true
if the file was opened successfully, and false
otherwise.
This function closes the CSV file.
This function renames a file. It takes three parameters: a reference to a File
object, the old filename, and the new filename. It returns true
if the file was renamed successfully, and false
otherwise.
This function prints a debug message to the Serial monitor if debug mode is enabled.
#include "CSVEditor.h"
CSVEditor csvEditor("data.csv", 10, true);
void setup() {
Serial.begin(9600);
csvEditor.writeHeader("Temperature,Humidity");
}
void loop() {
String data = String(analogRead(A0)) + "," + String(analogRead(A1));
csvEditor.writeData(data);
delay(1000);
}