Raspberry PI library for Rust. GPIO controller, L298N motors, sockets and "i2clib" integrated

Overview

raslib

Raspberry PI library for Rust. GPIO controller, L298N motors, sockets and "i2clib" integrated

All tests are made on Raspberry PI 4B+ on Raspbian OS

Overview

  • GPIO controller
  • L298N motors controller (needs the GPIO controller)

NOTE there is no server socket generator because the Rust standard library already contains a really good way to create sockets
SEE here to create a server socket

Install

In your project Cargo.toml file, add the "raslib" dependency :

[dependencies]
raslib = { git = "https://github.com/antoninhrlt/raslib" }

And then, build your project : cargo build

Examples

  • Blink a led

    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);
        }
    }
  • L298N motor

    use raslib::l298n::L298n;
    
    fn forward_forever() -> Result<(), std::io::Error> {
        let mut motor_left = L298n::new(18, 15, 14);
        let mut motor_right = L298n::new(9, 7, 25);
    
        motor_left.forward()?;
        motor_right.forward()?;
    
        Ok(())
    }
    And your connections are: (from : alcalyn.github.io) connection scheme

Server socket

From doc.rust-lang.org

use std::io::prelude::*;
use std::net::TcpListener;
use std::net::TcpStream;

fn server() {
    let server = TcpListener::bind("<raspi ip>:9000").unwrap();

    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
        }
    }
}
You might also like...
Easy c̵̰͠r̵̛̠ö̴̪s̶̩̒s̵̭̀-t̶̲͝h̶̯̚r̵̺͐e̷̖̽ḁ̴̍d̶̖̔ ȓ̵͙ė̶͎ḟ̴͙e̸̖͛r̶̖͗ë̶̱́ṉ̵̒ĉ̷̥e̷͚̍ s̷̹͌h̷̲̉a̵̭͋r̷̫̊ḭ̵̊n̷̬͂g̵̦̃ f̶̻̊ơ̵̜ṟ̸̈́ R̵̞̋ù̵̺s̷̖̅ţ̸͗!̸̼͋

Rust S̵̓i̸̓n̵̉ I̴n̴f̶e̸r̵n̷a̴l mutability! Howdy, friendly Rust developer! Ever had a value get m̵̯̅ð̶͊v̴̮̾ê̴̼͘d away right under your nose just when

GPIO reader, writer and listener

Unbothered gpio Everything is unwrapped under the hood for the precious prettiness of your code. It's more than a simple Rust crate, it's a philosophy

Streaming data over unix sockets, in Rust

Unix-socket based client/server In order to dig into Sōzu channels, I had to dig into the workings of unix sockets. What this repo contains a small so

Asynchronous Linux SocketCAN sockets with tokio

tokio-socketcan SocketCAN support for tokio based on the socketcan crate. Example echo server use futures_util::stream::StreamExt; use tokio_socketcan

A super minimal wrapper around unix sockets for IPC on top of tokio.

tokio-unix-ipc This crate implements a minimal abstraction over UNIX domain sockets for the purpose of IPC on top of tokio.

Advanced configuration options for sockets.

socket2-rs Documentation License This project is licensed under either of Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licens

A fast and cross-platform Signed Distance Function (SDF) viewer, easily integrated with your SDF library.
A fast and cross-platform Signed Distance Function (SDF) viewer, easily integrated with your SDF library.

SDF Viewer (demo below) A fast and cross-platform Signed Distance Function (SDF) viewer, easily integrated with your SDF library. A Signed Distance Fu

A Rust library integrated with ONNXRuntime, providing a collection of ML models.

usls A Rust library integrated with ONNXRuntime, providing a collection of Computer Vison and Vision-Language models including YOLOv8, YOLOv9, RTDETR,

A notebook app integrated with todo lists utility. Developed with Rust, WebAssembly, Yew and Trunk.

Flow.er A notebook app integrated with todo-list utility. Project flow.er is a Rust WASM app running in browser. Taking advantage of Yew and Trunk, it

Heavy - an opinionated, efficient, relatively lightweight, and tightly Lua-integrated game framework for Rust

Heavy - an opinionated, efficient, relatively lightweight, and tightly Lua-integrated game framework for Rust Slow down, upon the teeth of Orange Heav

Language Integrated Query in Rust.

Linq in Rust Language Integrated Query in Rust (created by declarative macros). Inspired by LINQ in .NET. What's LINQ This project is under developmen

Raspberry Pi's CPU and GPU temperature exporter for Prometheus consumption.
Raspberry Pi's CPU and GPU temperature exporter for Prometheus consumption.

Pi Temperature Exporter A simple application for collecting Raspberry Pi's CPU and GPU temperatures and exporting them for Prometheus consumption. Ins

SPICE-integrated n-body trajectory propagation tool

traj-propagate A command line utility that reads from and writes to SPICE SPK files to propagate trajectories of specified bodies. The user must provi

it aims to augment git with primitives to build integrated, cryptographically verifiable collaboration workflows around source code

it aims to augment git with primitives to build integrated, cryptographically verifiable collaboration workflows around source code. It maintains the distributed property of git, not requiring a central server. it is transport agnostic, and permits data dissemination in client-server, federated, as well as peer-to-peer network topologies.

Hierarchical Task Network Planning deeply integrated with bevy, which I use in my games :P

Note that CI currently tests against a matrix of (windows, mac, linux) * (toolchain stable, nightly) * (cargo build, test, clippy), which ensures vali

[OUTDATED] Instructions for how to cross compile Rust projects for the Raspberry Pi

Cross Compiling for Raspberry Pi This guide will show how Rust programs can be cross compiled for the Raspberry Pi using Cargo. These instructions may

Operating System development tutorials in Rust on the Raspberry Pi
Operating System development tutorials in Rust on the Raspberry Pi

Operating System development tutorials in Rust on the Raspberry Pi

Program a Raspberry Pi Pico with pure Rust

pi-pico-rs Program a Raspberry Pi Pico with pure Rust. Get Started Install the latest version of Rust and the thumbv6m-none-eabi target. This is the p

A port of OxidGB to the Raspberry Pi Pico

OxidGB Pico Port This is a simple, display-only (for now) port of OxidGB to the Raspberry Pi Pico. Note that this by default overclocks your device -

Owner
Anтo
Sysdev, electronics and embedded systems, 3D. Astronomy
Anтo
[OUTDATED] Instructions for how to cross compile Rust projects for the Raspberry Pi

Cross Compiling for Raspberry Pi This guide will show how Rust programs can be cross compiled for the Raspberry Pi using Cargo. These instructions may

Erik Hedvall 297 Jul 22, 2022
Operating System development tutorials in Rust on the Raspberry Pi

Operating System development tutorials in Rust on the Raspberry Pi

Rust Embedded 10k Jan 9, 2023
The sysroot manager that lets you build and customize `std`

PSA: Xargo is in maintenance mode xargo The sysroot manager that lets you build and customize std Cross compiling `std` for i686-unknown-linux-gnu Xar

Jorge Aparicio 993 Jan 2, 2023
Example of a Baremetal program written for the Rasperry Pi 1 (BCM2845). Both the UART and the Framebuffer graphics working

This repository is aimed to provide a starting point to whoever is trying to build a BCM2835 program from scratch. This repository contains linker scr

Pietro 4 Nov 10, 2022
Libraries and tools for the SMT-LIB-2 standard.

smt2utils: Libraries and tools for the SMT-LIB-2 standard This project aims to develop Rust libraries and tools around the SMT-LIB-2 standard. The SMT

Meta Incubator 18 Dec 16, 2022
Everything you need to know about cross compiling Rust programs!

rust-cross Everything you need to know about cross compiling Rust programs! If you want to set up your Rust toolchain as a cross compiler, you have co

Jorge Aparicio 2.3k Jan 2, 2023
Vue's template compiler reimplemented in Rust!

vue template compiler in Rust https://github.com/vuejs/rfcs/discussions/369#discussioncomment-1192421 Maybe in the long run we want the whole transfor

Herrington Darkholme 687 Jan 1, 2023
A Brainheck compiler written in Rust.

Brainhecc A compiler for Brain[hecc] programs, written in Rust with Cranelift. It compiles any valid Brainhecc program into an executable binary. Inst

Zack 1 Oct 28, 2021
A LED Christmas Tree controlled by Rust. Contribute your own renderers!

Rusty Christmas Tree This is code that draws on the LED Christmas Tree made by @aidancrowther. You can see his 3D design files and Pi Pico setup code

Forest Anderson 43 May 15, 2022
A controller for the display and fan of the Raspberry Pi Waveshare PoE HAT written in Rust 🦀

???? RustBerry-PoE-Monitor RustBerry-PoE-Monitor is a Rust-based monitoring and control tool for the Raspberry Pi, specifically designed for use with

jack 5 Nov 27, 2023