https://github.com/iostapyshyn/pzem004t
Rust embedded-hal driver for PZEM004T energy monitor
https://github.com/iostapyshyn/pzem004t
embedded embedded-hal embedded-hal-driver embedded-rust pzem004t rust
Last synced: about 1 year ago
JSON representation
Rust embedded-hal driver for PZEM004T energy monitor
- Host: GitHub
- URL: https://github.com/iostapyshyn/pzem004t
- Owner: iostapyshyn
- License: apache-2.0
- Created: 2020-03-11T15:53:07.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-05-21T13:07:32.000Z (about 6 years ago)
- Last Synced: 2025-01-22T20:35:33.224Z (over 1 year ago)
- Topics: embedded, embedded-hal, embedded-hal-driver, embedded-rust, pzem004t, rust
- Language: Rust
- Homepage:
- Size: 40 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
pzem004t
====
[](https://crates.io/crates/pzem004t)
[](https://docs.rs/pzem004t/)
[](LICENSE-MIT)
[](LICENSE-APACHE)
[](https://github.com/iostapyshyn/pzem004t/actions?query=workflow%3ARust)
An embedded-hal driver for the PZEM004T energy monitor.
A [CLI](https://github.com/iostapyshyn/pzem-cli) for the library is available and can be
run on all major operating systems (uses [serialport](https://crates.io/crates/serialport) crate).
## Examples
Examples can be found in the [`examples/`](https://github.com/iostapyshyn/pzem004t/tree/master/examples) directory.
### Read the measurements off the sensor every second
```rust
let mut pzem = pzem004t::Pzem::new(serial, None).unwrap();
let mut m = pzem004t::Measurement::default();
loop {
match pzem.read(&mut m, Some((&mut tim, TIMEOUT))) {
Err(e) => hprintln!("Could not read PZEM004T: {}", e).unwrap(),
Ok(()) => {
hprintln!("Voltage: {:.1} V", m.voltage).unwrap();
hprintln!("Current: {:.3} A", m.current).unwrap();
hprintln!("Power: {:.1} W", m.power).unwrap();
hprintln!("Energy: {:.3} kWh", m.energy).unwrap();
hprintln!("Frequency: {:.1} Hz", m.frequency).unwrap();
hprintln!("Power factor: {:.2}", m.pf).unwrap();
hprintln!("Alarm: {}\n", m.alarm).unwrap();
}
}
tim.start(1.hz());
block!(tim.wait()).unwrap();
}
```
## License
This project is licensed under either of
* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
http://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT](LICENSE-MIT) or
http://opensource.org/licenses/MIT)
at your option.