Issues with EEPROM

Hello everyone , I am working on a project where I have to write the values from 16 different "paths" to an SD CARD,and i've managed to do that.
But now I must use EEPROM to read the values from each 16 paths on the start up of the arduino card and write them on EEPROM when I stop the program.
For example if I have for the 7th path a value of 20 then it will be stored and if I change it then the EEPROM will overwrite it.
I know this is a little bit confused but maybe a bit of code and a few screens will help to understand my problem.
So here is the code:

#include <SPI.h>
#include <SD.h>
#include <SoftwareSerial.h>
#include <EEPROM.h>

File myFile;

SoftwareSerial BTSerial(6, 7); // RX | TX

int addr = 0;
int val;
int d=2;
int voie=0;
int valeur=0;
int ct=0;
String select="no selection";
int displaythis=1;

void setup()
{
  Serial.begin(9600);
  Serial.println("ENTER AT Commands:");
  
  
  BTSerial.begin(9600);  //gets changed to 115200 when the module is changed

while (!Serial) 
  {
    ; 
  }


  Serial.print("SD CARD IS INITIALISING...");

  if (!SD.begin(4)) {
    Serial.println("Error!");
    while (1);
  }
  Serial.println("Done.");


////////////////////////////////////////////////////////////////////
    // re open the document to verify that everything is written
  myFile = SD.open("test.txt");
  if (myFile) {
    Serial.println("test.txt:");

    //read until there is nothing else to read
    while (myFile.available()) {
      Serial.write(myFile.read());
    }
    // close the doc:
    myFile.close();
  } else {
    // if the doc won't open then print error
    Serial.println("error while oppening test.txt");
  }
}

 





void loop()
{
   if (BTSerial.available())
   {

    
    d=BTSerial.read();
    
    if (d==255 or d==254) //working on 4 bytes 255=Start byte and 254=End byte 
                          //thanks to this we can see the number of the output as well as what we put in it
    {
     //Serial.println ("start/end");
      displaythis=1;
      ct=0;
    }
    else
    {
      ct=ct+1;
     // select the output
     if (ct==1)
     {
      //Serial.print("voie:");
      //Serial.println(d,DEC);
      voie=d;
      
     }
      if (ct==2)
     {
     // Serial.print("valeur:");
     // Serial.println(d,DEC);
      valeur=d;
     select="voie:"+String(voie)+" valeur:"+String(valeur);
     }

    
    }
    
   
   }
   else
   {

    delay (1000);
    
    if (displaythis==1)
    {
    Serial.println (select);
    
    // module SD card code
   // open the doc(only one at the time is possible)
  // so we are closing before openning)
  myFile = SD.open("test.txt", FILE_WRITE);

  // if the docs opens then write on it
  if (myFile) {
    Serial.print("write on test.txt...");
    myFile.println(select="voie:"+String(voie)+" valeur:"+String(valeur));
   
   
    // close the doc:
    myFile.close();
    Serial.println("done.");
  } else {
    // if it doesn't open then error
    Serial.println("erreur while opening test.txt");
  }


   
    displaythis=0;
    }
    
   }
  
    if (Serial.available())
    {
      BTSerial.write(Serial.read());
      
     
    }



  
  
  
  int val = Serial.read();
   EEPROM.write(addr,displaythis);

  addr = addr + 1;
  
  if (addr == EEPROM.length()) {
    addr = 0;
  }

  delay(100);

 EEPROM.read(addr);

  Serial.println(addr);
  Serial.print("\t");
 Serial.println(displaythis);
  Serial.println();
  
  
  delay(500);
   
}

So what i'm trying to do is that if we change the values of a certain path and then close the app and starting it again it will show the last values we've entered and that for each paths so it's not a datalog like what i've done with the SD Card at the beginning of my program .

But for now i've only managed to write voie 0 = 0 (by the way voie means path) and what i'm trying to do is to get on to the next one so voie 1= value1 voie 2= value 2 and so on.

So this is the SD card part (there is no need to read all those values but i was just making sure it was really writing on the sd card):

And this is the EEPROM part:
eeprom.PNG

eeprom.PNG

Some general advice

Don't use Strings (uppercase S) in your program as they have a reputation for causing problems in environments with limited memory such as most Arduinos. Instead use zero terminated arrays of chars, confusingly known as strings (lowercase s)

Before going any further using the EEPROM have a look at the EEPROM.put() and EEPROM.get() functions which allow you to save and read data of any kind. I suspect that they will be useful.

Your use of the word path is confusing. Can you please expand on what you are trying to do ?

UKHeliBob:
Some general advice

Don't use Strings (uppercase S) in your program as they have a reputation for causing problems in environments with limited memory such as most Arduinos. Instead use zero terminated arrays of chars, confusingly known as strings (lowercase s)

Before going any further using the EEPROM have a look at the EEPROM.put() and EEPROM.get() functions which allow you to save and read data of any kind. I suspect that they will be useful.

Your use of the word path is confusing. Can you please expand on what you are trying to do ?

Well the project I have to complete is a circuit-breaker.
I have to simulate loads on 16 ways(the loads could be a tv, a fridge or whatever you want).And since we don't wan't to waste any money or power we are simulating these loads on arduino.

Balou38:
Well the project I have to complete is a circuit-breaker.
I have to simulate loads on 16 ways(the loads could be a tv, a fridge or whatever you want).And since we don't wan't to waste any money or power we are simulating these loads on arduino.

I wouldn't use a resource known to cause instability problems on a safety-critical device, simulated or real.

YMMV

Why? You have an SD card. Make a new file called settings.txt or whatever you want. Always read that file in setup() and set the initial settings.

EEPROM.write and EEPROM.read write bytes; as indicated in the first reply, EEPROM.put and EEPROM.get can be used for other datataypes.

Be aware that an eeprom cell can only be written 100,000 times; your code seems to be writing unconditionally.

void loop()
{
  ...
  ...


  EEPROM.write(addr, displaythis);

  addr = addr + 1;

  if (addr == EEPROM.length()) {
    addr = 0;
  }

  ...
  ...
}

You have somewhere a delay of one second (but not always); after 1000 seconds (assuming 1K eeprom), you will rewrite the same cell again. You can count how long your eeprom will survive.

EEPROM.put will not update a cell if there is no change.

MorganS:
Why? You have an SD card. Make a new file called settings.txt or whatever you want. Always read that file in setup() and set the initial settings.

This is exactly what I was going for in the beginning, but the people that gave me this project want me to use eeprom...

Why? Is it supposed to function when the card is removed?

It is like buying a car with a powerful engine and then using the starter motor to drive places.

MorganS:
Why? Is it supposed to function when the card is removed?

It is like buying a car with a powerful engine and then using the starter motor to drive places.

No not even.
I don't really understand why they told me to work with EEPROM.

Hello everyone, I am beginners for using arduino in-built EEPROM. I have a small doubt in this code.
in this code, I read a potentiometer value via PIN=A0. I read a push button signal via digital pin=4. My aim is, when I press the push button the corresponding value will be stored in internal EEPROM. After that, I want to get the value stored in EEPROM with the help of address. The address are provided via Serial monitor.

With the help of address the corresponding value stored in EEPROM will be display on the Serial monitor.
In this output I get a wrong value instead of stored value in internal EEPROM. I am using Arduino Uno Board.

Below I attached my program and output, kindly check it out,

#include <EEPROM.h>
int n, i = 0, p;

void setup() {
Serial.begin(9600);
pinMode(4, INPUT_PULLUP);
}

void loop() {
p = analogRead(A0);

if (digitalRead(4) == LOW) {
Serial.print("THE ADDRESS IS = ");
Serial.println(i);
Serial.print("THE VALUE OF POTENTIOMETER IS = ");
Serial.println(p);
EEPROM.put(i, p);
delay(4000);
i++;
}
if (Serial.available() > 0) {
Serial.println(“GET THE VALUE STORED IN EEPROM”);
n = Serial.parseInt();
Serial.print("THE GIVEN ADDRESS IS = ");
Serial.println(n);
Serial.print("THE VALUE STORED IN CORRESPONDING ADDRESS OF EEPROM IS = ");
Serial.println(EEPROM.get(n, p));
}
if(i==EEPROM.length()){
i=0;
}

}

THE OUTPUT IS,

THE ADDRESS IS = 0
THE VALUE OF POTENTIOMETER IS = 779
THE ADDRESS IS = 1
THE VALUE OF POTENTIOMETER IS = 1000
THE ADDRESS IS = 2
THE VALUE OF POTENTIOMETER IS = 672
THE ADDRESS IS = 3
THE VALUE OF POTENTIOMETER IS = 453
GET THE VALUE STORED IN EEPROM
THE GIVEN ADDRESS IS = 0
THE VALUE STORED IN CORRESPONDING ADDRESS OF EEPROM IS = -6133
GET THE VALUE STORED IN EEPROM
THE GIVEN ADDRESS IS = 2
THE VALUE STORED IN CORRESPONDING ADDRESS OF EEPROM IS = -14944
GET THE VALUE STORED IN EEPROM
THE GIVEN ADDRESS IS = 3
THE VALUE STORED IN CORRESPONDING ADDRESS OF EEPROM IS = 453

 i++;

An int takes 2 bytes of storage so after saving a value you need to increase the storage location by 2, not 1

You also need to adjust the location when reading from EEPROM or enter the real address

@Ganesh2807: Why did you start a new thread after hijacking this one? Are you looking for a time out? Keep this stuff up, and it WILL happen.