Overview
Coursera Flash Sale
40% Off Coursera Plus for 3 Months!
Grab it
Learn to implement Inter-Integrated Circuit (I2C) communication in embedded Rust using the Raspberry Pi Pico 2 in this 27-minute tutorial. Master one of the most widely used protocols in embedded systems that enables microcontrollers to communicate with sensors, displays, memory chips, and other peripherals using just two wires. Build a temperature monitoring application that reads data from a TMP102 I2C sensor and displays it over USB serial when you press a button, extending the USB serial template from previous episodes. Explore GPIO pin configuration for alternate I2C functions using the rp235x-hal, initialize the I2C peripheral with proper clock speed (100 kHz standard mode), and perform write-read operations for I2C device communication. Understand I2C addressing and device register access by reading the TMP102's datasheet to comprehend its register layout, performing combined write-read transactions, and converting raw binary sensor data into meaningful temperature values in degrees Celsius. Practice bit manipulation techniques including shifting and masking to extract 12-bit signed temperature values from the sensor's two-byte response. Implement button input handling with pull-up resistors and edge detection to trigger readings only on button press. Work with the heapless crate for fixed-size strings without heap allocation, essential for no-std embedded development where heap usage is avoided. Format floating-point temperature values into strings using the write! macro and core::fmt::Write trait for formatted output without the standard library. Handle I2C operation errors using Rust's Result type to gracefully manage communication failures and display error messages over USB serial. Create a reusable template for interfacing with I2C devices that can be adapted for accelerometers, gyroscopes, displays, EEPROMs, and thousands of other I2C peripherals.
Syllabus
Intro
Overview of TMP102 Temperature Sensor
Dependencies
Initialize Input Pin and I2C
Read and Print Temperature Value on Button Press
Build and Flash
Challenge and Reading Assignment
Conclusion
Taught by
Digi-Key