Problem: Upload Binary File to EEPROM

Hi @ all !

I try to upload a binary file from my PC to my arduino’s EEPROM. I searched the web for hours and did not find a solution.
My attempt:

void loop()
{
    int i = 64;   
   Serial.print("ready to read bytes and write bytes into eeprom: ");   
   char hex[2];
   
   while (i < 512)
   {
      if (Serial.available() > 0)
      {         
         byte b = Serial.read();
         
         Serial.print("Became: "); Serial.println(b, 10);
         delay(1);
                  
         EEPROM.write(i, b);
         i++;
      }
      else
         delay(1);
   }
   
   Serial.print("eeprom full!");
   
   while(true)
      delay(1000);
}

If i upload my test binary file (which has all values from 0 - 255 in a row) via GTKTerm or minicom, following output is generated:

Became: 1
Became: 2
Became: 3
Became: 4
Became: 5
… [everything right until:]
Became: 72
Became: 73
Became: 74
Became: 76
Became: 85
Became: 97
Became: 109
Became: 121
Became: 133
Became: 145
Became: 157

You see, there are many values missing.
So please guys, what am I doing wrong?

So long! -mindbyte

you might check for avrdude.exe and do the upload to EEPROM directly from PC?

So please guys, what am I doing wrong?

  • you did not post your whole code.
  • you print a lot while data comes in, your input buffer might overflow?
    try it without the print statements (the echo)...

Hello and thank you for your reply.
Sorry but this is the full source code. The rest is:

#include "EEPROM.h"

void setup()
{
   Serial.begin(19200);
}

In addition, I can not provide avrdude to upload binary data to eeprom.

EDIT:

Okay, my solution was to lower the baudrate. My GTKTerm sent the file too fast, input buffer ran over. Now it is working. Thank you.

you’re welcome,

You could also do the printing after the storage, it has some advantages.

void setup()
{
    Serial.begin(19200);
   Serial.print("ready to read bytes and write bytes into eeprom: ");   

   unsigned long start = millis();

    int i = 64; 
   char hex[2];
   
   while ( ( i < 512 ) && ( millis() - start ) < 120000UL) )  // timout after 2 minutes
   {
      if (Serial.available() > 0)
      {         
         byte b = Serial.read();
         EEPROM.write(i, b);
         i++;
      }
   }

  Serial.print("eeprom full! -> dump content");

  for (int i = 64; i< 512; i++)
  {
    Serial.print(i. DEC); 
    Serial.print(" :\t"); 
    Serial.println(EEPROM.read(i), DEC);  // read back is a guarantee it is saved in the EEPROM
   }

}

void loop(){}

Friend, I'm tottaly new in arduino and programming stuff.
But I reallyy need to upload a .bin file to a EEPROM.
Can you help me?
I understand you initialized the write protocol in arduino, after that you only use the GTKTerm software to uppload the binary file?

You shouldn’t hi jack a thread like this , you should start your own.
Have you looked at the example programs for the eeprom library ?

Why do you need to write, as a beginner to eeprom anyway ?