1 unstable release
new 0.1.0 | Jan 27, 2025 |
---|
#550 in Hardware support
77 downloads per month
12KB
72 lines
PCA9685 RPPal
A rppal-based Rust library for interacting with the Adafruit PCA9685 16-channel PWM/Servo Driver on Raspberry Pi. This library wraps the lower-level I²C operations to simplify setting up the PCA9685 and controlling PWM channels.
Features
- Simple Initialization: Easily create and configure the PCA9685 device at its default I²C address (
0x40
). - Frequency Control: Set the PWM frequency (in Hz) on all 16 channels simultaneously.
- Channel Control: Independently control each channel by specifying ON/OFF counts (0–4095).
- Bulk Control: Set PWM for all channels at once.
Getting Started
Prerequisites
- A Raspberry Pi with I²C enabled (see Raspberry Pi documentation for details).
- Rust (stable toolchain or later).
rppal
crate (installed automatically as a dependency).
Installation
Add the following to your project's Cargo.toml
:
[dependencies]
pca9685-rppal = "0.1.0"
Usage
You can initialize a device, set the PWM frequency and control a single or all channels at once!
let mut pca = Pca9685::new()?;
pca.init()?;
pca.set_pwm_freq(50.0)?;
pca.set_pwm(0, 0, 1500)?;
pca9685.set_all_pwm(0, 0)?;
Thanks
Special thanks to the rppal crate for acting as a base to this crate and to adafruit_pwm_servo_driver for generic implementation details :)
Dependencies
~365KB