Giter VIP home page Giter VIP logo

one-wire-bus's Introduction

One-Wire Bus

Build Status crates.io API

A Rust implementation of the 1-Wire protocol for embedded-hal

Quick Start

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

use embedded_hal::blocking::delay::DelayUs;
use embedded_hal::digital::v2::{InputPin, OutputPin};
use core::fmt::{Debug, Write};
use one_wire_bus::OneWire;

fn find_devices<P, E>(
    delay: &mut impl DelayUs<u16>,
    tx: &mut impl Write,
    one_wire_pin: P,
)
    where
        P: OutputPin<Error=E> + InputPin<Error=E>,
        E: Debug
{
    let mut one_wire_bus = OneWire::new(one_wire_pin).unwrap();
    for device_address in one_wire_bus.devices(false, delay) {
        // The search could fail at any time, so check each result. The iterator automatically
        // ends after an error.
        let device_address = device_address.unwrap();

        // 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

one-wire-bus's People

Contributors

fuchsnj avatar daniel-larsen avatar

Stargazers

 avatar

Forkers

elwerene

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.