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.
Right
#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
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro