Thuta Learning
AdvancedHardwarebeginner

I2C & SPI — Advanced GPIO Protocols

Relax. We'll talk through this in plain words — no textbook voice.

What you'll walk away with

  • Understand I2C & SPI — Advanced GPIO Protocols without any of the intimidation
  • Be able to run the hardware wiring/code yourself
  • Apply this concept right away in a real project

Let's think about it this way for a moment

I2C (Inter-Integrated Circuit) is a protocol that lets you connect many devices to a single bus using just two wires (SDA for data + SCL for clock) — each device has a unique address, and the Pi uses that address to decide which device it wants to talk to. SPI (Serial Peripheral Interface) uses more pins (MOSI, MISO, SCLK, CS) but runs faster — it's commonly used for high-speed sensor/display modules.

Let's connect it to a real scenario

You can chain I2C temperature sensors, OLED displays, and real-time clock modules together on the same I2C bus (just the two SDA/SCL pins) — with several devices connected, running the i2cdetect -y 1 command scans and shows you a list of connected device addresses (handy for troubleshooting). You'll need to enable the I2C interface in raspi-config (disabled by default, just like the Camera interface).

Let's look at it together

bash
# Enable I2C interface
sudo raspi-config
# Interface Options → I2C → Enable

# Install i2c-tools
sudo apt install i2c-tools

# Scan for connected I2C devices
i2cdetect -y 1
You should see
Running i2cdetect -y 1 should display a grid table, highlighting the address (e.g. 0x3c) of any device that's connected.

5-minute try-it

If you have an I2C sensor module, connect it and run i2cdetect -y 1 — see if you can spot its device address.

A quick word of caution

If you have multiple devices on an I2C bus, an address conflict (two devices sharing the same address) can cause communication errors — double-check each device's default address against its datasheet.

Easy traps

  • Trying to run the i2cdetect command without enabling the I2C interface in raspi-config first (results in 'command not found' or no devices detected)
  • Confusing I2C/SPI with plain GPIO digital pins (from the LED lesson) — missing the difference between these protocols

Now try it yourself

If you have an I2C sensor module, connect it and run i2cdetect -y 1 — see if you can spot its device address.

You'll know it worked when: Running i2cdetect -y 1 should display a grid table, highlighting the address (e.g. 0x3c) of any device that's connected.

I2C & SPI — Advanced GPIO Protocols | Thuta Learning