Giter Club home page Giter Club logo

rust-wiringpi's Introduction

WiringPi Bindings for Rust

An API wrapper for WiringPi to make it accessible using Rust. It implements the most important functions and provides a bit of type system convenience.

Add the following lines to your Cargo.io to use rust-wiringpi:

[dependencies]
wiringpi = "0.2"

Online Documentation

Released

Master branch

Example: Flashing Light

extern crate wiringpi;

use wiringpi::pin::Value::{High, Low};
use std::{thread, time};

fn main() {
    //Setup WiringPi with its own pin numbering order
    let pi = wiringpi::setup();

    //Use WiringPi pin 0 as output
    let pin = pi.output_pin(0);

    let interval = time::Duration::from_millis(1000);

    loop {
        //Set pin 0 to high and wait one second
        pin.digital_write(High);
        thread::sleep(interval);

        //Set pin 0 to low and wait one second
        pin.digital_write(Low);
        thread::sleep(interval);
    }
}

Cross Compiling Using Cargo

Follow this guide.

cargo build --target=arm-unknown-linux-gnueabihf   # Older models
cargo build --target=armv7-unknown-linux-gnueabihf # Newer models

Orange Pi support

rust-wiringpi can also wrap the WiringOP library for the Orange Pi SBC boards. This can be enabled with the orangepi feature:

[dependencies.wiringpi]
version = "0.2"
features = ["orangepi"]

Development Mode

In development mode, rust-wiringpi is compiled as a rust-native library excluding the original WiringPi. And binding functions are replaced by dummy functions that output simple logs to stdout. With this mode, you can build and debug your project on platforms that does not support WiringPi.

Development mode will be turned on automatically on non-arm targets, but can be turned on manually on arm targets as well

# build
$ cargo build --features wiringpi/development

# run
$ cargo run --features wiringpi/development

[wiringpi] `wiringPiSetup` called
[wiringpi] `pinMode` called with: 0, 1
[wiringpi] `digitalWrite` called with: 0, 1
[wiringpi] `digitalWrite` called with: 0, 0
...

rust-wiringpi's People

Contributors

ogeon avatar razican avatar yuhe00 avatar nisshiee avatar lindenk avatar vojtechkral avatar axos88 avatar jmatraszek avatar lennarts avatar nsenaud avatar zzeroo avatar

Watchers

James Cloos avatar  avatar

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.