All paths

Files, CSV and JSON

Build the flight computer of a weather balloon: read and write files without losing them, log a live sensor to CSV, keep settings in JSON, organize folders, survive every disk error, and ship a sensor log tool.

Raspberry Pi 4 Model BFree7 lessons5 h4 chapters2,050 XPCoding · Intermediate+150 XP

0 of 7 done

What you will build

3 projects, built step by step

7 lessons in 4 chapters, about 5 hours on a simulated Raspberry Pi 4 Model B. Free, in your browser, every step checked by the simulator.

Chapter 1 project

Writing safely

Write a flight log without losing it: "w" that wipes the file, "a" that appends, newlines you have to add, print to a file, and an atomic save with os.replace that survives a power cut.

Open it in the simulator
Chapter 2 project

JSON config

Keep a flight computer's settings in config.json: load it, fill gaps from defaults, validate it with clear messages, save it back atomically with indent and sort_keys, and learn what JSON changes on the way through.

Open it in the simulator
Chapter 3 project

Errors on disk

Make a flight computer that keeps going when files go wrong: a missing config, a config cut off by a power failure, folders where files should be, bad rows in a CSV, try/except/else/finally, and the OSError family by errno.

Open it in the simulator
The map

Chapter by chapter

Each lesson opens when the one before it is done, and each chapter ends in a project.

Chapter 1

Text files

Read a flight plan, then write a log that survives a power cut.

  1. Open205 XP

    Reading files

    Read a balloon's flight plan from a text file: the whole file, its lines and their hidden newlines, a loop that skips comments, a key: value parser, and the bytes underneath the text.

    0 of 5 steps

  2. ProjectLocked410 XP

    Writing safely

    Write a flight log without losing it: "w" that wipes the file, "a" that appends, newlines you have to add, print to a file, and an atomic save with os.replace that survives a power cut.

    0 of 5 steps

4 questions, graded as you go.
Chapter 2

CSV and JSON

Rows of readings in CSV, settings in JSON.

  1. Locked205 XP

    CSV in and out

    Read a recorded balloon flight with DictReader, turn pressure into altitude, log the live BME280 to a CSV with csv.writer, append with a header only once, and see how commas and quotes inside values survive.

    0 of 5 steps

  2. ProjectLocked410 XP

    JSON config

    Keep a flight computer's settings in config.json: load it, fill gaps from defaults, validate it with clear messages, save it back atomically with indent and sort_keys, and learn what JSON changes on the way through.

    0 of 5 steps

4 questions, graded as you go.
Chapter 3

Folders and failures

Organize the files, and keep going when the disk says no.

  1. Locked205 XP

    Paths and folders

    Organize a flight computer's files: the working folder, folders by date with makedirs, numbered log names that never overwrite, pathlib's Path objects, and a walk over the whole tree with sizes.

    0 of 5 steps

  2. ProjectLocked410 XP

    Errors on disk

    Make a flight computer that keeps going when files go wrong: a missing config, a config cut off by a power failure, folders where files should be, bad rows in a CSV, try/except/else/finally, and the OSError family by errno.

    0 of 5 steps

5 questions, graded as you go.
Chapter 4

Project

A sensor log tool for launch day.

  1. Locked205 XP

    Project: a sensor log tool

    Skylark's ground tool, from everything in the course: a config with defaults, numbered CSV logs of the live BME280 in a folder, a list of logs with rows and sizes, a summary saved as JSON atomically, and temperature alarms from the config.

    0 of 5 steps

4 questions, graded as you go.
Syllabus

Every lesson in the course

All 7 lessons, in order, each with what it covers. Any of them opens in the editor right away.

Chapter 1

Text files

  1. Reading filesRead a balloon's flight plan from a text file: the whole file, its lines and their hidden newlines, a loop that skips comments, a key: value parser, and the bytes underneath the text.
  2. Writing safelyWrite a flight log without losing it: "w" that wipes the file, "a" that appends, newlines you have to add, print to a file, and an atomic save with os.replace that survives a power cut.
Chapter 2

CSV and JSON

  1. CSV in and outRead a recorded balloon flight with DictReader, turn pressure into altitude, log the live BME280 to a CSV with csv.writer, append with a header only once, and see how commas and quotes inside values survive.
  2. JSON configKeep a flight computer's settings in config.json: load it, fill gaps from defaults, validate it with clear messages, save it back atomically with indent and sort_keys, and learn what JSON changes on the way through.
Chapter 3

Folders and failures

  1. Paths and foldersOrganize a flight computer's files: the working folder, folders by date with makedirs, numbered log names that never overwrite, pathlib's Path objects, and a walk over the whole tree with sizes.
  2. Errors on diskMake a flight computer that keeps going when files go wrong: a missing config, a config cut off by a power failure, folders where files should be, bad rows in a CSV, try/except/else/finally, and the OSError family by errno.
Chapter 4

Project

  1. Project: a sensor log toolSkylark's ground tool, from everything in the course: a config with defaults, numbered CSV logs of the live BME280 in a folder, a list of logs with rows and sizes, a summary saved as JSON atomically, and temperature alarms from the config.
Kits

Build it on your bench too

Every lesson runs in the simulator with nothing to buy. When you want the real thing, these kits have the parts.

Have a kit already?

Find your kit

Pick the starter kit you own and run every lesson in its manual with the same parts on the same pins.

See every kit
Questions

About Files, CSV and JSON

Is Files, CSV and JSON free?

Yes. All 7 lessons of Files, CSV and JSON are free and run in your browser, with nothing to install and no parts to buy before you start.

Do I need a real Raspberry Pi 4 Model B?

No. Every lesson runs on a simulated Raspberry Pi 4 Model B with its parts on the canvas, and the simulator checks each step as you go. When you want to build it for real, the same wiring and code work on a real board.

How long does Files, CSV and JSON take?

About 5 hours: 7 lessons in 4 chapters, each one a few short steps. Your progress is kept, so you can stop after any lesson and pick up where you left off.

What will I build?

Each chapter ends in a project that puts it together: Writing safely, JSON config and Errors on disk.

Where do I start?

With "Reading files", and each lesson builds on the one before it. New to circuits? Electronics basics is the course that starts from zero.