A Rust implementation of the 1-Wire protocol for embedded-hal
These examples omit error handling to keep them short. You should check all results and handle them appropriately.
The 1-wire bus requires a single digital pin that is configured as an
open-drain output (it's either open, or connected to ground), and the bus
should have a ~5K Ohm pull-up resistor connected. How you obtain this pin from your
specific device is up the the embedded-hal implementation for that device, but it must
implement both InputPin
and OutputPin
```rust use embeddedhal::blocking::delay::DelayUs; use embeddedhal::digital::v2::{InputPin, OutputPin}; use core::fmt::{Debug, Write}; use onewirebus::OneWire;
fn finddevices (
delay: &mut impl DelayUs
// The family code can be used to identify the type of device
// If supported, another crate can be used to interact with that device at the given address
writeln!(tx, "Found device at address {:?} with family code: {:#x?}",
device_address, device_address.family_code()).unwrap();
}
} ```
Example Output
Found device at address E800000B1FCD1028 with family code: 0x28
Found device at address 70000008AC851628 with family code: 0x28
Found device at address 0B00000B20687E28 with family code: 0x28
Found device at address 5700000B2015FF28 with family code: 0x28