Connect ESP32 sensors with I²C, SPI, and UART
Understand sensor buses, then find an I²C sensor on an ESP32-C6.
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.
| Bus | How it works | Check first |
|---|---|---|
| I²C | Devices share data and clock wires; an address selects the recipient. | Address and pull-up resistors |
| SPI | The controller clocks data and selects a peripheral with a dedicated wire. | Chip select and clock mode |
| UART | Each 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.
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 runThe 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.
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.
Before you move on
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
All lessons in this topic
- 1. Install Wendy Lite on your ESP32
- 2. Update an ESP32 app over Wi-Fi
- 3. Find your ESP32 on Wendy Net
- 4. Use ESP32 sensors from Linux and ROS 2
- 5. Run your first ESP32 app
- 6. Read a button, sample voltage, and drive PWM
- 7. Connect ESP32 sensors with I²C, SPI, and UART
- 8. Handle ESP32 interrupts and detect stalled work
- 9. Build an ESP32 alarm that tolerates noisy readings