IO10: Capstone: a tank monitor that lasts, copes and updates safely

Lesson 2 of 5 · reading 15–25 minutes; practice and project time is on the module page

Project 1: a year on one battery

🎯You'll be able to

Complete Project 1: a sensor driver that's correct and robust, a device that sleeps nearly all the time, and a battery life you can show with a budget and a measurement.

🏠The everyday picture

A night watchman who sits awake all night is worn out in a week. One who sleeps and checks the gate every fifteen minutes, for a moment, can keep going for months.

📘What it really is

📝A worked example

Input: test 02 failing: the driver returns a distance of 0 mm and 0.0 °C, where the test expects 766 mm and -3.5 °C.

Steps:

  1. Read the starter: it starts a conversion and reads straight away, before the LV-20 has finished, so the registers are still 0.
  2. Poll the status register until the result is ready, giving up after about 100 ms, and run the test again.
  3. Now it reads 65,026 mm and 124.5 °C. 766 is 0x02FE; reading the high byte first gives 0xFE02 (65,026). The temperature byte 0xF9 is signed, so it's -7 half-degrees, not 249. Read low byte first and treat the temperature as signed, as docs/lv20-datasheet.md says, and run pytest tests/test_power.py.

Expected output: test 02 passes with 766 mm and -3.5 °C.

🌍Where it's used

📝Case scenario

A learner's power budget said 900 days, but the simulation said 280. The budget had assumed the radio was used every fourth wake, but their code joined Wi-Fi on every wake. Fixing the code, not the budget, brought both to about 870 days in the practice kit.

🖱️Try it

Run python tools/simulate.py --days 7 on the starter and note the battery life it reports. Success: a figure of a few days, and the part of the report that uses the most charge.

⚠️Common mistakes

🛠️For your project

Project 1's evidence: the output of pytest tests/test_power.py with 10 passing, docs/power-budget.md, and the simulation report.

✅Quick check

Why does JalSetu keep its counters in RTC memory?

Show the answer

Deep sleep clears ordinary memory, and RTC memory keeps them between wakes.

How does the starter's level reading go wrong?

Show the answer

It reads the two distance bytes in the wrong order, and doesn't wait for the conversion.

← PreviousPlanning the capstone
ProLearners Assist