Sensors & Measurement · Study deck
Protocol Diagnostics and Bus Design
Picture a room sensor that sometimes reports zero after a board restart.
Gateway Gus is your guide for this deck.

After studying this chapter
Learning objectives
You will be able to:
- Explain: The optimal value depends on bus capacitance: R = t_rise / (0.8473 x C_bus), where t_rise is the maximum rise time from the I2C specification (1000 ns standard mode, 300 ns fast mode).
- Explain: The Mistake: Connecting I2C sensors directly to GPIO pins without external pull-up resistors, assuming the microcontroller's internal pull-ups are sufficient, or using incorrect resistor values that cause unreliable communication.
- Explain: The HIGH threshold is 2.31 V, which corresponds to about 11.0 kΩ: leakage below that can hold the bus invalid without being a dead short.
- resolve sensor address conflicts
Major section
Start With the Measurement Story
Zero may be a real reading, a missing reply, the wrong address, or a timing error.
- The receiving code must keep those states separate.
- GPIO means a general-purpose input/output pin used for a direct line.
- I2C is a shared two-wire link for addressed nearby parts.
- This runway does not diagnose every board fault.
Major section
Start With the Measurement Story (continued)
SPI is a clocked link with separate data paths and a select line.
- UART is a simple serial link that sends timed bits between two endpoints.
- Disconnect a wire, change the rate, repeat a read, and restart the controller.
- A bus failure often looks like a bad sensor until the evidence is checked.
Major section
Start With the Measurement Story (continued)
The deeper sections cover pull-ups, addresses, clock modes, framing, logic traces, shared-line design, and the tests that separate wiring from software.
- The useful story follows pull-ups, addresses, clock speed, cable length, signal integrity, and logs until the fault is visible instead of guessed.
- On the chapter's 3.3 V bus with 4.7 kΩ pull-up, a 1.65 V idle reading means Rf=4.7 kΩ.
- The HIGH threshold is 2.31 V, which corresponds to about 11.0 kΩ: leakage below that can hold the bus invalid without being a dead short.
Major section
Common Protocol Pitfalls
The left switch gives a stream of zeros.
- The middle timing sheet points to the clock-edge setting, and the right display shows a checked reading after that setting changes.
- The practical test is to compare the sensor data sheet with the SPI mode in code and confirm one known value.
- The tool identifies collisions and suggests resolution strategies.
Major section
Common Protocol Pitfalls (continued)
Beginners also confuse I2C (open-drain, requires pull-ups) with SPI (push-pull, no pull-ups needed).
- The next pitfall concerns I2C pull-ups, which are a separate electrical check.
- The Mistake: Connecting I2C sensors directly to GPIO pins without external pull-up resistors, assuming the microcontroller's internal pull-ups are sufficient, or using incorrect resistor values that cause unreliable communication.
- Symptom of missing pull-ups: I2C scanner finds no devices, or communication works intermittently.
Major section
Common Protocol Pitfalls (continued)
The MAX31855 thermocouple ADC requires Mode 0, while the ADXL345 accelerometer is typically used in Mode 3 (it also supports Mode 0).
- Internal pull-ups on ESP32 are weak (45-65 kohm), only suitable for very short wires (<10 cm) at low speeds.
- Common starting values are 4.7 kohm for standard 100 kHz I2C and 2.2 kohm for fast mode 400 kHz.
- // WRONG: Default mode may not match sensor SPI.begin(); SPI.transfer(0x00).
Major section
Common Protocol Pitfalls (continued)
The optimal value depends on bus capacitance: R = t_rise / (0.8473 x C_bus), where t_rise is the maximum rise time from the I2C specification (1000 ns standard mode, 300 ns fast mode).
- Mode 0 means clock idle low and sample on the rising edge; Mode 3 means clock idle high and sample on the falling edge.
- Debug tip: If sensor returns 0x00 or 0xFF consistently, try all four SPI modes - one should produce valid register values.
- Understanding which clock edge is used for sampling helps you debug corrupted sensor readings.
Major section
Multi-Sensor I2C Bus Design
The breakout shares SDA and SCL but also exposes wake, reset, and interrupt signals that affect integration and recovery.
- Too weak (high resistance) causes slow rise times and communication errors.
- Too strong (low resistance) wastes power and may damage devices.

Major section
Summary
One to send, one to receive, one to keep time, and one to pick who is talking.
- I2C, SPI, and UART are the three core sensor communication protocols in IoT.
- Temperature Terry wanted to tell the microcontroller about the temperature, but they did not speak the same language!
- SPI would need a separate wire for each friend!" Now the whole Sensor Squad could chat, whether they needed speed or simplicity!
Deck summary
Key takeaways
Zero may be a real reading, a missing reply, the wrong address, or a timing error.
- SPI is a clocked link with separate data paths and a select line.
- The deeper sections cover pull-ups, addresses, clock modes, framing, logic traces, shared-line design, and the tests that separate wiring from software.
- The left switch gives a stream of zeros.
- Beginners also confuse I2C (open-drain, requires pull-ups) with SPI (push-pull, no pull-ups needed).
Retrieval practice
Recall check 1 of 4

Physics Phoebe says: answer from memory, then check your reasoning.
Q1An I2C bus works at a slow clock but fails after longer cables are added. The address scan is unstable. What should be measured first?
Show answer
Answer: B Longer cables raise capacitance, so weak pull-ups can make the lines rise too slowly.
Retrieval practice
Recall check 2 of 4

Physics Phoebe says: answer from memory, then check your reasoning.
Q2An ESP32 has three I2C sensors: BMP280 (0x76), BH1750 (0x23), and SHT31 (0x44). After adding a second BMP280 for redundancy, both pressure readings return identical values. What is the most likely cause?
Show answer
Answer: D Both BMP280 sensors default to address 0x76.
Retrieval practice
Recall check 3 of 4

Physics Phoebe says: answer from memory, then check your reasoning.
Q3An SD card must transfer at 2 MB/s. A BME280 also needs a connection, and GPIO pins are limited. Which protocol combination meets the throughput while keeping the sensor connection pin-efficient?
Show answer
Answer: D SPI provides the clock rates needed for multi-megabyte-per-second SD-card traffic.
Retrieval practice
Recall check 4 of 4

Physics Phoebe says: answer from memory, then check your reasoning.
Q4What bidirectional open-drain line carries I2C data between devices?
Show answer
Answer: C SDA carries bidirectional I2C data and must be checked as a shared open-drain line.
Q5Complete the MicroPython code to read temperature from a BME280 sensor over I2C on an ESP32:
Show answer
Answer: A I2C initialization requires specifying the bus number, SCL/SDA pins, and clock frequency (400kHz for Fast Mode).
Print reference
Answers
Answer key.
- B · Longer cables raise capacitance, so weak pull-ups can make the lines rise too slowly.
- D · Both BMP280 sensors default to address 0x76.
- D · SPI provides the clock rates needed for multi-megabyte-per-second SD-card traffic.
- C · SDA carries bidirectional I2C data and must be checked as a shared open-drain line.
- A · I2C initialization requires specifying the bus number, SCL/SDA pins, and clock frequency (400kHz for Fast Mode).