Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rahul-thakoor/rust_gpiozero
A library inspired by gpiozero written in Rust
https://github.com/rahul-thakoor/rust_gpiozero
embedded-hal gpio gpiozero raspberry-pi rust
Last synced: 7 days ago
JSON representation
A library inspired by gpiozero written in Rust
- Host: GitHub
- URL: https://github.com/rahul-thakoor/rust_gpiozero
- Owner: rahul-thakoor
- License: apache-2.0
- Created: 2018-01-06T11:25:24.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2024-06-06T12:39:54.000Z (7 months ago)
- Last Synced: 2024-12-20T07:53:14.899Z (14 days ago)
- Topics: embedded-hal, gpio, gpiozero, raspberry-pi, rust
- Language: Rust
- Homepage: https://crates.io/crates/rust_gpiozero
- Size: 116 KB
- Stars: 235
- Watchers: 10
- Forks: 27
- Open Issues: 21
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE-APACHE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# rust_gpiozero
[![CI](https://github.com/rahul-thakoor/rust_gpiozero/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/rahul-thakoor/rust_gpiozero/actions/workflows/ci.yml)
[![Crates.io](https://img.shields.io/crates/v/rust_gpiozero)](https://crates.io/crates/rust_gpiozero)A simple interface to GPIO devices with Raspberry Pi.
This library is based on [GPIOZero](https://gpiozero.readthedocs.io/en/stable/index.html)
library.The idea is to get started with physical computing using Rust with little coding
by hiding the underlying complexity.The library uses [BCM Pin numbering](https://pinout.xyz/)
### Example : Blinking an LED
```rust
use rust_gpiozero::*;
fn main() {
// Create a new LED attached to Pin 17
let mut led = LED::new(17);// on_time = 2 secs, off_time=3 secs
led.blink(2.0,3.0);// prevent program from exiting immediately
led.wait();
}```
### Example : Wait for a Button Press
```rustuse rust_gpiozero::*;
fn main() {
// Create a button which is attached to Pin 17
let mut button = Button::new(17);
button.wait_for_press(None);
println!("button pressed");
}```
Compare this to using the crate `sysfs_gpio` to blink an LED on the Raspberry Pi :
```rust
extern crate sysfs_gpio;
use sysfs_gpio::{Direction, Pin};
use std::thread::sleep;
use std::time::Duration;fn main() {
let my_led = Pin::new(127); // number depends on chip, etc.
my_led.with_exported(|| {
loop {
my_led.set_value(0).unwrap();
sleep(Duration::from_millis(200));
my_led.set_value(1).unwrap();
sleep(Duration::from_millis(200));
}
}).unwrap();
}```
## Install/Use
To use `rust_gpiozero`, first add this to your Cargo.toml:
```toml
[dependencies]
rust_gpiozero = "^0.2"
```
Compiling your project on a Raspberry Pi directly can take significant time depending on the model. Ideally, you would cross compile your project then run it on the Raspberry Pi.[More information](https://github.com/japaric/rust-cross)
## Features
The following features are planned :
- [ ] Support for `embedded-hal`
- [ ] Support for common devices such as Accelerometer, Temperature sensors, etc## Changelog
[CHANGELOG.md](https://github.com/rahul-thakoor/rust_gpiozero/blob/master/CHANGELOG.md)
## License
Licensed under either of
* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)at your option.
## Contributing
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any
additional terms or conditions.Thanks for your interest in `rust_gpiozero`. I am a newbie rustacean and just started using the language! I am using this project to learn more about Rust. Feel free to give feedback or send PRs. Your experiences and feedback will also benefit others who use this library.
## Credits
This library would not be possible without the great work of the maintainers of [GPIOZero](https://gpiozero.readthedocs.io/en/stable/index.html) and [rppal](https://github.com/golemparts/rppal)