The PZEM004Tv30 class can be initialized using different serial interfaces depending on your hardware (AVR, ESP8266, ESP32, etc.).
Hardware Serial (Recommended)
For most boards, pass a reference to a HardwareSerial object. On ESP32, you must also specify the receive and transmit pins.
Software Serial (AVR and ESP8266 only)
If using AVR or ESP8266, you can pass a SoftwareSerial object. Note that the constructor PZEM004Tv30(uint8_t receivePin, uint8_t transmitPin, uint8_t addr) is deprecated; you should create a SoftwareSerial object first and pass it to the constructor.
Stream Interface
You can also pass any object that inherits from Stream.
Default Address
The default Modbus address is 0xF8 (PZEM_DEFAULT_ADDR).
// Hardware Serial (Standard)
PZEM004Tv30 pzem(Serial1);
// Hardware Serial (ESP32 with custom pins)
PZEM004Tv30 pzem(Serial1, RX_PIN, TX_PIN);
// Software Serial (AVR/ESP8266)
SoftwareSerial swSerial(RX_PIN, TX_PIN);
PZEM004Tv30 pzem(swSerial);
// Using a custom address
PZEM004Tv30 pzem(Serial1, 0x12);