Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for PZEM004T energy monitor for 3 phase - request #2315

Closed
roblad opened this issue Apr 1, 2018 · 193 comments

Comments

@roblad
Copy link

@roblad roblad commented Apr 1, 2018

Hi,

Is it possible add USE_PZEM004T and add support for PZEM004T Energy monitor for 3 phase by using
USE_SERIAL_BRIDGE and report each phase through that functionality ? May be there is possibility to use 3 phase config for USE_PZEM004T as it is in that project:

https://github.com/apreb/eNode

@roblad

This comment has been minimized.

Copy link
Author

@roblad roblad commented Apr 13, 2018

Hi,

Is it possible to add 3 PZEM004T in one node?

Rgds,
RL

@0x3333

This comment has been minimized.

Copy link

@0x3333 0x3333 commented Apr 26, 2018

I'm looking for the same thing.

As long as I can tell, each PZEM004T can be directly addressed, so you can hookup as many PZEM004T as you can in the same UART, when you read, you send the "ip address" of each module.

But the code in xdrv_03_energy.ino is not able to read from multiple sources. When I get my units I'll work on this. Don't know if this can be accomplished, but would be great.

@roblad

This comment has been minimized.

Copy link
Author

@roblad roblad commented Apr 26, 2018

Hi,
It means that when I change IP for each PZM and plug 3 of themas a 3 soft serials or plug 3 of them to 1 serial ? Could you sent me a private mesage if you could with more detailed manual or some code that you hook haw it looks. I am not such expert as you it will be very usfull :-)

Thanks,

@0x3333

This comment has been minimized.

Copy link

@0x3333 0x3333 commented Apr 26, 2018

I mean plugging all the 3 PZEM in the same hardware/soft serial, like this:

smms_ttl

The diode can be a BAT45, the pullup resistor can be a 10K to 5V.

But you need to program the PZEM address before using this method, the address can be sequential, like 0.0.0.1,0.0.0.2,0.0.0.3, it is not really a IP address.

But the tasmota must be changed to accommodate multiple meters, you can test using an arduino.

@roblad

This comment has been minimized.

Copy link
Author

@roblad roblad commented Apr 26, 2018

Hi,

Many thanks, but I have a question, may be stupid, Master UART means tasmota serial ? Yes ?

And all of the slaves there are PZEMs Am I right ?

Have you got it on your Arduino/ESP connected ?

I will try it ofcource but first of all I am working for MQTT bridge through serial bridge of Tasmota - I have Nodes based on it:

https://github.com/artekw/sensnodetx
https://github.com/artekw/sensnodetx

and receiver basenode which prints output to serial as JSON, I am working on www displaing all recaived data as normal sensors pluged to tasmota, next one task will be the hook of PZM004 ino.

and

also see that:

https://github.com/apreb/eNode/issues/1#issuecomment-354369777

@0x3333

This comment has been minimized.

Copy link

@0x3333 0x3333 commented Apr 26, 2018

Yes, Tasmota master, PZEM slaves. Yes, connected to ESP.

@roblad

This comment has been minimized.

Copy link
Author

@roblad roblad commented Apr 26, 2018

Hi,

Could you share Your ino code for PEZM for further testing, I have 3 already :-) after 2 months shipment :-) ?

@0x3333

This comment has been minimized.

Copy link

@0x3333 0x3333 commented Apr 27, 2018

Well, I don't have it actually, but here is some to start with:

#include <PZEM004T.h>

PZEM004T pzem(10, 11);

IPAddress ip[3];

void setup() {
  Serial.begin(9600);

  ip[0] = IPAddress(0, 0, 0, 1);
  ip[1] = IPAddress(0, 0, 0, 2);
  ip[2] = IPAddress(0, 0, 0, 3);
}

void loop() {
  for (uint8_t j ; j < 3 ; j++) {
    Serial.print("ID: ");
    Serial.print(j);
    Serial.print(": ");
    float v = pzem.voltage(ip[j]);
    if (v < 0.0)
      v = 0.0;
    Serial.print(v);
    Serial.print("V; ");

    float i = pzem.current(ip[j]);
    if (i >= 0.0) {
      Serial.print(i);
      Serial.print("A; ");
    }

    float p = pzem.power(ip[j]);
    if (p >= 0.0) {
      Serial.print(p);
      Serial.print("W; ");
    }

    float e = pzem.energy(ip[j]);
    if (e >= 0.0) {
      Serial.print(e);
      Serial.print("Wh; ");
    }
    Serial.println();
  }

  delay(1000);
}

Remember to call pzem.setAddress(ip[X]); with only one connected to set it's internal address.

@roblad

This comment has been minimized.

Copy link
Author

@roblad roblad commented Apr 27, 2018

Hi,

Many thanks, but what do you mean 👍
Remember to call pzem.setAddress(ip[X]); with only one connected to set it's internal address.

I did not catch you, it means that I have to set the pzem.setAddress(ip[X]) step by step with plug only one PZEM for initial setup of IP ? And next plug all of them for finale mastering am I right ?
What about Save set values in PZEM, will they disappear after power lost ?
What do you mean "with only one connected to set it's internal address"

@0x3333

This comment has been minimized.

Copy link

@0x3333 0x3333 commented Apr 28, 2018

Buddy, dont get me wrong, but you should do your homework...

Each PZEM have an Address. You must set a unique address to each one, individually. That's what I meant with setAddress. Create another sketch to set the addresses. Then run the one I provided.

@roblad

This comment has been minimized.

Copy link
Author

@roblad roblad commented Apr 28, 2018

Hi,

" but you should do your homework" yes I will :-), thanks for explanation, I let you know about my results :-)

@0x3333

This comment has been minimized.

Copy link

@0x3333 0x3333 commented Apr 29, 2018

Great, as soon as I get my sonoffs, I'll let you know my findings.

@asking23

This comment has been minimized.

Copy link

@asking23 asking23 commented May 28, 2018

Any updates ? but in this way we would never be able to poll 3 Phases Simultaneously to Make Graph/Trend 3 Phases. Each Consecutive reading will have 1 Second Interval so wont be able to correlate voltage on each phase to each other.

@0x3333

This comment has been minimized.

Copy link

@0x3333 0x3333 commented May 29, 2018

I'm looking to do the readings in the same time slice. But I'll need to change the code. I'm on vacations now, next week I'll work on it.

@0x3333

This comment has been minimized.

Copy link

@0x3333 0x3333 commented Jun 12, 2018

Here I'm again. I read the code and believe that create another xdrv for this is the best option to me. Change a code that is shared with other devices to add 2 more phases will require a lot of effort and will not benefit the others. I'm looking to create a xdrv_13_energy_3phases.ino driver, especifically to PZEM004T, this way it will not add more line of codes to other energy meters and increased complexity.

I've only an hour at night to work on side projects, but will give it some attention.

@arendst , do you believe that this is the right thing to do? What is your direction on this matter?

Thanks!

@roblad

This comment has been minimized.

Copy link
Author

@roblad roblad commented Jun 12, 2018

Hi,

Where is xdrv_13_energy_3phases.ino ?

@0x3333

This comment has been minimized.

Copy link

@0x3333 0x3333 commented Jun 12, 2018

There is no xdrv_13_energy_3phases.ino, I'm about to write it.

@roblad

This comment has been minimized.

Copy link
Author

@roblad roblad commented Jun 12, 2018

aaaaaaa :-)

@stale

This comment has been minimized.

Copy link

@stale stale bot commented Jul 27, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jul 27, 2018
@0x3333

This comment has been minimized.

Copy link

@0x3333 0x3333 commented Jul 27, 2018

Well, I changed to ESPurna, and in that firmware, it's simply not possible, it is too slow to read all magnitudes from all sensors. I'm working in a custom board with an Arduino Pro Mini that will read all PZEM(Max 6 devices) and will communicate using I2C, all measurements will be read in a single call. I'll let you know the progress.

@stale stale bot removed the stale label Jul 27, 2018
@rt400

This comment has been minimized.

Copy link
Contributor

@rt400 rt400 commented Aug 21, 2018

any new with this ?

@0x3333

This comment has been minimized.

Copy link

@0x3333 0x3333 commented Aug 21, 2018

I'm finishing the custom board, the board will read up to 6 PZEM004T and will communicate using I2C/SPI. It constantly read the PZEM and buffer the responses, when asked the response is instantaneous. In my board I also added a ESP-01 module, so I don't need a Sonoff Basic or alike. But it is not finished yet...

screen shot 2018-08-21 at 11 07 35

screen shot 2018-08-21 at 11 07 50

@0x3333

This comment has been minimized.

Copy link

@0x3333 0x3333 commented Aug 21, 2018

Probably I will use this repo: https://github.com/0x3333/powermeter

But the code probably will change...

@rt400

This comment has been minimized.

Copy link
Contributor

@rt400 rt400 commented Aug 21, 2018

https://github.com/apreb/eNode
did you see this ?
its looks that he success to do that..
can you share the diagram of connection ?
and i understant that you connect directly to wemos or arduino board ..so why use also in spi or i2c ?

@0x3333

This comment has been minimized.

Copy link

@0x3333 0x3333 commented Aug 21, 2018

Yes, I saw that.

In my case, the arduino pro mini(Not running arduino) is connected to a ESP-01(Running Espurna, but can work with any other firmware) using a spi connection. The arduino is only doing the hard work.

@roblad

This comment has been minimized.

Copy link
Author

@roblad roblad commented Aug 21, 2018

Hi,

Great, but will you add that to tasmota as a 3 phase module ?

@0x3333

This comment has been minimized.

Copy link

@0x3333 0x3333 commented Aug 21, 2018

Sure, @arendst will need to approve a custom driver, but sure.

@sendorm

This comment has been minimized.

Copy link

@sendorm sendorm commented Nov 1, 2019

@rt400 do you use the 1k resistor fix, can you provide a picture of your setup and also what are your pzem’s versions? Thank you

@localhost61

This comment has been minimized.

Copy link
Contributor

@localhost61 localhost61 commented Nov 1, 2019

@rt400 I guess you mean the 10kΩ pullup. 1kΩ may be too much current to sink for the slave to achieve a low level.

@Jason2866

This comment has been minimized.

Copy link
Contributor

@Jason2866 Jason2866 commented Nov 1, 2019

The 1k resistor is needed on every Pzem device to make the TTL level compatible to 3.3V
The 10k resistor is needed as bus pullup!
So you have to install 3 pieces of 1k resistors and one 10k resistor

@sendorm

This comment has been minimized.

Copy link

@sendorm sendorm commented Nov 1, 2019

@Jason2866 When the 1K is connected, the pzem is still powered with 5Vs right?

@localhost61

This comment has been minimized.

Copy link
Contributor

@localhost61 localhost61 commented Nov 1, 2019

@sendorm Yes! That's the reason why.

@sendorm

This comment has been minimized.

Copy link

@sendorm sendorm commented Nov 1, 2019

Ok. I have pzem004t v2’s and they do readily work with no 1k ohm and being directly connected to 5V with a 8266. Could not get any info on the net on v2 sensors and what is the difference with v1.
Could not get to use them with the schottky diodes and 3 phase setup though. Well I just bought v3’s in the mean time.

@localhost61

This comment has been minimized.

Copy link
Contributor

@localhost61 localhost61 commented Nov 2, 2019

ESP8266 is powered in 3.3V and not more than 3.6V, There is a voltage regulator on a Wemos D1 mini that convert the 5V into 3.3V. It's really not advisable to interconnect the ESP I/O with 5V powered sensors without caution. There are protection diodes on every ESP I/O intended to shorten voltage spikes over 3.6V. If the overvoltage duration is too long, those diodes will blow and the MCU will follow soon. With 1kΩ serial resistor you reduce the stress on the ESP I/O and the protective diodes will be able to handle the overvoltage.

@sendorm

This comment has been minimized.

Copy link

@sendorm sendorm commented Nov 2, 2019

ok thank you and you are right.
But I just couldn’t get the pzems to work when a 1K is connected. Also the CEO, Teo Swee Ann has stated that pins are indeed 5V tolerant.
https://www.facebook.com/groups/1499045113679103/permalink/1731855033731442/?hc_location=ufi
Mind you that my pzems are v2.

@localhost61

This comment has been minimized.

Copy link
Contributor

@localhost61 localhost61 commented Nov 2, 2019

Thank's for the input ;-)

@rt400

This comment has been minimized.

Copy link
Contributor

@rt400 rt400 commented Nov 2, 2019

@Jason2866 @localhost61 What about the 10K resistor pull-up you mean ???
here is my schema
image

@localhost61

This comment has been minimized.

Copy link
Contributor

@localhost61 localhost61 commented Nov 2, 2019

@rt400 Your schema has several divergencies with the one @0x3333 provided here.

  • On the Wemos side you should cross RX and TX.
  • The pullup is missing on the Wemos RX side, where the diodes should arrive.

Following Telecom industry standards, RX and TX are intended to be crossed because RX is a Receiver and TX a Transmitter, some manufacturer add confusion when they write on the Sensor pinout the label of the MCU pins they connect too. It applies for buses and is more intuitive for newbies, but it's wrong for "point to point" serial connection.

I remind I have no experience with PZEM, I only own Eastron SDM modbus and Neo Coolcam energy monitors.

@rt400

This comment has been minimized.

Copy link
Contributor

@rt400 rt400 commented Nov 2, 2019

@localhost61 i correct the schema. i draw by mistake but on real its in cross..
in @0x3333 schema he connect from 5v a 10Kohm resistor to TX . so the VCC connect direcly to 5v ?
don't understantd exacly the schema..

@Jason2866

This comment has been minimized.

Copy link
Contributor

@Jason2866 Jason2866 commented Nov 2, 2019

Yes, you connect 5V via the 10k Ohm resistor to the TX line which goes to RX input of the ESP
This resistor is called "PullUp" without this resistor it will 100% NOT work

@rt400

This comment has been minimized.

Copy link
Contributor

@rt400 rt400 commented Nov 2, 2019

@Jason2866 thank..
so one wire from ESP 5v to PZEM 5V and add resistor from ESP 5v to ESP TX ?

@Jason2866

This comment has been minimized.

Copy link
Contributor

@Jason2866 Jason2866 commented Nov 2, 2019

Add resistor to the line where the diodes are where it goes to ESP

@rt400

This comment has been minimized.

Copy link
Contributor

@rt400 rt400 commented Nov 2, 2019

@Jason2866 OK i will add it and respond if the problem was fixed.
many thanks

@Jason2866

This comment has been minimized.

Copy link
Contributor

@Jason2866 Jason2866 commented Nov 2, 2019

I clarified my text!

@localhost61

This comment has been minimized.

Copy link
Contributor

@localhost61 localhost61 commented Nov 2, 2019

Wemos mini 5V, not ESP 5V, on the module the ESP run at 3.3V

@rt400

This comment has been minimized.

Copy link
Contributor

@rt400 rt400 commented Nov 3, 2019

@Jason2866 with adding the pull-up resistor won't fix the problem , but i install diffrent power supply and now its look ok. i keep check it..

@sheminasalam

This comment has been minimized.

Copy link

@sheminasalam sheminasalam commented Nov 20, 2019

Can I use the transformer coil with the phase wire instead of the neutral wire to read the values? I know the coil is instructed to be used with neutral wire. But in my case there is no separate neutral wires for the 3 phases and i want to read the values of all the three phases separately. How can I do this if there is no separate neutral line for each phases?

@jziolkowski

This comment has been minimized.

Copy link
Contributor

@jziolkowski jziolkowski commented Nov 20, 2019

I use my CT's on L wires and it works well. TBH I have no idea how else you could measure 3 phase installation using N wire only, because by design 3 phase has only one N wire.

@sheminasalam

This comment has been minimized.

Copy link

@sheminasalam sheminasalam commented Nov 22, 2019

I have two questions.

  1. what are the specifications of the ph junction diode used to connect to TX?
  2. If i use a sonoff basic instead of wemos, do i have to connect a 5v external power supply with 10k resistor to TX ?
@Jason2866

This comment has been minimized.

Copy link
Contributor

@Jason2866 Jason2866 commented Nov 22, 2019

  1. schottky diode like BAT45
  2. dont use a sonoff basic for
@localhost61

This comment has been minimized.

Copy link
Contributor

@localhost61 localhost61 commented Nov 22, 2019

dont use a sonoff basic for

... security reason regarding hazardous voltage and only 3.3V, no 5V available.

@sheminasalam

This comment has been minimized.

Copy link

@sheminasalam sheminasalam commented Nov 23, 2019

Actually its a salvaged sonoff basic which only works if i give 3.3v to the chip directly kind of the way we power up during flashing. The 220v input side is not usable so hazardous voltage is not an issue. I plan to use a 5v 2.5a dc power supply for the sonoff and the PZEMs. In case of the sonoff i will use a 5v to 3.3v converter. But what about the 5v with 10k resistor. Can i directly conncect the 10k resistor to this 5v power supply?

@localhost61

This comment has been minimized.

Copy link
Contributor

@localhost61 localhost61 commented Nov 23, 2019

In that case, yes, it's the way to do.

@sheminasalam

This comment has been minimized.

Copy link

@sheminasalam sheminasalam commented Dec 2, 2019

I am planning to use ESP01S as my master device which works with 3.3v volt. The above scheme has been discussed with wemos d1 mini in mind which uses 5v as input. I can see that the pullup resistor is connected to 5v vdd in case of TX pin of the salve and then to RX pin of wemos. In my case since the master device is working with 3.3v direct supply which I plan to obtain from a 5v to 3.3v converter, should I connect the pull up resistor of 10k to 3.3v as in the schema have uploaded or to the 5v as shown in the original schema?
please advise.
diode-level-converter

@localhost61

This comment has been minimized.

Copy link
Contributor

@localhost61 localhost61 commented Dec 2, 2019

@sheminasalam ->10k to the 5V.

And, once again the ESP from the Wemos D1 mini is NOT powered with 5V but with the 3.3V supplied by the regulator located on the back of the PCB.
Your schematic is confusing, and doesn't apply here. Where are the TX & RX signal pins? I only see power pins here.
According to Espressif representative you can use a 10k pullup to 5V on the entries of an ESP powered in 3.3V, it won't fry.

@sheminasalam

This comment has been minimized.

Copy link

@sheminasalam sheminasalam commented Dec 3, 2019

Ok Thanks.. I was suggested schottky diodes similar to BAT45 for connecting to TX of slave. I have IN4148 with me. Even though it is not a schottky diode it is fast switching. Can i use it instead of BAT45?

@localhost61

This comment has been minimized.

Copy link
Contributor

@localhost61 localhost61 commented Dec 3, 2019

It may work but not as good as a BAT45.
So use it for your tests in the meanwhile but get some BAT45 for the long term. Because we want a voltage drop as low as possible so that the RX pin see a Low level when one of the TX pins is low but the others high.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
You can’t perform that action at this time.