knaxuslearn · build · ship

Projects / Temperature logger

BeagleBone · about 10 hours · 4 phases

Build a temperature logger on a BeagleBone

A BeagleBone is a small computer the size of a credit card that runs Linux, with rows of pins along its edges for connecting sensors. That mix makes it a good place to learn how a measurement gets from a wire to a file we can trust. The sensor gives a voltage, the chip turns it into a number, Linux shows that number as a file, and our program turns it into degrees and keeps it. Then the real questions start. What happens when a reading is nonsense, when the board boots with the wrong date, when the program crashes, or when someone pulls the power in the middle of a write? In about 10 hours we will build a logger that answers each of those, runs by itself from power-on, and shows its readings on a web page.

You work in four phases of about 2.5 hours each, and every phase ends with something you can run and look at. By the end you will have:

  • a TMP36 sensor wired to the BeagleBone's analog input, read from Linux, with a test that shows one wild reading cannot spoil a result,
  • a logger that takes a reading on a fixed schedule, refuses readings that make no sense, marks readings taken before the clock was set, and stores them all in SQLite,
  • the logger running as a system service that starts at boot, restarts after a crash and stops cleanly,
  • a database that survives a crash at any moment, checked by killing the logger 200 times, and a web page with the latest reading, an hourly summary and a CSV download.

You need basic Python (functions, loops, reading a file) and to be comfortable typing commands in a terminal. Everything about the board, the sensor and Linux services is explained when it first comes up.

The four phases

  1. From a wire to a number

    You end with a sensor wired to the board, its reading in degrees on your screen, and a test that shows one wild reading cannot spoil a result.

    • 1.1 The plan, and the sensor15 min
    • 1.2 Get onto the board25 min
    • 1.3 Find the ADC20 min
    • 1.4 Wire the sensor30 min
    • 1.5 Volts and degrees, tested on your laptop35 min
    • 1.6 One wild reading25 min
  2. Keep every reading

    You end with a logger that takes a reading on a fixed schedule, refuses readings that make no sense, marks readings taken while the clock was wrong, keeps them all in SQLite, and an hourly report.

    • 2.1 What to keep20 min
    • 2.2 The table25 min
    • 2.3 Readings on a schedule35 min
    • 2.4 Readings that make no sense20 min
    • 2.5 The clock that starts in the past30 min
    • 2.6 An hourly report20 min
  3. Run it as a service

    You end with the logger installed on the board as a service that starts at boot, comes back after a crash, stops cleanly when asked, and writes its messages to the system log.

    • 3.1 What a service is15 min
    • 3.2 Stop cleanly30 min
    • 3.3 Install it30 min
    • 3.4 The unit file30 min
    • 3.5 Break it on purpose30 min
    • 3.6 Read its messages15 min
  4. Survive anything, and share it

    You end with a database that comes through crashes and power cuts undamaged, checked by killing the logger 200 times, and a web page with the latest reading, an hourly summary and a CSV download.

    • 4.1 What happens when the power goes25 min
    • 4.2 WAL, and how hard to try20 min
    • 4.3 Kill it 200 times30 min
    • 4.4 A web page40 min
    • 4.5 Run the page as a service20 min
    • 4.6 How long will it run?15 min

Start with the setup →