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.
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.
Talking to a chip
Addresses, ACKs, register maps, and 16-bit reads and writes.
| Lesson | Time | What students do |
|---|---|---|
| Who is on the busAn 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 |
|
| Reads and writes: the INA219A 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 |
|
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".
Getting data out
The startup sequence, and bursts of calibration and data.
| Lesson | Time | What students do |
|---|---|---|
| Init sequencesThe 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 |
|
| Burst readsRead 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 |
|
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".
Units and failures
The compensation math, and a driver that survives a missing chip.
| Lesson | Time | What students do |
|---|---|---|
| Calibration mathBosch’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 |
|
| Error handlingA 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 |
|
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".
Boss project
A complete BMP280 driver class flying a weather balloon.
| Lesson | Time | What students do |
|---|---|---|
| Boss: a BMP280 driverEverything 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 |
|
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".
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.