I succes use the PZEM to arduino nano and wemos mini D1, but cant use in TTGO. can you help me to solve the problem. when i compile to TTGO, always error... this is error message when i compile to TTGO
Code: Select all
Arduino: 1.8.9 (Windows 10), Board: "ESP32 Dev Module, Disabled, Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS), 240MHz (WiFi/BT), QIO, 80MHz, 4MB (32Mb), 921600, None"
C:\Users\user\sketchbook\libraries\PZEM-004T-v30-master\PZEM004Tv30.cpp: In constructor 'PZEM004Tv30::PZEM004Tv30(uint8_t, uint8_t, uint8_t)':
C:\Users\user\sketchbook\libraries\PZEM-004T-v30-master\PZEM004Tv30.cpp:62:5: error: 'SoftwareSerial' was not declared in this scope
SoftwareSerial *port = new SoftwareSerial(receivePin, transmitPin);
^
C:\Users\user\sketchbook\libraries\PZEM-004T-v30-master\PZEM004Tv30.cpp:62:21: error: 'port' was not declared in this scope
SoftwareSerial *port = new SoftwareSerial(receivePin, transmitPin);
^
C:\Users\user\sketchbook\libraries\PZEM-004T-v30-master\PZEM004Tv30.cpp:62:32: error: expected type-specifier before 'SoftwareSerial'
SoftwareSerial *port = new SoftwareSerial(receivePin, transmitPin);
^
exit status 1
Error compiling for board ESP32 Dev Module.[/quote]
and this is my simple program
[code=simple program]#include <PZEM004Tv30.h>
#include <Wire.h>
#include "SH1106Wire.h"
#include "SH1106.h"
#include "images.h"
SH1106 display(0x3c, SDA, SCL);
PZEM004Tv30 pzem(25,27);
void setup() {
Serial.begin(115200);
Serial.println();
Serial.println();
display.init();
display.flipScreenVertically();
display.setFont(ArialMT_Plain_10);
pzem.resetEnergy();
pzem.setAddress(0x42);
}
void drawTextFlowDemo() {
display.setFont(ArialMT_Plain_10);
display.setTextAlignment(TEXT_ALIGN_LEFT);
display.drawStringMaxWidth(0, 0, 128, "TES 1 2 3 INDRA" );
}
void loop() {
display.clear();
// draw the current demo method
display.setTextAlignment(TEXT_ALIGN_RIGHT);
display.drawString(10, 128, String(millis()));
drawTextFlowDemo();
display.display();
float volt = pzem.voltage();
Serial.print("Voltage: ");
Serial.print(volt);
Serial.println("V");
float cur = pzem.current();
Serial.print("Current: ");
Serial.print(cur);
Serial.println("A");
float powe = pzem.power();
Serial.print("Power: ");
Serial.print(powe);
Serial.println("W");
float ener = pzem.energy();
Serial.print("Energy: ");
Serial.print(ener,3);
Serial.println("kWh");
float freq = pzem.frequency();
Serial.print("Frequency: ");
Serial.print(freq);
Serial.println("Hz");
float pf = pzem.pf();
Serial.print("PF: ");
Serial.println(pf);
delay(1000);
}