eeprom-log.ino
The microcontroller EEPROM keeps data without power (100,000 write cycles minimum). EEPROM.put only writes changed bytes, sparing the memory; the resume index is re-read at boot.
Hardware required
An Arduino Duemilanove (ATmega168 or 328P, 16 MHz, 5 V) with its mini-USB-B cable; the serial port appears once the FTDI driver is installed. None (any voltage source on A0 for testing: potentiometer or LDR).
Wiring
Nothing special; wire A0 to a divider or analog sensor.
How it works
Each record is 16 theoretical bytes (2 used here); the header at address 0 stores the sample count so logging resumes after a reboot. In the Arduino IDE, select « Arduino Duemilanove » (or « Diecimila » for very old boards) and the FTDI port, then Upload. The ATmega168 leaves only 14 KB for the sketch.
Going further
Tag the entries (count, date) and dump the journal over the serial link on demand.
eeprom-log.ino
// Journalise une valeur analogique dans l'EEPROM (4 Ko ou 1 Ko).
#include <EEPROM.h>
const int ENTREE = 16; // taille d'un enregistrement (octets)
const int MAX = EEPROM.length() / ENTREE;
int compteur = 0;
void setup() {
Serial.begin(9600);
// Relit le dernier indice ecrit (0xFFFF = vierge)
EEPROM.get(0, compteur);
if (compteur == 0xFFFF || compteur > MAX) compteur = 0;
Serial.print(F("Reprise a l'entree "));
Serial.println(compteur);
}
void loop() {
int valeur = analogRead(A0);
int idx = compteur % MAX;
EEPROM.put(2 + idx * ENTREE, valeur); // 2 octets par entree
EEPROM.put(0, ++compteur); // memoire du rang
Serial.print(idx); Serial.print(F(" -> ")); Serial.println(valeur);
delay(2000);
}