A generic sensor logger for the Sense HAT
A configurable long-running logger that samples every Sense HAT sensor on a fixed interval and writes CSV to a file — with --label, --interval, --duration and --output flags.
Logger is a small, generic CSV logger for the Sense HAT. Point it at an event you want to record — a meteor shower, an overnight temperature drop, a weekend of pressure changes — set the interval and duration, and it writes one CSV row per sample until it's done.
Source code: projects/Logger/Logger.java
Running it
jbang projects/Logger/Logger.java \
--label "Perseid Meteor Shower 2026" \
--interval 30s \
--duration 6h \
--output perseids.csv
That logs every enabled Sense HAT sensor (temperature, humidity, pressure, and colour on a v2) every 30 seconds for 6 hours, writing rows to perseids.csv. When the duration is up, the process exits cleanly.
Flags
All four flags are optional and have sensible defaults:
| Flag | Purpose | Default |
|---|---|---|
--label |
Free-form run label, written into a # label: … header at the top of the CSV. |
sensor log |
--interval |
Sample interval — 500ms, 30s, 2m, 6h. |
1s |
--duration |
Total run time, same syntax as --interval. |
run forever |
--output |
Output CSV path. | stdout |
Durations accept the short forms above or full ISO-8601 (PT6H, PT30M). Anything else prints a clear error and exits.
What ends up in the CSV
The file starts with three comment lines describing the run, then a header row, then one row per sample:
# label: Perseid Meteor Shower 2026
# interval: 30s
# started: 2026-08-13T02:00:00Z
timestamp,temp_hts,temp_lps,humidity,pressure,clear,red,green,blue,marker
2026-08-13T02:00:00.012Z,18.42,18.60,72.10,1013.20,4820,1600,1710,1510,
2026-08-13T02:00:30.021Z,18.40,18.58,72.30,1013.19,4805,1592,1704,1509,
The clear,red,green,blue columns only appear on a Sense HAT v2 (the TCS3400 colour sensor is v2-only). On a v1 board the header and rows are shorter — no manual configuration needed.
Joystick markers
While it runs, pressing the joystick in any direction drops an extra row with MARK in the marker column, timestamped to the moment of the press. It reuses the latest reading so the marker sits inline with the surrounding samples and you can find it later with a simple grep MARK perseids.csv.
This is deliberately simpler than the Eclipse logger, which uses each direction for a specific contact tag (C1–C4). For a generic logger a single "something happened here" mark is usually all you need.
Why a separate script
The Eclipse demo is tuned for one thing — 1 Hz sampling with a live light meter on the LED matrix and eclipse-specific tags. Logger is the opposite: no LED output, no fixed schema, no hard-coded interval. It's meant to be the boring default you reach for whenever you want to leave the Pi somewhere recording data for a while.
A few things that fall out of that design:
- The output file is opened once and flushed after every row, so a
Ctrl-Cor a power loss still leaves a well-formed CSV. - Any sensor that throws while reading returns an empty field instead of killing the run — useful for overnight logs where a transient I²C hiccup shouldn't cost you hours of data.
- The header line captures the label, interval and start time, so a folder of CSVs stays self-describing without a separate metadata file.
A few things worth logging
- Meteor showers — pair temperature and humidity trends with your own visual counts.
- A cold front — long
--duration,1minterval, watch pressure fall. - A room at night — humidity and temperature drift while you're asleep.
- A greenhouse or a fridge — set it and forget it for a day.
Requirements
Same as the other examples: this script depends on a specific branch of pi4j-drivers (my igfasouza branch), so clone and install it locally first:
git clone -b igfasouza https://github.com/igfasouza/pi4j-drivers.git
cd pi4j-drivers
mvn install
Then run it with JBang on a Raspberry Pi with a Sense HAT attached.