Sensors & Measurement · Study deck

Protocol Diagnostics and Bus Design

Picture a room sensor that sometimes reports zero after a board restart.

Physics Phoebe 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 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 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 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.

Numbers to remember

1.65 Va 1.65 V idle reading means $R_f=4.7$ kΩ.
2.31 VThe HIGH threshold is 2.31 V
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 $R_f=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 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.

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

Key terms

Common starting values
Common starting values are 4.7 kohm for standard 100 kHz I2C and 2.2 kohm for fast mode 400 kHz.
Mode 0
Mode 0 means clock idle low and sample on the rising edge; Mode 3 means clock idle high and sample on the falling edge.
iotclass.org

Major section

Common Protocol Pitfalls (continued)

// WRONG: Default mode may not match sensor SPI.begin(); SPI.transfer(0x00).

  • Beginners also confuse I2C (open-drain, requires pull-ups) with SPI (push-pull, no pull-ups needed).
  • Common starting values are 4.7 kohm for standard 100 kHz I2C and 2.2 kohm for fast mode 400 kHz.
  • The tool identifies collisions and suggests resolution strategies.
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).

  • Symptom of missing pull-ups: I2C scanner finds no devices, or communication works intermittently.
  • The MAX31855 thermocouple ADC requires Mode 0, while the ADXL345 accelerometer is typically used in Mode 3 (it also supports Mode 0).
  • Mode 0 means clock idle low and sample on the rising edge; Mode 3 means clock idle high and sample on the falling edge.
  • 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 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.
  • // WRONG: Default mode may not match sensor SPI.begin(); SPI.transfer(0x00).
iotclass.org

Retrieval practice

Recall check 1 of 4

Physics Phoebe says: answer from memory, then check your reasoning.

Q1An 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 2 of 4

Physics Phoebe says: answer from memory, then check your reasoning.

Q2You need to read data from an SD card at 2 MB/s and also connect a BME280 environmental sensor. Which protocol combination is most appropriate?

AI2C for both the SD card and BME280
BSPI for both the SD card and BME280
CSPI for the SD card and I2C for the BME280
DUART for the SD card and SPI for the BME280
Show answer

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

iotclass.org

Retrieval practice

Recall check 3 of 4

Physics Phoebe says: answer from memory, then check your reasoning.

Q3Place each sensor-interface signal where it lives so you can isolate an I2C, SPI, or voltage-level wiring fault.

ASDA (I2C Data Line)
BSCL (I2C Clock Line)
CPull-up Resistor (4.7kΩ)
DMOSI (SPI Master Out)
ECS/SS (Chip Select)
FLevel Shifter
Show answer

Answer: A Separate I2C shared-line checks, SPI transfer checks, and voltage-boundary protection so you can diagnose a silent sensor without swapping protocols or pins blindly.

iotclass.org

Retrieval practice

Recall check 4 of 4

Physics Phoebe says: answer from memory, then check your reasoning.

Q4Complete 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. D · Both BMP280 sensors default to address 0x76.
  2. C · SPI provides the clock rates needed for multi-megabyte-per-second SD-card traffic.
  3. A · Separate I2C shared-line checks, SPI transfer checks, and voltage-boundary protection so you can diagnose a silent sensor without swapping protocols or pins blindly.
  4. A · I2C initialization requires specifying the bus number, SCL/SDA pins, and clock frequency (400kHz for Fast Mode).
iotclass.org