Expand description
An embedded-hal driver for the PZEM004T energy monitor.
The driver must be initialized by passing a Serial interface peripheral
to the Pzem::new
function, which in turn will create a driver instance, with the slave address specified,
or the default general address for a single-slave environment 0xf8.
§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();
}Structs§
- Measurement
- Measurement results stored as the 32-bit floating point variables.
- NoTimeout
- Empty struct to satisfy Rust’s type requirements, when using
Nonefor thetimeoutparameter. - Pzem
- Struct representing a PZEM004T sensor connected to a serial bus.
Enums§
- Error
- Errors which can occur when attempting to communicate with PZEM004T sensor.