| Crates.io | automation-hat |
| lib.rs | automation-hat |
| version | 0.1.1 |
| created_at | 2025-07-22 13:31:35.612537+00 |
| updated_at | 2025-07-22 14:35:24.721904+00 |
| description | A Rust library for the Pimoroni Automation HAT |
| homepage | |
| repository | https://github.com/JudahZF/automation-hat |
| max_upload_size | |
| id | 1763526 |
| size | 52,442 |
A Rust library for controlling the Pimoroni Automation HAT, Automation pHAT, and Automation HAT Mini.
Add this to your Cargo.toml:
[dependencies]
automation-hat = "0.1.0"
This library requires I2C and SPI to be enabled on your Raspberry Pi. You can enable these interfaces using raspi-config.
use automation_hat::{AutomationHAT, HatType};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a new AutomationHAT instance
let mut hat = AutomationHAT::new(HatType::AutomationHAT);
// Toggle relay 3
hat.relays.three.write(true)?;
// Read digital input 1
let input_value = hat.inputs.one.read()?;
println!("Input 1: {}", input_value);
// Set digital output 2
hat.outputs.two.write(true)?;
// Read analog input 3
let analog_value = hat.analog_inputs.three.read()?;
println!("Analog 3: {}", analog_value);
Ok(())
}
use automation_hat::{AutomationHAT, HatType};
use embedded_graphics::{
mono_font::MonoTextStyleBuilder,
pixelcolor::Rgb565,
prelude::*,
primitives::{Rectangle, PrimitiveStyleBuilder},
text::{Baseline, Text},
};
use embedded_graphics_core::primitives::Rectangle;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut hat = AutomationHAT::new(HatType::AutomationHATMini);
if let Some(ref mut display) = hat.display {
// Clear display
let style = PrimitiveStyleBuilder::new()
.fill_color(Rgb565::BLACK)
.build();
Rectangle::new(Point::new(0, 0), Size::new(160, 80))
.into_styled(style)
.draw(display)?;
// Draw some text
let text_style = MonoTextStyleBuilder::new()
.font(&FONT_6X10)
.text_color(Rgb565::WHITE)
.build();
Text::with_baseline("Automation HAT", Point::new(10, 20), text_style, Baseline::Top)
.draw(display)?;
}
Ok(())
}
The library supports:
// Create an AutomationHAT instance
let mut hat = AutomationHAT::new(HatType::AutomationHAT);
You can choose between:
HatType::AutomationHATHatType::AutomationPHATHatType::AutomationHATMiniRelays provide a high-power switch controlled by the Raspberry Pi.
// Set relay state (true = on, false = off)
hat.relays.one.write(true)?; // Only available on HAT and pHAT
hat.relays.two.write(true)?; // Only available on HAT and pHAT
hat.relays.three.write(true)?;
// Get relay state
let state = hat.relays.three.value;
Digital outputs provide 5V signals for controlling external devices.
// Set output state (true = on, false = off)
hat.outputs.one.write(true)?;
hat.outputs.two.write(true)?;
hat.outputs.three.write(true)?;
// Get output state
let state = hat.outputs.one.value;
Digital inputs read 5V signals from external devices.
// Read input state (returns true for high, false for low)
let input1 = hat.inputs.one.read()?;
let input2 = hat.inputs.two.read()?;
let input3 = hat.inputs.three.read()?;
Analog inputs read variable voltage levels from external devices.
// Read analog value (returns a float from 0.0 to 1.0)
let analog1 = hat.analog_inputs.one.read()?;
let analog2 = hat.analog_inputs.two.read()?;
let analog3 = hat.analog_inputs.three.read()?;
The Automation HAT Mini includes a 0.96" 160x80 color LCD display.
if let Some(ref mut display) = hat.display {
// Use embedded-graphics to draw to the display
// See embedded-graphics documentation for more details
}
This project is licensed under the MIT License - see the LICENSE file for details.