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.

sensorinterfacingprotocol
Physics Phoebe, the module guide, in a scene from this chapter.
iotclass.org

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
iotclass.org

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.

Key terms

SPI
SPI is a clocked link with separate data paths and a select line.
iotclass.org

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.
iotclass.org

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.7R_f=4.7Rf​=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.
iotclass.org

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.

Key terms

Internal pull-ups on ESP32
Internal pull-ups on ESP32 are weak (45-65 kohm), only suitable for very short wires (<10 cm) at low speeds.
iotclass.org

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.
iotclass.org

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).
iotclass.org

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.
iotclass.org

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.

Why it matters

Unique addresses prevent one class of conflict, while pull-up strength, capacitance, power sequencing, and control-line handling complete the dependable bus design developed below.

A red CCS811 air-quality sensor breakout board with the sensing package and labeled I2C pads visible
A red CCS811 air-quality sensor breakout board with the sensing package and labeled I2C pads visible
iotclass.org

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!
iotclass.org

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).
iotclass.org

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?

AChange dashboard color to diagnose the I2C cable rise-time fault.
BMeasure SDA/SCL rise time and bus capacitance, then check pull-ups.
CMeasure sensor calibration offset instead of SDA and SCL edges.
DMeasure SPI mode as if it set the I2C bus's pull-up resistance.
Show answer

Answer: B Longer cables raise capacitance, so weak pull-ups can make the lines rise too slowly.

iotclass.org

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?

AThe I2C bus capacitance exceeds 400 pF, causing signal degradation
BThe SDA and SCL lines are swapped on the second BMP280
CThe pull-up resistor value is too high for four devices on the bus
DBoth BMP280 sensors share the same default I2C address (0x76).
Show answer

Answer: D Both BMP280 sensors default to address 0x76.

iotclass.org

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?

AI2C for both the SD card and BME280
BSPI for both the SD card and BME280
CUART for the SD card and SPI for the BME280
DSPI for the SD card and I2C for the BME280
Show answer

Answer: D SPI provides the clock rates needed for multi-megabyte-per-second SD-card traffic.

iotclass.org

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?

ASCL (I2C Clock Line)
BPull-up Resistor (4.7kΩ)
CSDA (I2C Data Line)
DMOSI (SPI Master Out)
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:

Ai2c = I2C(0, scl=Pin(22), sda=Pin(21), freq=400000)
Bi2c = I2C(scl=22, sda=21)
Ci2c = Pin(22, Pin.OUT)
Di2c = I2C(0, freq=9600)
Show answer

Answer: A I2C initialization requires specifying the bus number, SCL/SDA pins, and clock frequency (400kHz for Fast Mode).

iotclass.org

Print reference

Answers

Answer key.

  1. B · Longer cables raise capacitance, so weak pull-ups can make the lines rise too slowly.
  2. D · Both BMP280 sensors default to address 0x76.
  3. D · SPI provides the clock rates needed for multi-megabyte-per-second SD-card traffic.
  4. C · SDA carries bidirectional I2C data and must be checked as a shared open-drain line.
  5. A · I2C initialization requires specifying the bus number, SCL/SDA pins, and clock frequency (400kHz for Fast Mode).
iotclass.org