Pzem-017 Datasheet

0 views
Skip to first unread message

Agenor Ramadan

unread,
Aug 3, 2024, 4:18:46 PM8/3/24
to miczbatickret

Or you make a little circuit with Comperators (LM339 for example) where you measure the phase across the current transformer (secondary side). Could get powered by the 3,3V LDO on the PZEM004. Then you have current and phase and can thus determine the current flow.

As I'm currently working with the PZEM004 myself maybe, you can answer my question. I don't get responses from it. Have you used the command from the datasheet = B0 C0 A8 01 01 00 A1, HEX? This works for you?
Have you used Uart with 9600, 8N2?

In this article, I will show you how I modified the cheap and popular panel power meters from Peacefair to read data into a microcontroller. You can get one and modify yourself using this guide and the provided example code, or you could buy a pre-modded version to get up and running in no time.

The idea for this came up when I installed a power meter in my electric go kart. I wanted to build a data logging system for it that can record the power stats along with some other metrics. One option was to add another power monitoring module that could record the current and voltage but I wasnt able to easily find one that can handle the voltage and current range of the go kart. And the added complexity didnt sit right with me since there was already a sensor isntalled.

I looked up if anyone has done a hack on these meters before where they tapped the data stream and were able to read it from a microcntroller. I only found one guide in which an AC power meters is hacked. The DC meters have a different architechture and the existing hack wouldnt work. So I decided to hack it myself, how hard could it be?

Note: I earn a small commission on Amazon purchases made through this post. But rest assured, my recommendations are not influenced by that at all. Any revenue will most likely go straight back into buying some more tools or supplies.

I drew up a rough schematic for the power meter and started looking up the components. My next choice to tap into the data was going to be at the interface between the microcontroller and the display driver. I identified the display driver to be the TM1621B and found its datasheet. The hacking could commence.

Unfortunately, on the PZEM-031 (V4.0) that I was modifying, there were no easy locations to access the data signals, so I had to solder thin wires to the fine pitch microcontroller leads. I later learned that on the PZEM-051 (V5.0), there are easy to access test points that the wires can be soldered to.

The connection between display driver and microcontroller consists of CS, RD, WR and Data lines. Looking at the datasheet, the communication protocol isnt exactly SPI, but its close enough that we could use SPI to read it, or so I thought.

Looking at the CS line, I could tell that there were 16 packets of data, each packet 17 bits long. That made sense when looking at the datasheet since the first 3 bits were for the packet type, next 6 were for the memory address and the last 8 were two 4 bit numbers for to write to that address bit. These numbers would be the actual data that correspond to the digits being displayed.

I tried to decode the data being sent at each address to the number being displayed but I couldnt determine exactly what each bit corresponded to. So I decided to switch over to reading this data from an Arduino instead.

I thought reading the data would be fairly trivial. The first mistake I made was to hook it up to an Arduino Mega which has a 5V logic level whereas the microcontroller in the power meter was 3.3V logic. I switched over to an ESP32 instead. The next challenge was to read 17 packets of data. Most SPI libraries are playing a role in the SPI transaction and cant just sniff the data. I was able to find a library to just read the data but it could only read in 8 bit chunks. I tried to get away with reading 8 bits but the last bit was important and without it, I would be able to discern between some numbers.

The next challenge was to decode the data values from the packets and correspond them to the digit being displayed on the screen. Instead of trying to figure out the mapping of each bit to the display, I instead combined the two values being written per packet into a single decimal number. I then used trial and error to determine the decimal number for each digit. I formed a lookup table and was able to decode the data.

I tested the decoding for the PZEM-031 and PZEM-051 but I could have missed some corner case where the decimal moves or something like that. If you find any issues, please file an issue on the github repo.

The code is written in Arduino and I tested it on the ESP32-WROOM dev board. It could be ported to other boards but they would need to have interrupt capability on the clock and select pin and have 3.3V logic level.

I wont go over the code in detail here but I have tried to add comments to make it as easy to understand as possible. Basically I am reading the data communication using interrupts, cleaning them up and decoding them to get the values I am interested in. The harder part of the code would be to understand the various bit operations I am doing since a lot of that was done by looking at the data on the logic analyzer.

This was a fun little mini project and I was able to achieve the goal I set out for. You should be able to replicate the modification as well but if you are interested in getting pre-modified power meters, you can contact me. In any case, thank you for reading through and I hope you benefited from this post.

We always adhere to the principle of quality and reputation, and continuously improve product quality to ensure that we provide customers with the most perfect UL1015 PVC Hook Up Wire/lead Wire, LSOH Power Supply Cable, RG316 coaxial cable. Innovation is one of our core values and we strive to deliver innovative solutions for our customers that bring value to their business. By creating a complete after-sales service system and accepting customer feedback on products, we are constantly updating and improving product quality and services.

Should the bulk ul approved control cable ul2464 made in China caters to your requirement, welcome to get the datasheet with us. As one of the leading manufacturers and suppliers in China, we also offer the customized service.

Suitable for electronic equipment matching wiring, inside and outside of machine (such as office computer system, recorder, X machines etc.)
Can be used as a measurement, detection and control cable.Used in machine tool manufacturing, equipment installation, power plant, heating and air-conditioning systems, refrigeration equipment, office automation equipment and data processing system.

Good heat resistance, cold resistance and flame retardant.
Able to bear external mechanical forces and certain wear resistance.
Wire clear core color, simple and convenient for installation.
Shielding anti-interference characteristics

Besides providing high-quality Awm Style 80c 300V Wire 2464 3 Core Cable for customers in different industries, we also provide customers with technical support, professional solutions and other personal instant services. We adhere to the innovation-driven development strategy and have achieved a number of core key technology breakthroughs. Our enterprise has become a new star of the industry with its strong talent advantages, strong technical advantages and scale advantages.

Hi,

I've looked into this meter before. Given the fact that this is a 3-phase device (the v9821 that is in the ZMAI-90 is a single phase metering chip) and because of the RS-485 bus capability and the type of protocol that is detailed in the product page, it is likely a very different device. It is of course also an interesting target for reverse engineering just as done with the ZMAI-90..

Cheers


Hello friend, congratulations for the post. I recently purchased a Zmai-90 and it is not registering energy consumption in the Tuya application. It does not register and does not record. I would like to leave it in original firmware, but it would work. My Zmai90 has current firmware 1.0.2 and I found that updated firmware would be 1.0.6. Would the current firmware update (1.0.6) flash? Would you have this file to provide me? You said you backed up yours. I thank you for your attention.

Hello Rogerio, thanks! I'm sorry, I don't have the original firmware v1.0.6. I converted my own test device to Tasmota before any original firmware update could take place (it was in version 1.0.2). Nevertheless (not sure if is true or not), I read that Tuya firmwares can contain device specific data, preventing a firmware image extracted from one device, to work in another device.

Cheers

Thanks for the reply friend. Could you give me a hint as to why my device does not register or record energy consumption in the application?

I bought 2 devices and both are having the same problem.

Hello Rogerio, it is difficult to troubleshoot just based on the behaviors you describe. It is possible that you are not provisioning it with the correct Wifi password? Can it be the case that you Wifi access point uses older encryption standards such as WEP? It can be the case that open or unsafe encryption is unsupported by these Tuya firmwares..honestly my experience with stock firmware was short and not incredibly satisfying. Sorry for not being able to help further..

Hello Mark,

Can you try increasing the log level so that we can have more details? Go to Configuration > Configure Logging > Web log level > 4 More debug.

Could you share the output of the State command? Do you have a solid wifi connection with the device?

You may also want to share this behavior as an issue in the Tasmota project ( )

Thank you

Cheers

Hi , thank's to your post i was able to do what you wrote but instead of using home assistant, i'm using openhab...could you help me please to find a way to analyze and convert the string from the MQTT message into some ussefull items? thank you very much

c80f0f1006
Reply all
Reply to author
Forward
0 new messages