I'm currently building a midi switching device, the device has 6 buttons, in effect I would like to assign 4 buttons to some midi program changes, and 2 buttons to 'banks' which will cycle through different presets (i.e different program changes) for each button.
I want this to be fully customisable by the user, so I essentially would like to create some set format (preferably in JSON format), and store that in a config file which it read whenever the Arduino is booted.
The problem I'm having is how to store a non-code type file on the Arduino, and be able to read/write access it. Writing to a file isn't that important for now, but it could be in the future if a user would like to create their own presets.
Can anyone point me in the right direction for storing config files on the device and reading from them in the sketch to extract the data? If there is some alternative method you think may be better/more performant I'd be keen to hear it!
Using JSON (or YAML) for config files is nice but these formats have a lot of overhead. Maybe you want to think about storing the data in binary form instead.
If your configuration data is a simple list of objects of the same type, this should be relatively easy to do.
For a basic Arduino (like UNO, Nano, Mega, Leonardo, Micro, Mini) your main choices for non-volatile memory (memory that retains its value with the power off) are EEPROM and SD Card. You don't need any extra hardware with EEPROM but it is VERY limited so a human-readable format like JSON will not hold much data. An SD Card, on the other hand, holds gigabytes of data but requires an SD Card adapter.
If you have a Nano/Uno/Mega, don't think of EEPROM as storing files, but rather as a place to store and recover data structures from. Create a configuration struct, and use the .put and .get actions to interact with EEPROM. See reference material and tutorials for further clarification.
Yes, on the Nano, 1024 bytes is it. All depends on the volume and complexity of the data you want to store and retrieve, as to whether that's enough space.
The Teensy 4.1 has an SD card port so I think route will be to use that, though for the future it would be nice not to require an SD card adapter, thanks for the idea!
FYI, I store a struct of structs on my Nano to configure a network of RS485 nodes. The software is universal, all the node needs to know is what it's ID is for it to self-configure in setup(). It works beautifully. Some of the rest of my code is still WIP, but I've started forgetting the EEPROM stuff, haven't touched it in months.