Ramblings of an aging IT geek
← Ramblings of an aging IT geek
hardware

a cheap logic analyser and the moment i2c stopped being magic

Using an inexpensive logic analyser and sigrok to debug a misbehaving I2C sensor, and why seeing the actual bus changed how I work.

A soldering iron and electronics on a workbench

For years I'd debugged I2C the way most hobbyists do: blindly. The sensor returns nonsense, you check your wiring, you reseat the pull-up resistors, you swap the breakout board, you reflash, and eventually it works and you never quite know which thing fixed it. It's debugging by ritual.

This week I finally bought a logic analyser, one of the cheap clones of the well-known eight-channel USB ones, the sort that costs less than a takeaway. And for the first time I could actually see the bus.

what changed

The sensor was returning a fixed, wrong value. My code looked right. The wiring looked right. Before, that's where I'd have stalled.

Instead I clipped the analyser onto SDA and SCL, ran sigrok, and decoded the I2C transaction. There it was, plain as anything: my code was reading from address 0x68 and the device was sitting at 0x69. The board had an address-select pad I'd never noticed, bridged by default the other way. Five minutes, when it had previously been the sort of thing that ate an evening.

A circuit board with probe connections

the workflow

PulseView, the GUI front-end to sigrok, does the heavy lifting. You capture a window of samples, then apply a protocol decoder on top of the raw lines:

pulseview --driver fx2lafw

Set the trigger to fire on SCL going active so you're not staring at idle, capture, then add the I2C decoder and point it at the right channels for clock and data. Suddenly the wall of square waves becomes "start, address 0x69, write, register 0x75, restart, read, byte, NAK, stop". It reads like a sentence once you've seen it a few times.

The decoder for I2C is built in, so is SPI, so is plain UART. That covers the great majority of what a hobbyist actually wrestles with. I haven't needed anything fancier yet.

the wider lesson

The analyser didn't teach me anything about I2C I couldn't have read in a datasheet. What it did was turn the bus from a thing I reasoned about into a thing I could observe. That's the whole difference. Before, every bug was a hypothesis I couldn't test without swapping hardware. Now I look at what's actually on the wire and the bug usually announces itself.

If you've been doing embedded work and squinting at a multimeter wishing it could tell you more, this is the upgrade. It's cheap, the software is free and open, and it retires an entire category of guesswork. I should have bought one years ago.