Can I store a byte array in EEPROM un order to save RAM?

Hello, I just started using Arduino and I was wondering if I could use the EEPROM to store a byte array un order to save some ram, I'm working in a school project that registers in and outs with rfid and stores it in an sd card and when requested send the data trough udp, what I want to do is to store the sd data in the EEPROM instead of in a RAM buffer to then send it trough udp. Is that possible? If not what do you recommend me to do? I will need some hundreds of bytes.

EEPROM is for small amounts of data that need to be stored persistently. The main caveat is that EEPROM wears out if you write to it frequently - it's mainly used for settings. You could do what you have described with eeprom, but why would you if you have an sd card?

So, using it to "save RAM" - that's not really what it's for. It's for saving values that need to be kept when you reset or power down the device.

But, if your device gets powered down occasionally, and you want to leave it sitting there with no SD card in it, and the data needs to be saved - yeah, this should work just fine. Hundreds of bytes is no problem. More than a couple of K might be, depending on what Arduino you have.

I store byte arrays in progmem

Data in EEPROM (or PROGMEM for that matter), still needs to be moved into RAM in order to use it.

INTP: I store byte arrays in progmem

I guess thst that is data that is not frequently changing; I have the feeling that @chal7401 wants to store changing data.

Which brings me to the point that it's not quite clear to me how OP thinks that RAM can be saved? After all anything that has to be transferred over udp will have to go through RAM.

Maybe OP should show the code; it might be full of text strings and storing them in PROGMEM will do the trick.

Instead of internal EEPROM, external EEPROM or FRAM can be considered. It wll respectively ease or completely solve the problem of wearing out the internal EEPROM.

Short answer is you can

Long answer is your gains will depend - explain what you want to do, this might not be the only option (PROGMEM) and it would make sense only if you use subpart of that array at run time otherwise you will need to bring it in memory anyway. If you plan to access the EEPROM on demand, this is also super slow compared to RAM so there are performance considerations to this too.

Post your code and maybe someone can make another suggestion. Your main storage is the SDcard so you should not need to use a large array in RAM to hold data, you simply have to ensure that the captured data is more directly written to the SDcard. If you are generally having problems with RAM (and the SD card driver eats up alot) you can look at other things like using the F() macro for constant strings like in messages e.g.

Serial.println( F("This message is stored in Flash memory and not RAM"  ) ) ;

6v6gt: you can look at other things like using the F() macro for constant strings like in messages e.g.

Serial.println( F("This message is stored in Flash memory and not RAM"  ) ) ;

I tried to keep it a little more generic as we don't know the code yet ;)

I haven’t write entire the code yet but if it helps, every time an rfid is placed in the reader it will store an entry like this on the SD “user has arrived -hour” an the SD card will store múltiple entries like this one and when requested send all of them, so I can’t use progmem.

This is a piece of code that I wrote just for testing writing in sd and then sending it, but the final program will include data in the SD card every now and then, and send all the data when requested, I’m thinking about storing the data in the pc when requested and clear the data in the arduino since it is not needed anymore. Also I’m using a mega 2560 with an ethernet/SD shield.

#include <SPI.h>
#include <SD.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
char Buffer[90];
byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02};
IPAddress ip(192, 168, 1, 65);
unsigned int packetsize;
EthernetUDP udp;

void setup() {
  pinMode(10,OUTPUT);
  digitalWrite(10, HIGH);
  Serial.begin(9600);
  while(!Serial){
  }
  Serial.println("Buscando tarjeta...");
  if(!SD.begin(4)){
    Serial.println("No se encontro tarjeta");
    return;
  }
  Serial.println("Tarjeta encontrada");
  String texto;
  File dataf = SD.open("ENTR.txt", FILE_WRITE);
  if(dataf){
    for(int i = 0; i < 3; i++){
      texto = "valor ";
      texto += i;
      dataf.println(texto);
    }
    dataf.close();
    Serial.println("Listo");
  }
  else{
    Serial.println("Error al abrir el archivo");
  }
  Ethernet.begin(mac, ip);
  udp.begin(8000);
}

void loop() {
  if(udp.parsePacket()){
    udp.read(Buffer, 90);
    if(Buffer[0] = 'h'){
      File dataf = SD.open("ENTR.txt"); 
      while(dataf.available()){
        dataf.read(Buffer, 90); 
      }
      dataf.close();
      udp.beginPacket(udp.remoteIP(), 8002);
      udp.write(Buffer, 90);
      udp.endPacket();
      
    }
  }

If you stream the data such as to an online database, then you don't have to worry about local storage and later accessing

INTP: If you stream the data such as to an online database, then you don't have to worry about local storage and later accessing

Till the network is down.

chal7401:
This is a piece of code that I wrote just for testing writing in sd and then sending it, but the final program will include data in the SD card every now and then, and send all the data when requested, I’m thinking about storing the data in the pc when requested and clear the data in the arduino since it is not needed anymore. Also I’m using a mega 2560 with an ethernet/SD shield.

#include <SPI.h>

#include <SD.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
char Buffer[90];
byte mac = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02};
IPAddress ip(192, 168, 1, 65);
unsigned int packetsize;
EthernetUDP udp;

void setup() {
 pinMode(10,OUTPUT);
 digitalWrite(10, HIGH);
 Serial.begin(9600);
 while(!Serial){
 }
 Serial.println(“Buscando tarjeta…”);
 if(!SD.begin(4)){
   Serial.println(“No se encontro tarjeta”);
   return;
 }
 Serial.println(“Tarjeta encontrada”);
 String texto;
 File dataf = SD.open(“ENTR.txt”, FILE_WRITE);
 if(dataf){
   for(int i = 0; i < 3; i++){
     texto = "valor ";
     texto += i;
     dataf.println(texto);
   }
   dataf.close();
   Serial.println(“Listo”);
 }
 else{
   Serial.println(“Error al abrir el archivo”);
 }
 Ethernet.begin(mac, ip);
 udp.begin(8000);
}

void loop() {
 if(udp.parsePacket()){
   udp.read(Buffer, 90);
   if(Buffer[0] = ‘h’){
     File dataf = SD.open(“ENTR.txt”);
     while(dataf.available()){
       dataf.read(Buffer, 90);
     }
     dataf.close();
     udp.beginPacket(udp.remoteIP(), 8002);
     udp.write(Buffer, 90);
     udp.endPacket();
     
   }
 }

OK. But where in this code do you see excessive RAM being used up ? That was the main subject of the first post. Apart form one String definition in setup(), I don’t see any big risk.

sterretje:
Till the network is down.

K