Intro to Embedded Rust Part 7: Creating a TMP102 Driver Library and Crate | DigiKey
In this video, we create reusable embedded Rust libraries in this comprehensive tutorial on driver development for the Raspberry Pi Pico 2 and other microcontrollers. We'll extract our previous TMP102 temperature sensor code into a separate library crate that uses generics and embedded-hal traits to work across any platform that implements the standard I2C interface. This tutorial demonstrates real-world embedded Rust development practices: drivers are published as separate crates on crates.io, allowing the community to share platform-agnostic code that works with STM32, ESP32, nRF52, RP2350, and countless other microcontrollers. The written guide for this episode can be found here: https://www.digikey.com/en/maker/tutorials/2026/intro-to-embedded-rust-part-7-creating-a-tmp102-driver-library-and-crat The GitHub repository containing the Docker image and example code for this series can be found here: https://github.com/ShawnHymel/introduction-to-embedded-rust This hands-on Rust library development tutorial covers the complete process of creating an embedded driver from scratch. We demonstrate how to use rustdoc documentation comments (/// and //!) to generate API documentation and how to design public interfaces with proper encapsulation. We explore advanced generic programming patterns including generic structs with type parameters, trait bounds using the where clause, and associated types like I2C::Error from the embedded-hal traits. The tutorial demonstrates creating custom error enums with generic type parameters, using the #[derive(Debug, Clone, Copy)] attribute to automatically implement common traits, and defining enums for hardware configuration options like I2C addresses. You'll understand how trait bounds constrain generic types to only those implementing specific interfaces, enabling compile-time verification that your driver works with any compatible HAL implementation. We then create a demo application that imports our library using a path dependency in Cargo.toml, showing how to use local libraries during development before publishing to crates.io. The demo application demonstrates the practical benefits of good library design: instead of managing raw I2C transactions with register addresses and bit manipulation scattered throughout the code, we simply instantiate our TMP102 driver and call clean methods like read_temperature_c(). You'll see how the application code becomes dramatically simpler and more maintainable when driver complexity is properly encapsulated in a separate library. We walk through the minimal changes needed to convert our previous I2C example to use the new library, highlighting how ownership of the I2C peripheral transfers to the driver and how the generic type parameters get filled in with concrete types from the rp235x-hal when you instantiate the driver with real hardware.
Part List
| 圖片 | 製造商零件編號 | 說明 | 現有數量 | 價格 | 查看詳情 | |
|---|---|---|---|---|---|---|
![]() | ![]() | SC1631 | RASPBERRY PI PICO 2 RP2350 | 26210 - 即時供貨 | $180.00 | 查看詳情 |
![]() | ![]() | SC1632 | RASPBERRY PI PICO 2 H RP2350 | 1693 - 即時供貨 | $216.00 | 查看詳情 |
![]() | ![]() | SC1633 | RASPBERRY PI PICO 2 W RP2350 | 6111 - 即時供貨 | $252.00 | 查看詳情 |
![]() | ![]() | SC1634 | RASPBERRY PI PICO 2 WH RP2350 | 2388 - 即時供貨 | $288.00 | 查看詳情 |
![]() | ![]() | 13314 | TMP102 DIGITAL TEMP SENSOR BOARD | 254 - 即時供貨 | $214.00 | 查看詳情 |
![]() | ![]() | LTL-4224 | LED RED CLEAR T-1 3/4 T/H | 73475 - 即時供貨 | $5.00 | 查看詳情 |
![]() | ![]() | CF14JT220R | RES 220 OHM 5% 1/4W AXIAL | 93369 - 即時供貨 30000 - 工廠存貨 | $4.00 | 查看詳情 |
![]() | ![]() | 1825910-6 | SWITCH TACTILE SPST-NO 0.05A 24V | 45941 - 即時供貨 | $5.00 | 查看詳情 |
![]() | ![]() | FIT0096 | BREADBRD TERM STRIP 3.20X2.00" | 3713 - 即時供貨 | $104.00 | 查看詳情 |
![]() | ![]() | 1957 | JUMPER WIRE M TO M 6" 28AWG | 3907 - 即時供貨 | $70.00 | 查看詳情 |
![]() | ![]() | DH-20M50055 | USB AM TO USB MICRO, USB 2.0 - 1 | 9354 - 即時供貨 | $56.00 | 查看詳情 |
















