Exercise A: Bus Scan
~15 min
Goal
Set up an I2C bus on the uFerris board and scan for connected devices.
Steps
1. Create a New Project
esp-generate --chip esp32c3 -o unstable-hal -o vscode -o esp-backtrace -o log --headless i2c_scan
cd i2c_scan
2. Find an I2C Example
Navigate to the esp-hal I2C documentation.
Look for an I2C example in:
- The module-level documentation (
esp_hal::i2c) - The
I2cstruct page - The esp-hal examples directory on GitHub
3. Apply the Mental Model
Read the example and identify:
- Instantiate — How is the
I2ccreated? What peripheral and pins does it need? - Configure — What configuration is applied? (Clock speed, pins)
- Control — What methods are available for reading/writing?
4. Adapt to uFerris
- Check your pinout card for the I2C SDA and SCL pins
- Update the pins in the example to match the uFerris board
5. Scan the Bus
Write a loop that attempts to communicate with every address from 0x01 to 0x7F:
- For each address, try a zero-length write
- If the write succeeds, a device is present at that address
- Print the address of each device found
6. Build and Flash
cargo build --release
espflash flash target/riscv32imc-unknown-none-elf/release/i2c-scan --monitor
What to Notice
- Which addresses respond? Write them down — you'll need them in the next exercise
- One of those addresses is the TCA6424 I/O expander
- Compare the I2C
Instantiatepattern to GPIO — what's similar? What's different?