#raspberry #sensor #display #rainbow #hat

rainbow-hat-rs

Rust Driver for the Rainbow HAT for Raspberry Pi

3 unstable releases

0.2.1 Jul 25, 2021
0.2.0 Aug 24, 2020
0.1.0 Aug 12, 2020

#1002 in Hardware support

Download history 55/week @ 2023-10-28 50/week @ 2023-11-04 27/week @ 2023-11-11 54/week @ 2023-11-18 18/week @ 2023-11-25 17/week @ 2023-12-02 43/week @ 2023-12-09 46/week @ 2023-12-16 35/week @ 2023-12-23 34/week @ 2023-12-30 31/week @ 2024-01-06 17/week @ 2024-01-13 31/week @ 2024-01-20 67/week @ 2024-01-27 32/week @ 2024-02-03 44/week @ 2024-02-10

183 downloads per month
Used in applehat

MIT license

51KB
1K SLoC

Rust driver for Rainbow HAT

Build Status MIT licensed Minimum rustc version Documentation

This repository contains an unofficial Rust driver library for Rainbow HAT, for use with Raspberry Pi OS on your Raspberry Pi.
For the official Python driver see: https://github.com/pimoroni/rainbow-hat.
For the official AndroidThings driver see: https://github.com/androidthings/contrib-drivers/tree/master/rainbowhat.

This library depends on https://github.com/golemparts/rppal for access to the Raspberry Pi peripherals.

Current periferials supported:

Periferial Supported Structs
Multicolour LEDs X rainbow_hat_rs::apa102::APA102
Four 14-segment alphanumeric displays X rainbow_hat_rs::alphanum4::Alphanum4
Three capacitive touch buttons X rainbow_hat_rs::touch::Buttons
Temperature and pressure sensor
Blue, green and red LEDs X rainbow_hat_rs::lights::Lights
Piezo buzzer X rainbow_hat_rs::buzzer::Buzzer

References

Usage

Add a dependency for rainbow-hat-rs to your Cargo.toml.

[dependencies]
rainbow-hat-rs = "0.2.0"

Call new() on any of the peripherals to construct a new instance.

use rainbow_hat_rs::lights::Lights;
use rainbow_hat_rs::alphanum4::Alphanum4;
use rainbow_hat_rs::touch::Buttons;
use rainbow_hat_rs::apa102::APA102;
use rainbow_hat_rs::buzzer::Buzzer;

let mut apa102 = APA102::new()?;
let mut lights = Lights::new()?;
let mut buttons = Buttons::new()?;
let mut alphanum = Alphanum4::new()?;
let mut buzzer = Buzzer::new()?;

Examples

See folder examples.

Multicolour LEDs

let mut apa102 = APA102::new()?;

 // Sets color for all LED.
 apa102.set_all(255, 0, 0, 0.5);

 // Sets color for first LED.
 apa102.set_pixel(0, 0, 255, 0, 0.5);

// Shows on the device.
apa102.show()?;

Lights

let mut lights = Lights::new()?;

// Turn on red and green lights
lights.rgb(true, true, false);

// Turn off red light
lights.red.off()

// Turn on blue light
lights.blue.on()

// Toggle green light
lights.green.toggle()

Buttons

let mut buttons = Buttons::new()?;

// Identify if button A is pressed
if buttons.a.is_pressed() {
    println!("Button A touched!");
}

Display

let mut alphanum = Alphanum4::new()?;

// Print a message on the display
alphanum.print_str("1234", false);
alphanum.show()?;

Buzzer

let mut buzzer = Buzzer::new()?;

// Play a note
buzzer.midi_note(69, 0.3)?;

Caution

Always be careful when working with the Raspberry Pi's peripherals, especially if you attach any external components to the GPIO pins. Improper use can lead to permanent damage.

Copyright (c) 2020 Yann Nicolas. Released under the MIT license.

Dependencies

~380KB