Skip to content

Rust embedded-hal driver for PZEM004T energy monitor

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

iostapyshyn/pzem004t

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pzem004t

crates.io docs.rs license license Rust

An embedded-hal driver for the PZEM004T energy monitor.

A CLI for the library is available and can be run on all major operating systems (uses serialport crate).

Examples

Examples can be found in the examples/ directory.

Read the measurements off the sensor every second

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

at your option.

About

Rust embedded-hal driver for PZEM004T energy monitor

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages