Connect ESP32 sensors with I²C, SPI, and UART

Understand sensor buses, then find an I²C sensor on an ESP32-C6.

Guided walkthrough·Beginner·3 min read

Opening the Python editor…

Requirements and learning goals

Before you start

  • Complete Run your first ESP32 app on an ESP32-C6-DevKitC-1
  • A 3.3V-compatible I²C sensor breakout and its datasheet

You will be able to

  • Choose the interface a sensor actually supports
  • Find a responding I²C address

Why sensors need a bus

A digital sensor sends numbers over a communication bus instead of exposing a voltage to measure. Your ESP32 and sensor must agree on wiring and message format before your code can read temperature, motion, or distance.

BusHow it worksCheck first
I²CDevices share data and clock wires; an address selects the recipient.Address and pull-up resistors
SPIThe controller clocks data and selects a peripheral with a dedicated wire.Chip select and clock mode
UARTEach end sends bytes on its TX wire to the other's RX wire.Baud rate and framing

Use the interface your sensor supports. A working electrical connection does not yet prove you decoded a measurement correctly.

Checkpoint 1 of 2

You wire a UART sensor by matching labels: its TX to the ESP32's TX, and its RX to the ESP32's RX. What happens?

Commit to an answer. Every choice explains itself.

Use the deployment console to inspect probe results after each wiring change. Once readings work, carry them into the sensor dashboard.

Find an I²C device

Disconnect power. Wire the breakout's SDA to 6, SCL to GPIO 7, and ground to GND. Use its documented 3.3V supply connection. SDA and SCL need pull-ups to 3.3V, typically 4.7k ohms for a short breadboard connection; many breakouts already include them.

Reuse the first app's project. Save the I²C scanner as main/main.c and the component configuration as main/CMakeLists.txt. Keep the other files and wendy_core dependency.

wendy run

The scanner checks ordinary seven-bit addresses with a bounded wait:

esp_err_t result = i2c_master_probe(bus, address, 50);

Expected result

Logs show ACK at 0x... for each responding address, then a count. Compare the address with your sensor's datasheet and address-select pins. An acknowledgement proves a device answered; it does not identify the chip or read a measurement.

Checkpoint 2 of 2

The scanner logs ACK at 0x48 and then a count of one. What has that established?

Commit to an answer. Every choice explains itself.

Troubleshooting

No response? Check supply, shared ground, SDA/SCL, and pull-ups. Timeouts can mean a stuck bus. Disconnect power before rewiring. Two sensors sharing one address need an address change or a bus multiplexer.

Optional extension: read the sensor's identity register using its datasheet before decoding measurements. Reference: ESP32-C6 I²C driver.

Can you do each of these?

  • Choose the interface a sensor actually supports
  • Find a responding I²C address

0 of 2 checkpoints solved. Try checkpoint 1

Previous: Read a button, sample voltage, and drive PWM
All lessons in this topic
  1. 1. Install Wendy Lite on your ESP32
  2. 2. Update an ESP32 app over Wi-Fi
  3. 3. Find your ESP32 on Wendy Net
  4. 4. Use ESP32 sensors from Linux and ROS 2
  5. 5. Run your first ESP32 app
  6. 6. Read a button, sample voltage, and drive PWM
  7. 7. Connect ESP32 sensors with I²C, SPI, and UART
  8. 8. Handle ESP32 interrupts and detect stalled work
  9. 9. Build an ESP32 alarm that tolerates noisy readings

Ask Wendy

Answers about Wendy and WendyOS

What would you like to know?

Ask about devices, development, and deployment.

Check linked docs for technical details.