Question from a noob: Can I upload a .csv file together with the cpp code?

Hello,

My experience with MCU programming is not that much. I mainly have just worked with digital / analog read / write or I2C communications using something like Arduino or esp32 boards (I think it’s called Arduino Framework? because they seem to share the same code even if esp32 boards are not Arduino boards)

I am wondering, can I upload a CSV file together with my program, and when the MCU runs the code, the code will go to the CSV file to grab some information?

For example (pseudocode)

void setup(){
int loopCount = 0;
}

void loop(){
String a = grabValueFromCSV(loopCount); // get the data in row #loopCount in the CSV file 
// Do something with a
loopCount++;
}

Or, is it possible to save any data (e.g. sensor’s reading) into a CSV file in flash and later copy that file out via a debugger?

I don’t know if a file system exists in the world of embedded systems but I think it doesn’t hurt to ask!

Thank you!

1 Like

The ESP32 has built-in libraries for opening a filesystem (e.g. with LittleFS) on parts of the free flash (most ESP32 have 4MByte of flash that needs to fit everything).

See:

Thank you for the information!
I noticed the LittleFS library is under “ESP32 Libraries”, which says “arduino-esp32 includes libraries for Arduino compatibility”
Does this mean any code using Arduino Framework can use libraries under this category?
In that case, I can also use this library with Amtel or nRF MCUs?

If you wan to embed a fixed csv file to map numbers (loop counter) to strings, another option is to embed the data in the code. For example

const char* my_table[] {
   "string 0",
   "string 1",
   ...
};

Compile it with your program and then find the string like this:

const char* string = my_table[loop counter];

Thanks for your reply. Yes, that is my current solution. I was just wondering if there is any more elegant/ proper way of doing this.

After all, it is much easier to just swap or change the CSV file than to edit the source code every time I need to make changes.

One option is to write a python script that will read the csv and generate the .c file with that data.