When to put data in a sketch or EEPROM?

I have written a sketch which uses some numeric data in a 2 x 10 table implemented as 2 arrays. It works fine, no problems there. BTW it runs standalone, only connected to the PC to upload the sketch.
However, from time to time I need to change one or more values in the table. At the moment I change the data in the sketch and re-upload the sketch.
My question is : Would there be any advantages in writing the table data to EEPROM and using a small PC application to make table changes?
In each case I need to connect the Arduino to a PC, run some PC software and make an upload. Is one method really better than the other, if so, WHY?

I would just modify the sketch because it's easier. You could use the EEPROM if you wanted to change the values without connecting the computer. But, that would require additional hardware for a user interface.

Thanks DVDdoug, I have no desire to add hardware for updating the tables. I’d much rather just connect a laptop when the table needs changing.

Make sure you have some reliable storage for your sketch. Github or some other source control system. You are going to forget about this thing for 2 years and then you need to change one value. If you've lost the original sketch then you must re-write it from scratch. Also store the .zip file you used to install the Arduino IDE, as future versions are not guaranteed to compile old code.

Tony,

I am planning to use a similar approach in a project I am porting over from a PIC design I did a few years back.

My Sketch uses a 4x4 array of integers. At startup, these values are loaded from EEPROM. During normal operation, these values can be changed via serial commands. One command is to write the array back to EEPROM. That way, I can update the data table without having to change the Sketch itself.

As I port the code from my PIC project, I have decided to store multiple sets of the commonly used data array values in EEPROM and index to them as needed. For my PIC program, I wrote a simple Visual BASIC program to read / edit / write the values in the table by communicating with the running Sketch. I will be using that same PC program again after the conversion.

For your project, if the changes are rare and minor, you could just open a serial terminal and send commands to change values in the table and then write the changes to EEPROM. I think it's a relatively minor programming addition that will prove its usefulness down the line.

My process in psuedo-code is as follows:

ReadStoredProfile()
{
  // Check CRC or Checksum of EEPROM storage area
  if (CRC_Good)
  {
    // Read table values into array.
  }
  else
  {
    // Set up some default values in the array
  }
}

WriteStoredProfile()
{
  // Copy array values to EEPROM while calculating CRC or Checksum
  // Write CRC or Checksum to EEPROM
}

So yes, I think you have a good approach. In my opinion, it has an advantage over hard programming the values into EEPROM in that you could make the changes in a non-development environment at any point in the future, if required.

John

John,

I decided to go the EEPROM route with a dedicated programme on a PC to update the EEPROM.

The Arduino code is as follows.

if serial connection then
tell PC to send data
update EEPROM
read EEPROM
send EEPROM data to PC for checking
(on PC
if data OK then
ShowMessage(“All OK, disconnect USB cable and reset Arduino”
endif )
else
Read EEPROM data
Run Arduino code in standalone mode
endif

The standalone mode will not run if connected to a PC.

It works fine and the PC programme is constructed to help select the values to download.

The main advantage of EEPROM is that it's independent of the programming environment. You can use any terminal program.

The disadvantage of PC connectivity via USB is that it most of the time resets the Arduino, something that is not always desired; there are work-arounds but they might make the uploading of sketches a little more complicated. Additional hardware is anonther way to work around the problem (either a serial interface that does not expose DTR or e.g. a bluetooth or network connection).