Giter Site home page Giter Site logo

csveditor's Introduction

CSVEditor Library

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.

Features

  • 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.

API Reference

CSVEditor(String fileName, int chipSelectPin, bool debug)

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.

~CSVEditor()

This is the destructor for the CSVEditor object. It ensures that the file is closed when the object is destroyed.

void writeHeader(String header)

This function writes a header to the CSV file. It only writes the header if the file does not already exist.

void writeData(String data)

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.

String readLastRow()

This function reads and returns the last row of data from the CSV file.

void checkAndHandleFileSize()

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.

String readHeader()

This function reads and returns the header of the CSV file.

bool openFile(uint8_t mode)

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.

void closeFile()

This function closes the CSV file.

bool renameFile(File &file, const String &oldName, const String &newName)

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.

void debugMessage(const String &message)

This function prints a debug message to the Serial monitor if debug mode is enabled.

Example Usage

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

csveditor's People

Contributors

arefttt avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.