olehs / PZEM004T

Arduino communication library for Peacefair PZEM-004T Energy monitor
MIT License
226 stars 114 forks source link

STM32 board issue #53

Closed Pauperman66 closed 5 years ago

Pauperman66 commented 5 years ago

Dear olehs great job indeed! Tried to adapt code PZEM004TDIsplay to Black Pill board equipped with an STM32F103C8 chip. It seems code (without compiler errors) got on stuck once library is invoked. STM32 has 3 HW Serials, all 5V tolerants: I have used (as tipically I do) Serial1 and Serial2. Serial1 is used for communicating with PZEM004T and Serial2 for taking a look to serial monitor. I am using Arduino IDE v1.8.19.0

Code is following and I do not see even any message setting up serial! If I comment all code lines related to PZEM00T it is working…

include "PZEM004T.h"

PZEM004T pzem(PA10,PA9); // (RX,TX) connect to TX,RX of PZEM // ON STM32F103 RX1 is PA10, TX1 is PA9 IPAddress ip(192,168,1,1);

void setup() { Serial1.begin(9600); Serial2.begin(9600); pzem.setAddress(ip); Serial2.print("Serial Port 2 INITIALIZED"); Serial2.println(); }

void loop() {

//float v=0; float v = pzem.voltage(ip); if (v < 0.0) v = 0.0; Serial2.print(v);Serial2.print("V; "); //float i =0; float i = pzem.current(ip); if(i >= 0.0){ Serial2.print(i);Serial2.print("A; "); } //float p =0; float p = pzem.power(ip); if(p >= 0.0){ Serial2.print(p);Serial2.print("W; "); } //float e =0; float e = pzem.energy(ip); if(e >= 0.0){ Serial2.print(e);Serial2.print("Wh; "); }

Serial2.println();

delay(1000); }

olehs commented 5 years ago

I guess you should try HardSerial example instead

Pauperman66 commented 5 years ago

Oooops! YOu're of course RIGHT. Thanks: it works. Happy 2019!