Source: https://mokxi.com/teachers/plans/device-drivers
Updated: 2026-11-19

Lesson plan

# Write a driver from a datasheet lesson plan

Raw Wire transactions against real register maps, no library: an I2C scan and a chip id, an INA219 driver with big-endian registers and its calibration, the BMP280 init sequence, burst reads, Bosch’s compensation formulas, error handling for a chip that is missing or unplugged, and a complete BMP280 driver flying a weather balloon.

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

Start a class from this course

The unit

## Objectives and materials

### By the end, students can

- Addresses, ACKs, register maps, and 16-bit reads and writes.
- The startup sequence, and bursts of calibration and data.
- The compensation math, and a driver that survives a missing chip.
- A complete BMP280 driver class flying a weather balloon.

### Materials for the whole unit

- Arduino Uno R3
- Current monitor, INA219
- Half breadboard
- Pressure and temperature, BMP280
- Resistor
- Slide switch

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 2 h

## Talking to a chip

Addresses, ACKs, register maps, and 16-bit reads and writes.

Lesson | Time | What students do

Who is on the bus An I2C scan, an ACK and a NACK, and a first read from a register map: the BMP280 answers 0x58 from register 0xD0, its power-on values say it has measured nothing yet, and a missing chip reads 0xFF. | 60 min

- Run it: scan the bus
- A register map
- Power-on values
- Unplug it
- The wrong address
- Read the datasheet like an engineer

Reads and writes: the INA219 A first complete driver: the INA219 current monitor, with 16-bit big-endian registers, signed shunt counts, a bus register with status bits in it, and a calibration register that has to be written before the current reads anything. | 60 min

- Run it: a 16-bit register
- Shunt and bus voltages
- The register that makes it look broken
- Write a register, read it back
- Change the load
- Pick your own resolution

### Materials

- Arduino Uno R3
- Current monitor, INA219
- Half breadboard
- Pressure and temperature, BMP280
- Resistor
- Slide switch

### Check for understanding

Each student finishes "Reads and writes: the INA219" 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: "Pick your own resolution".

Chapter 2. About 2 h

## Getting data out

The startup sequence, and bursts of calibration and data.

Lesson | Time | What students do

Init sequences The BMP280 startup as the datasheet orders it: check the id, soft reset, wait for the NVM copy, write config while asleep, start a forced measurement, and poll the status register, timing every wait. | 60 min

- Run it: six steps
- Soft reset, and the NVM copy
- Forced mode and the measuring bit
- Read back what you wrote
- Oversample the pressure
- Your init checklist

Burst reads Read 24 calibration bytes and 6 data bytes in one transfer each: little-endian words, signed and unsigned coefficients, 20-bit counts assembled from three bytes, and the time a burst saves. | 60 min

- Run it: 24 bytes, one transfer
- Little-endian words
- Signed or unsigned
- Twenty bits from three bytes
- What a burst saves
- More samples, more bits

### Materials

- Arduino Uno R3
- Current monitor, INA219
- Half breadboard
- Pressure and temperature, BMP280
- Resistor
- Slide switch

### Check for understanding

Each student finishes "Burst reads" 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: "More samples, more bits".

Chapter 3. About 2 h 10 min

## Units and failures

The compensation math, and a driver that survives a missing chip.

Lesson | Time | What students do

Calibration math Bosch’s integer compensation formulas, copied from the datasheet: t_fine first, then the 32-bit pressure formula, checked against the part’s sliders, and broken on purpose to see what a byte-order bug looks like. | 60 min

- Run it: degrees and pascals
- t_fine, and why order matters
- Pressure, and an honest pascal
- Heat it up
- Climb a mountain
- Break it on purpose

Error handling A driver that never trusts the bus: a status from every transfer, the wrong chip caught by its id, timeouts on every wait, a sensor unplugged mid-run and re-initialized when it comes back, and a second address to try. | 70 min

- Run it: every call returns a status
- The wrong chip
- Unplug it while it runs
- Plug it back in
- Strapped the other way
- Try both addresses
- The failure list

### Materials

- Arduino Uno R3
- Current monitor, INA219
- Half breadboard
- Pressure and temperature, BMP280
- Resistor
- Slide switch

### Check for understanding

Each student finishes "Error handling" on their own, without opening the hints. The simulator checks 7 of its 7 steps as they go.

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

Chapter 4. About 1 h

## Boss project

A complete BMP280 driver class flying a weather balloon.

Lesson | Time | What students do

Boss: a BMP280 driver Everything in one class: id check, reset, a calibration burst, normal mode at 16x, the compensation formulas and a status from every call, with an INA219 driver beside it, flying a weather balloon that survives a loose connector. | 60 min

- Run it: a balloon flight computer
- Normal mode
- Launch
- A loose connector at altitude
- Two drivers, one bus
- Set the ceiling

### Materials

- Arduino Uno R3
- Current monitor, INA219
- Half breadboard
- Pressure and temperature, BMP280
- Resistor
- Slide switch

### Check for understanding

Each student finishes "Boss: a BMP280 driver" 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: "Set the ceiling".

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.

Start a class from this course See the demo class

More units

## Other lesson plans

Electronics basics 20 lessons, about 10 h. Embedded on the Arduino Uno 16 lessons, about 12 h. Embedded on the ESP32-C3 13 lessons, about 11 h. Embedded on the Raspberry Pi Pico 7 lessons, about 6 h. Build your own fight stick 5 lessons, about 4 h. Embedded on the STM32F411 6 lessons, about 6 h. C++ on a board 13 lessons, about 10 h. Digital logic and memory 4 lessons, about 4 h. Interactive devices on the Uno 9 lessons, about 8 h. From gates to a computer 23 lessons, about 16 h. Build a claw machine 8 lessons, about 6 h. Every unit All the courses as ready-made units, on the teachers page.
