See UART and I²C on a logic analyzer
Probe a sketch's Serial output and its I²C traffic with an 8-channel logic analyzer and decode each byte.
Basic · Intermediate
In a real product: Production test rig (Industrial): Engineers decode the bus traffic to prove a board talks correctly.
When a sensor does not answer, the first question is what is actually on the wires. A logic analyzer records every change on its probes and decodes it as a protocol, the way PulseView or a Saleae does on a real bench.
What you'll learn
- What a UART byte looks like: start bit, eight data bits least significant first, stop bit
- What an I²C transfer looks like: START, address and direction, ACK, data, STOP
- Choosing a time window to fit the signal
How it works
The sketch prints OK on Serial at 9600 baud and writes a byte to an EEPROM at 0x50 every 20 ms. The analyzer's D0 watches TX (pin 1), and D1 and D2 watch SDA and SCL.
At 9600 baud a bit lasts 104 µs, so one character is about 1 ms: a 10 ms window shows a few. Set the decoder to UART and each byte is labelled over the trace. An I²C byte at 100 kHz takes 90 µs; probe SDA on D0 and SCL on D1, set the decoder to I2C and you see S 50 W, the data byte and P. A missing chip shows as NACK right after the address.
Try this
- Run it with the UART decoder, then stop: the last capture stays on the screen.
- Move D0 and D1 to SDA and SCL, set the decoder to I2C and the window to 1 ms.
- Change the EEPROM's address to 0x51 in the sketch: the address byte now ends in NACK.
sketch.ino
// Traffic to look at: "OK" on Serial (TX, pin 1) and a byte written to a 24LC256 at 0x50, every 20 ms.
#include <Wire.h>
uint8_t counter = 0;
void setup() {
Serial.begin(9600);
Wire.begin();
}
void loop() {
Serial.print("OK");
Wire.beginTransmission(0x50);
Wire.write(0x00); // memory address, high byte
Wire.write(0x10); // memory address, low byte
Wire.write(counter++); // data
Wire.endTransmission();
delay(20);
}