Manage a Raspberry Pi device from Rust. GPIO ports and L298N motors controller
All tests are performed on Raspberry PI 4B+ on Raspbian OS.
In your "Cargo.toml" file :
toml
[dependencies]
raslib = "*"
Check the current version on crates.io.
```rust use raslib; use raslib::gpio::Gpio;
fn blink_led() -> Result<(), std::io::Error> { let led = Gpio::new(16)?; loop { led.write(raslib::HIGH)?; raslib::sleep(1000);
led.write(raslib::LOW)?;
raslib::sleep(1000);
}
} ```
```rust use raslib::l298n::L298n;
fn forwardforever() -> Result<(), std::io::Error> { let mut motorleft = L298n::new(18, 15, 14); let mut motor_right = L298n::new(9, 7, 25);
motor_left.forward()?;
motor_right.forward()?;
Ok(())
}
```
Considering your connection are made this way: (from : alcalyn.github.io)
Modified from the Rust docs example: ```rust use std::io::prelude::*; use std::net::TcpListener; use std::net::TcpStream;
fn server() {
let server = TcpListener::bind("
for stream in server.incoming() {
let mut stream: TcpStream = stream.unwrap();
let mut signal = [0; 1];
loop {
stream.read(&mut signal);
if signal[0] == 0 {
break;
}
// does things with the raspi
}
}
} ```