Crates.io | gpio-rust |
lib.rs | gpio-rust |
version | 0.1.4 |
source | src |
created_at | 2021-07-27 12:43:20.981881 |
updated_at | 2021-07-27 14:21:38.965737 |
description | Rust GPIO is a low-level library used to interact with a Raspberry PI's GPIO pins. |
homepage | https://github.com/jweir136/gpio-rust |
repository | https://github.com/jweir136/gpio-rust |
max_upload_size | |
id | 427956 |
size | 21,238 |
Rust GPIO is a low-level library used to interact with a Raspberry PI's GPIO pins.
In order to use Rust GPIO you not only need to install this crate to your project, but to
install the correct GPIO library on your Raspberry PI. Under the hood, Rust GPIO uses
RPi.GPIO. Luckily, the library comes pre-installed
in most Raspbian/Raspberry Pi OS operating systems. If you find yourself needing to download or
update the RPi.GPIO library you can run sudo apt-get update && sudo apt-get install python-rpi.gpio python3-rpi.gpi
. If you are unsure if the library is already installed, you install this crate and call the is_installed()
method. The Rust GPIO crate can be installed to a project
by adding gpio-rust = "*"
to your Cargo.toml file.
Using this crate is very basic by design. You are given low-level GPIO access with the turn_on and turn_off functions located in the gpio module. The cleanup function is used to free up all allocated resources.
match turn_on(1) {
Ok(()) => {
println!("The pin is now on!");
},
Err(msg) => {
println!("The pin could not be turn on: {}", msg);
}
};
match turn_off(1) {
Ok(()) => {
println!("The pin is now off!");
},
Err(msg) => {
println!("The pin could not be turn off: {}", msg);
}
};
match cleanup() {
Ok(()) => {
println!("The cleanup has been run!");
},
Err(msg) => {
println!("The cleanup could not be run: {}", msg);
}
};
The Rust GPIO crate is very self-explanatory. However, if you find yourself in the need of some documentation, and there is a good change you will, you can access it at Docs.rs | Rust GPIO. You can also download the crate from source and build the docs using cargo doc --no-deps --open
.