Lesson plan

Data logging: SD, EEPROM and flash lesson plan

Keep data through resets and power cuts: the Uno's EEPROM and its wear, a 24LC256 on I2C, SD cards and FAT, CSV logs with DS3231 timestamps, safe writes, and a month-long weather balloon flight recorder.

4 chapters, 7 lessons, about 6 hours, on the Arduino Uno R3. Every lesson runs in the browser, with nothing to install.

The unit

Objectives and materials

By the end, students can

  • Small memories that survive the power going off.
  • FAT, CSV logs and real timestamps.
  • What reaches the card when the power goes.
  • A weather balloon flight recorder built to log for a month.

Materials for the whole unit

  • Arduino Uno R3
  • Half breadboard
  • I2C EEPROM, 24LC256
  • LED
  • microSD card module
  • Real-time clock, DS1307
  • Real-time clock, DS3231
  • Resistor x 2
  • Temperature sensor, DS18B20

Every part is already on the simulator’s bench, so there is nothing to buy or hand out. The counts are the most any one lesson uses, if you build it on real breadboards too.

Chapter 1. About 1 h 40 min

EEPROM

Small memories that survive the power going off.

LessonTimeWhat students do
EEPROM and wearThe Uno's own 1024 bytes of EEPROM: a boot counter that survives a reset, settings saved as a struct, and the sums for a cell rated at 100,000 writes.50 min
  1. Run it: memory that remembers
  2. Press reset
  3. Settings as a struct
  4. Cells wear out
  5. Save less often
  6. Spreading the wear
A 24LC256 on the bus32 KB of I2C EEPROM: page writes, the write cycle found by ACK polling, and the page wrap bug that a wrong page size causes.50 min
  1. Run it: two chips, one bus
  2. The write cycle
  3. The page wrap bug
  4. Fix the page size
  5. How much fits
  6. Which memory for what

Materials

  • Arduino Uno R3
  • Half breadboard
  • I2C EEPROM, 24LC256
  • Real-time clock, DS1307

Check for understanding

Each student finishes "A 24LC256 on the bus" on their own, without opening the hints. The simulator checks 6 of its 6 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Which memory for what".

Chapter 2. About 2 h 30 min

Files on an SD card

FAT, CSV logs and real timestamps.

LessonTimeWhat students do
SD cards and FATA microSD card on SPI: blocks, a FAT16 file system, listing the card, and why a file name has to fit in eight characters and three.50 min
  1. Run it: a card on SPI
  2. FAT: names on top of blocks
  3. Eight and three
  4. A name that fits
  5. No card
  6. Treat cards kindly
CSV logsA temperature every second appended to LOG.CSV: a header row, one record per line, a separator, and the file printed back on demand.50 min
  1. Run it: a log file
  2. One record per line
  3. Warm it up
  4. Read the file back
  5. A European spreadsheet
  6. CSV habits
Timestamps from an RTCRows stamped by a DS3231: why millis() is not a time, Unix time, a date that rolls over at midnight by itself, and an ISO 8601 timestamp.50 min
  1. Run it: a clock on the bus
  2. Stamp every row
  3. Unix time
  4. Midnight, New Year
  5. ISO 8601
  6. Log in UTC

Materials

  • Arduino Uno R3
  • Half breadboard
  • LED
  • microSD card module
  • Real-time clock, DS3231
  • Resistor x 2
  • Temperature sensor, DS18B20

Check for understanding

Each student finishes "Timestamps from an RTC" on their own, without opening the hints. The simulator checks 6 of its 6 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Log in UTC".

Chapter 3. About 50 min

Surviving power loss

What reaches the card when the power goes.

LessonTimeWhat students do
Power-loss safe writesA file kept open for speed: what flush() really does, a power cut that loses the unflushed rows, and the trade between speed, wear and safety.50 min
  1. Run it: a fast logger
  2. Written is not saved
  3. Pull the plug
  4. Past the flush
  5. Flush every row
  6. Designing for power loss

Materials

  • Arduino Uno R3
  • Half breadboard
  • LED
  • microSD card module
  • Real-time clock, DS3231
  • Resistor x 2
  • Temperature sensor, DS18B20

Check for understanding

Each student finishes "Power-loss safe writes" on their own, without opening the hints. The simulator checks 6 of its 6 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Designing for power loss".

Chapter 4. About 1 h 5 min

Boss project

A weather balloon flight recorder built to log for a month.

LessonTimeWhat students do
Boss: a month-long flight recorderA weather balloon logger built for a month: a file per day named by the RTC, timestamp, temperature and altitude rows, the flight number in EEPROM, and a resume after a power cut.65 min
  1. Run it: flight recorder
  2. Will a month fit?
  3. Rows with time, temperature and height
  4. A blink you can see
  5. Power cut in flight
  6. A file per day
  7. Stretch the battery
  8. Make it your recorder

Materials

  • Arduino Uno R3
  • Half breadboard
  • LED
  • microSD card module
  • Real-time clock, DS3231
  • Resistor x 2
  • Temperature sensor, DS18B20

Check for understanding

Each student finishes "Boss: a month-long flight recorder" on their own, without opening the hints. The simulator checks 8 of its 8 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Make it your recorder".

Your class

Teach this unit as a class

Start a class from this course and its 7 lessons are assigned in one go, in order. Students join with a six-character code or printed login cards, and each one’s work comes back to you.

The class tools are free for 30 days for one class of up to 20 students, with no card. The lessons themselves are free either way.