5 releases (2 stable)
new 2.0.0 | Jan 29, 2025 |
---|---|
1.0.0 | Dec 29, 2024 |
0.2.0 | Apr 10, 2024 |
0.1.1 | Mar 23, 2024 |
0.1.0 | Mar 14, 2024 |
#471 in Hardware support
123 downloads per month
16KB
236 lines
Manager of PFC8574 and PFC8575.
This crate is very simple manager of hardware pcf8574 and pcf8575.
Compatible with embedded-hal v1 and embedded-hal-bus v1.
Crate was tested on ESP32 WROOM-32.
See rust documentation.
Compatibility
pcf857x-simple | embedded-hal | embedded-hal-bus |
---|---|---|
0.1.x | v0.2.x | No |
0.2.x | v0.2.x | No |
1.x.x | v1 | No |
2.x.x | v1 | Yes |
Example of use
use std::thread;
use std::time::Duration;
use esp_idf_hal::units::KiloHertz;
use esp_idf_sys as _;
use esp_idf_hal::peripherals::Peripherals;
use esp_idf_hal::i2c::I2cDriver;
use esp_idf_hal::i2c::config::Config;
use pcf857x_simple::pcf8574::Pcf8574;
use pcf857x_simple::{Pin, PinState, PCF857X_DEFAULT_ADDRESS};
fn main() {
esp_idf_sys::link_patches();
esp_idf_svc::log::EspLogger::initialize_default();
let peripherals = Peripherals::take().unwrap();
let scl = peripherals.pins.gpio22;
let sda = peripherals.pins.gpio21;
let i2c_config = Config::new()
.baudrate(KiloHertz(100).into())
.scl_enable_pullup(true)
.sda_enable_pullup(true);
let mut i2c_driver = I2cDriver::new(peripherals.i2c0, sda, scl, &i2c_config).unwrap();
let mut expander = Pcf8574::new(&mut i2c_driver, PCF857X_DEFAULT_ADDRESS);
loop {
let _ = expander.clear();
println!("All off");
thread::sleep(Duration::from_millis(1000));
let _ = expander.up_pins(&[Pin::P0]).unwrap();
println!("P0 on");
thread::sleep(Duration::from_millis(1000));
let _ = expander.up_pins(&[Pin::P1]).unwrap();
println!("P0, P1 on");
thread::sleep(Duration::from_millis(1000));
let _ = expander.up_pins(&[Pin::P2]).unwrap();
println!("P0, P1, P2 on");
thread::sleep(Duration::from_millis(1000));
let _ = expander.set_pins(&[PinState::Up(Pin::P0), PinState::Down(Pin::P1), PinState::Down(Pin::P2)]);
println!("P0 = on, P1 = off, P2 = off");
thread::sleep(Duration::from_millis(1000));
}
}
Dependencies
~56KB