Skip to content

Ard Eeprom Put

DodaTech 1 min read

In this tutorial, you'll learn about Arduino EEPROM.put Writes Wrong Bytes. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.

The Problem

EEPROM.put() stores data that reads back incorrectly.

Quick Fix

Wrong

float val = 3.14159;
EEPROM.put(0, val);  // Works but beware of address overlap
Starting at address 0 and putting multiple values may overlap.
#include <EEPROM.h>

void setup() {
  Serial.begin(9600);
  
  int addr = 0;
  
  // Store multiple values with address tracking
  float pi = 3.14159;
  EEPROM.put(addr, pi);
  addr += sizeof(pi);  // 4 bytes
  
  int count = 42;
  EEPROM.put(addr, count);
  addr += sizeof(count);  // 2 bytes on AVR
  
  Serial.print("Next free address: ");
  Serial.println(addr);
}

void loop() { }
Next free address: 6

Prevention

Track addresses manually when putting multiple values. Each put() advances by sizeof(type). Use a struct to group related data. EEPROM.put() uses update-style logic (reads before write). Total EEPROM size depends on the board (Uno: 1024 bytes, Mega: 4096 bytes).

DodaTech engineers apply these same patterns across Doda Browser, DodaZIP, and Durga Antivirus Pro for production IoT reliability.

FAQ

### How big is EEPROM on different boards?

Uno/Pro Mini/Nano: 1024 bytes (1 KB). Mega: 4096 bytes (4 KB). Due: 0 (no EEPROM, use flash emulation). ESP32: 512 bytes (emulated in flash).

Can I put() beyond EEPROM size?

The function does not bounds-check. Writing beyond the end will wrap around or silently fail. Always calculate and check the address.

Does put() return anything?

It returns a reference to the EEPROM object. Use EEPROM.put(addr, val) == EEPROM.get(addr, val) to verify writes.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro