Sensors & Measurement · Study deck

Sensor Interfacing Protocols

Picture a room sensor connected to a small controller.

Physics Phoebe is your guide for this deck.

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

After studying this chapter

Learning objectives

You will be able to:

  • Differentiate between I2C, SPI, and UART communication protocols based on wiring, speed, and topology
  • Configure an I2C bus with correct pull-up resistors and address assignments for multi-sensor applications
  • Implement SPI communication with proper mode selection for high-speed sensor data transfer
  • Evaluate and justify the appropriate protocol for specific sensor requirements and constraints
iotclass.org

Major section

Start With the Measurement Story

The sensor may use one pin, two shared wires, a clocked link, or a simple serial line.

  • The best choice is the one that keeps the reading and its failure state clear.
  • A protocol means shared rules for an exchange.
  • GPIO means general purpose input and output pins.
  • Silence must not become a valid zero.
iotclass.org

Major section

Start With the Measurement Story (continued)

Inter-integrated circuit (I2C) means a short shared wired link between chips.

  • Serial Peripheral Interface (SPI) means a clocked wired link with separate data paths.
  • Universal asynchronous receiver-transmitter (UART) means a serial link that agrees on timing without a shared clock.
  • This runway does not prove cable length, noise margin, or power use.
iotclass.org

Major section

In 60 Seconds

Sensor communication protocols (I2C, SPI, UART) are the "languages" sensors and microcontrollers use to exchange data.

  • I2C uses just two wires and supports dozens of sensors on one bus, while SPI trades extra wires for much faster data transfer.
  • The mathematical gist.: I2C rise time is $t_r=0.847RC$.
iotclass.org

Major section

I2C Communication Protocol

I2C (Inter-Integrated Circuit) is a two-wire synchronous protocol perfect for connecting multiple sensors using minimal GPIO pins.

  • The controller addresses the sensor for writing, selects a register, issues a repeated START, addresses it for reading, accepts the returned byte, and ends the transfer with NACK and STOP.

Why it matters

That shared electrical boundary explains why duplicate addresses, excessive bus capacitance, or missing pull-ups can defeat an otherwise correct transaction sequence.

I2C Protocol Sequence: Reading Temperature from BMP280 Sensor
I2C Protocol Sequence: Reading Temperature from BMP280 Sensor
iotclass.org

Major section

SPI Communication Protocol

SPI (Serial Peripheral Interface) is a synchronous, full-duplex communication protocol using four lines: MISO (Master In Slave Out), MOSI (Master Out Slave In), SCK (Serial Clock), and CS (Chip Select).

  • Unlike I2C, SPI supports simultaneous bidirectional data transfer.
  • The transaction is easiest to understand when chip selection and clocking are separated from the two data paths.
SPI Protocol Communication: Full-Duplex SD Card Read Transaction
SPI Protocol Communication: Full-Duplex SD Card Read Transaction
iotclass.org

Major section

UART Serial Communication

Many sensors provide UART as a simpler alternative to I2C/SPI, though at lower data rates.

  • UART (Universal Asynchronous Receiver/Transmitter) is the simplest serial protocol, using just two wires for point-to-point communication without a clock signal.
  • Unlike I2C and SPI, UART is asynchronous -- both sides must agree on the baud rate (bits per second) beforehand.
  • void loop() { while (Serial2.available()) { char c = Serial2.read(); Serial.print(c); // Forward GPS NMEA sentences to USB } }.

Key terms

UART
UART is commonly used for GPS modules (NMEA sentences at 9600 bps), Bluetooth modules (HC-05 AT commands), GSM/cellular modems, and debug/logging output.
iotclass.org

Deck summary

Key takeaways

The sensor may use one pin, two shared wires, a clocked link, or a simple serial line.

  • Inter-integrated circuit (I2C) means a short shared wired link between chips.
  • Sensor communication protocols (I2C, SPI, UART) are the "languages" sensors and microcontrollers use to exchange data.
  • I2C (Inter-Integrated Circuit) is a two-wire synchronous protocol perfect for connecting multiple sensors using minimal GPIO pins.
  • SPI (Serial Peripheral Interface) is a synchronous, full-duplex communication protocol using four lines: MISO (Master In Slave Out), MOSI (Master Out Slave In), SCK (Serial Clock), and CS (Chip Select).
iotclass.org

Retrieval practice

Recall check 1 of 4

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

Q1Per Phoebe's Field Notes, why can't a 4.7 kOhm pull-up reliably run an I2C bus at the full 400 pF capacitance ceiling, even at just 100 kHz (Standard mode)?

AAt 4.7 kOhm and 400 pF, the calculated rise time is about 1.59 us, slower than the 1000 ns (1 us) Standard-mode rise-time limit -- so the bus can't reliably reach the high threshold before the next clock edge
B400 pF is below the I2C specification's capacitance limit, so 4.7 kOhm is always safe regardless of speed
C4.7 kOhm exceeds the maximum resistance I2C allows on any bus, regardless of capacitance
DStandard mode has no rise-time limit, only Fast mode does
Show answer

Answer: A

iotclass.org

Retrieval practice

Recall check 2 of 4

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

Q2In the I2C protocol, what does Wire.endTransmission(false) do differently from Wire.endTransmission(true)?

AIt sends data at half the clock speed
BIt disables the internal pull-up resistors on SDA and SCL
CIt issues a Repeated START instead of a STOP condition.
DIt switches the bus from write mode to broadcast mode
Show answer

Answer: C Passing false to endTransmission() sends a Repeated START instead of a STOP.

iotclass.org

Retrieval practice

Recall check 3 of 4

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

Q3Per this chapter's 'When to Choose Each Protocol' guidance, which requirement is listed as a reason to choose SPI over I2C?

AReal-time requirements under 1 ms latency
BLimited GPIO pins available
CModerate data rates under 50 kB/s are sufficient
DMultiple sensors such as temperature, pressure, and an IMU need to share a bus
Show answer

Answer: A see answers page

iotclass.org

Retrieval practice

Recall check 4 of 4

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

Q4Per this chapter's UART Key Characteristics, what fundamentally limits UART to connecting exactly two devices, unlike I2C or SPI?

AUART has no bus topology or addressing scheme -- its TX/RX lines are point-to-point only, with no shared clock or device-select mechanism
BUART's baud rate is too slow to support more than two devices
CUART requires a dedicated chip-select line per device, like SPI, which becomes impractical past two devices
DUART devices all share the same hardware address, so adding a third device would cause conflicts
Show answer

Answer: A see answers page

iotclass.org

Print reference

Answers 1 of 2

Answer key.

  1. A
  2. C · Passing false to endTransmission() sends a Repeated START instead of a STOP.
  3. A · The chapter's two lists: Choose I2C when multiple sensors are needed, GPIO pins are limited, data rates are moderate (<50 kB/s), and cable runs are moderate; Choose SPI when high-speed transfer (>1 MB/s), large data blocks, real-time (<1 ms) requirements, and plenty of GPIO pins are the priorities.
iotclass.org

Print reference

Answers 2 of 2

Answer key.

  1. A · The chapter's UART Key Characteristics list 'Point-to-point only: Connects exactly two devices (no bus topology)' -- UART has neither I2C's 7-bit addressing nor SPI's per-device CS line, so it has no mechanism to distinguish or share among more than two devices.
iotclass.org