All paths

Write a driver from a datasheet

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.

Arduino Uno R3Free7 lessons7 h4 chapters2,864 XPEmbedded engineering · Advanced+250 XP

0 of 7 done

What you will build

3 projects, built step by step

7 lessons in 4 chapters, about 7 hours on a simulated Arduino Uno R3. Free, in your browser, every step checked by the simulator.

Chapter 1 project

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.

Open it in the simulator
Chapter 2 project

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.

Open it in the simulator
Chapter 3 project

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.

Open it in the simulator
The map

Chapter by chapter

Each lesson opens when the one before it is done, and each chapter ends in a project.

Chapter 1

Talking to a chip

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

  1. Open265 XP

    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.

    0 of 6 steps

  2. ProjectLocked576 XP

    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.

    0 of 6 steps

5 questions, graded as you go.
Chapter 2

Getting data out

The startup sequence, and bursts of calibration and data.

  1. Locked265 XP

    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.

    0 of 6 steps

  2. ProjectLocked576 XP

    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.

    0 of 6 steps

4 questions, graded as you go.
Chapter 3

Units and failures

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

  1. Locked288 XP

    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.

    0 of 6 steps

  2. ProjectLocked606 XP

    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.

    0 of 7 steps

4 questions, graded as you go.
Chapter 4

Boss project

A complete BMP280 driver class flying a weather balloon.

  1. Locked288 XP

    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.

    0 of 6 steps

3 questions, graded as you go.
Syllabus

Every lesson in the course

All 7 lessons, in order, each with what it covers. Any of them opens in the editor right away.

Chapter 1

Talking to a chip

  1. 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.
  2. 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.
Chapter 2

Getting data out

  1. 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.
  2. 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.
Chapter 3

Units and failures

  1. 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.
  2. 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.
Chapter 4

Boss project

  1. 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.
Kits

Build it on your bench too

Every lesson runs in the simulator with nothing to buy. When you want the real thing, these kits have the parts.

Have a kit already?

Find your kit

Pick the starter kit you own and run every lesson in its manual with the same parts on the same pins.

See every kit
Questions

About Write a driver from a datasheet

Is Write a driver from a datasheet free?

Yes. All 7 lessons of Write a driver from a datasheet are free and run in your browser, with nothing to install and no parts to buy before you start.

Do I need a real Arduino Uno R3?

No. Every lesson runs on a simulated Arduino Uno R3 with its parts on the canvas, and the simulator checks each step as you go. When you want to build it for real, the same wiring and code work on a real board.

How long does Write a driver from a datasheet take?

About 7 hours: 7 lessons in 4 chapters, each one a few short steps. Your progress is kept, so you can stop after any lesson and pick up where you left off.

What will I build?

Each chapter ends in a project that puts it together: Reads and writes: the INA219, Burst reads and Error handling.

Where do I start?

With "Who is on the bus", and each lesson builds on the one before it. New to circuits? Electronics basics is the course that starts from zero.