How to write a bin file to the EEPROM using Arduino?

Today, I saw a comment on my video Arduino Nano I2C EEPROM programming tutorial asking how to write .bin file to external EEPROM. The tutorial actually had two buttons and external EEPROM connected to Arduino Nano(because it has low memory size), one for write and one for read operation. So at first, I was about to answer that he/she had to use the push button for write operation. But then I realized that he was not asking that but rather how to transfer .bin file to the EEPROM. I thought the .bin file should be opened with text editor, copy that text and then paste in the Arduino code which can be found in the original tutorial Arduino Nano I2C EEPROM programming tutorial. But this will not work because the text of the .bin are not human readable or more exactly not in ASCII format

SD card EEPROM Arduino Nano

So why would one store .bin file inside EEPROM? This is not what I have done. I found out that writing a .bin file to an external EEPROM allows you to store binary data that must persist even when the microcontroller is powered off. This technique is useful in embedded systems where large datasets, such as custom fonts or graphics for displays, audio waveforms, configuration parameters, game assets, or even machine learning model weights need to be accessed at runtime but don't fit within the microcontroller’s limited program memory. By storing such data externally in binary format, the main program can retrieve and use it as needed, enabling more flexible and memory-efficient designs.

So let's break this down step by step to clarify what a .bin file is, how it's used, and how it can be written to an external EEPROM using an Arduino Nano and I2C.

✅ What is a .bin file?

A .bin (binary) file is a file that contains data in raw binary format, not human-readable text. It’s often used to store firmware, configuration data, images, or any form of compiled data that will be read or interpreted by a machine, not a human.

  • Unlike .txt or .hex, .bin files don't use ASCII encoding.

  • You can open it with a text editor, but you'll see gibberish (weird characters), because the contents are raw bytes, not characters.

🤔 Can you open a .bin file with a text editor and copy the contents?

Technically yes, but practically no.

  • If you open a .bin file in a text editor, you'll see junk characters that don't make sense.

  • Copying that and pasting into code will not give you the actual binary content in byte form.

  • You must read the .bin file as raw bytes using a tool or code.

💡 How to write a .bin file to an external EEPROM with Arduino Nano?

You have to:

  1. Read the .bin file from somewhere (like a microSD card or upload via serial).

  2. Send its raw byte contents to the EEPROM over I2C.

📁 Method 1: Write .bin file from SD card to EEPROM

You can store the .bin file on an SD card and use the Arduino to read each byte and write to EEPROM.

🧰 What You Need

Hardware:

  • Arduino Nano (or Uno)

  • SD Card module (with 5V logic level shifter)

  • microSD card (formatted as FAT32)

  • I2C EEPROM (like 24LC256)

  • Jumper wires and breadboard


SD Card Module to Arduino Wiring

SD Card Module PinArduino Nano Pin
VCC5V
GNDGND
MISOD12
MOSID11
SCKD13
CS (Chip Select)D10

✅ Note: Most SD card modules have onboard logic level converters, so it's safe to power them with 5V.


🧠 EEPROM to Arduino Nano Wiring (I2C)

 

EEPROM PinArduino Nano Pin
SDAA4
SCLA5
VCC5V
GNDGND
WPGND

📂 SD Card File

  • Format the SD card as FAT32

  • Copy your file.bin into the root directory of the SD card


📜 Circuit Wiring Diagram

 SD card EEPROM Arduino Nano

 ✅ Arduino Code: Write .bin from SD to EEPROM

#include <Wire.h>
#include <SPI.h>
#include <SD.h>

#define EEPROM_ADDR 0x50

File binFile;
unsigned int address = 0;

void setup() {
  Serial.begin(9600);
  Wire.begin();

  if (!SD.begin(10)) {
    Serial.println("SD Card not found");
    return;
  }

  binFile = SD.open("file.bin", FILE_READ);
  if (!binFile) {
    Serial.println("Cannot open file");
    return;
  }

  while (binFile.available()) {
    byte b = binFile.read();
    writeEEPROM(address++, b);
    delay(5); // small delay for write cycle
  }

  binFile.close();
  Serial.println("Done writing BIN to EEPROM");
}

void loop() {}

void writeEEPROM(unsigned int addr, byte data) {
  Wire.beginTransmission(EEPROM_ADDR);
  Wire.write((addr >> 8) & 0xFF); // MSB
  Wire.write(addr & 0xFF);        // LSB
  Wire.write(data);
  Wire.endTransmission();
}

📁 Method 2: Upload .bin via Serial from PC to EEPROM

If you don’t use SD card, you can send the .bin from a PC over the serial port using a terminal like Tera Term, RealTerm, or a Python script.

🔄 Reading .bin back

To read from EEPROM and dump it into a .bin file:

  1. Read bytes over I2C

  2. Send them back to PC over Serial

  3. Save serial output using terminal or script

🧠 Summary

TaskPossible?How
Open .bin in text editor✔️But not readable, shows garbage
Copy/paste .bin contentNot useful — doesn't copy raw bytes properly
Write .bin to EEPROM✔️Use SD card or serial and I2C write code
Read EEPROM back as .bin✔️Read via I2C, save as binary over serial

I think this is enough for this entry. In the next blog post I will write about how to write bin file to external EEPROM using SD or Serial transfer method.

Post a Comment

Previous Post Next Post