Automation HAT Rust Library
A Rust library for controlling the Pimoroni Automation HAT, Automation pHAT, and Automation HAT Mini.
Features
- Control relays, digital outputs, and read digital/analog inputs
- Full LED control with automatic status indication
- Support for all Automation HAT variants (HAT, pHAT, Mini)
- Display support for Automation HAT Mini
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Hardware Setup
This library requires I2C and SPI to be enabled on your Raspberry Pi. You can enable these interfaces using raspi-config.
Usage Examples
Basic Usage
use ;
Automation HAT Mini with Display
use ;
use ;
use Rectangle;
Device Support
The library supports:
- Automation HAT: 3 relays, 3 analog inputs, 3 digital inputs, 3 digital outputs, with indicator LEDs for all channels
- Automation pHAT: 1 relay, 3 analog inputs, 3 digital inputs, 3 digital outputs, no indicator LEDs
- Automation HAT Mini: 3 relays, 3 analog inputs, 3 digital inputs, 3 digital outputs, no indicator LEDs, but includes a 0.96" color LCD display
API Reference
Initialization
// Create an AutomationHAT instance
let mut hat = new;
You can choose between:
HatType::AutomationHATHatType::AutomationPHATHatType::AutomationHATMini
Relays
Relays provide a high-power switch controlled by the Raspberry Pi.
// Set relay state (true = on, false = off)
hat.relays.one.write?; // Only available on HAT and pHAT
hat.relays.two.write?; // Only available on HAT and pHAT
hat.relays.three.write?;
// Get relay state
let state = hat.relays.three.value;
Digital Outputs
Digital outputs provide 5V signals for controlling external devices.
// Set output state (true = on, false = off)
hat.outputs.one.write?;
hat.outputs.two.write?;
hat.outputs.three.write?;
// Get output state
let state = hat.outputs.one.value;
Digital Inputs
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
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?;
Display (Automation HAT Mini only)
The Automation HAT Mini includes a 0.96" 160x80 color LCD display.
if let Some = hat.display
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgements
- Pimoroni for creating the Automation HAT hardware
- embedded-hal for the Rust embedded abstractions