Example sketches#
Every example below ships with the library. In the Arduino IDE they are under File → Examples → BBR Digital Expander; in PlatformIO they are in the library’s examples/ folder.
They all assume the board is at the default address 0x38 on Wire. If you jumpered a different address, change the constructor.
Start here#
| Sketch | What it shows |
|---|---|
DeviceInfo |
Identity, firmware version, variant, capabilities, and what is on each port |
SensorDump |
Every live value in one transaction — the fastest way to check your wiring |
EncoderRead |
Counts, firmware velocities, idempotent resets |
Run DeviceInfo before anything else. If it prints a device report, your wiring, pull-ups, logic levels and address jumpers are all correct, and everything else will work.
Colour#
| Sketch | What it shows |
|---|---|
ColorTeach |
Teach-by-example from the serial monitor, saved to flash |
ColorRead |
Reading colour classes, confidence and raw channels |
LatchedOutput |
Latched outputs — catching an event too brief for your loop |
Distance#
| Sketch | What it shows |
|---|---|
DistanceRead |
Millimetres, and what “nothing in range” looks like |
Triggers#
| Sketch | What it shows |
|---|---|
TriggerSetup |
The canonical setup-once configuration: colour, distance, encoder and heading |
TriggerRuntime |
The runtime half: one digitalRead(), zero I2C, no library at all |
Read these two together. They are the clearest demonstration of what the board is for — the setup sketch runs once and is then never needed again, and the runtime sketch is 23 lines that do not even #include the library.
Encoders#
| Sketch | What it shows |
|---|---|
PwmEncoder |
Absolute pulse-width encoders, calibration, wrap tracking |
Heading and odometry#
| Sketch | What it shows |
|---|---|
HeadingIMU |
Heading, gyro calibration, failing loudly on an untrustworthy gyro |
Localizer |
Full pose tracking: parameters, calibration, live pose, re-zeroing |
Both need the odometry variant of the board. On a base board they say so and stop, rather than reporting a heading of 0.00 forever.
A note on the examples#
They are written to be read as much as run. Where an example checks ok() or a status flag rather than trusting a return value, that is showing you something worth copying — particularly HeadingIMU and Localizer, where the check is the difference between “the gyro is not answering” and a heading that looks fine and is wrong.
The interactive ones take single-character commands from the serial monitor at 115200 — r to reset, c to calibrate, 1–7 to teach a colour. Each sketch’s header comment says which.