Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/emeric-martineau/pcf857x-simple-rs
A very simple crate to manage PCF8574 and PCF8575 hardware
https://github.com/emeric-martineau/pcf857x-simple-rs
Last synced: about 1 month ago
JSON representation
A very simple crate to manage PCF8574 and PCF8575 hardware
- Host: GitHub
- URL: https://github.com/emeric-martineau/pcf857x-simple-rs
- Owner: emeric-martineau
- License: mit
- Created: 2024-03-11T17:30:02.000Z (10 months ago)
- Default Branch: master
- Last Pushed: 2024-04-10T15:58:29.000Z (9 months ago)
- Last Synced: 2024-11-15T09:25:26.320Z (about 2 months ago)
- Language: Rust
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Manager of PFC8574 and PFC8575.
This crate is very simple manager of hardware pcf8574 and pcf8575.
Crate was tested on ESP32 WROOM-32.
See rust documentation.
## Compatibility
| pcf857x-simple | embedded-hal |
|----------------|--------------|
| 0.1.x | v0.2.x |
| 0.2.x | v0.2.x |## Example of use
```rust
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));
}
}
```