This repository contains two Python scripts for interfacing with PZEM-017 Modbus energy monitoring devices. The scripts allow you to read the data from the devices and change their parameters.
Install Python 3 from the official website.
Install the required Python libraries by running the following command in your terminal or command prompt:
pip install minimalmodbus pyserial
Clone this repository or download the Python scripts pzem_reading.py
and change_settings.py
.
git clone https://github.com/croutonso/PZEM017modbus.git
This script reads data from the PZEM-017 device and displays the voltage, current, power, and energy values.
Open pzem_reading.py
in a text editor and set the DEVICE_ADDRESS
, PORT
, and other parameters according to your device and connection.
Save the changes and close the text editor.
Open a terminal, navigate to the directory containing pzem_reading.py
, and run the following command:
python pzem_reading.py
The script will display the voltage, current, power, and energy values.
This script allows you to change the parameters of the PZEM-017 device, such as high and low voltage alarm thresholds, slave address, and current range (PZEM-017 only).
Open change_settings.py
in a text editor and set the SLAVE_ADDRESS
, DEVICE_PORT
, and other parameters according to your device and connection.
Save the changes and close the text editor.
Open a terminal, navigate to the directory containing change_settings.py
, and run the following command:
python change_settings.py
The script will display a menu with options to change various device parameters.
Q: Does the slave address matter?
A: The slave address is important to avoid conflicts between multiple Modbus devices connected to the same computer. Each device should have a unique slave address to prevent clashes and ensure proper communication.
Q: What should I do if I already have another Modbus device connected to my computer?
A: Make sure that each Modbus device has a unique slave address. You can change the slave address of the PZEM devices using the change_settings.py
script. Follow the steps in the Usage section to run the script and change the slave address.
Q: What if the script does not work or shows an error message?
A: Check the following:
DEVICE_ADDRESS
, PORT
, and other parameters in the script are correctly set according to your device and connection.minimalmodbus
and pySerial
).Q: Where can I find more information about the PZEM-004T and PZEM-017 devices?
A: You can find more information about the devices on their respective product pages:
Q: How do I identify the correct port for my device on my Raspberry Pi or Linux system?
A: You can run the following command to list available serial ports:
dmesg | grep tty
Look for lines containing ttyUSB
or ttyAMA
. The port name should look like /dev/ttyUSB0
or /dev/ttyAMA0
. Use this port name in the PORT
variable in the Python scripts.
Q: Can I use these scripts on a Windows system?
A: Yes, these scripts can be used on a Windows system. You will need to adjust the PORT
variable in the Python scripts to the appropriate COM port for your device (e.g., COM3
). You can check available COM ports in the Device Manager under "Ports (COM & LPT)".
Q: How do I install the minimalmodbus and pySerial libraries on a Raspberry Pi or Linux system?
A: You can install the libraries using the following command:
pip3 install minimalmodbus pyserial
Make sure you are using pip3
for Python 3 installations.
Q: How do I run the scripts with Python 3 on a Raspberry Pi or Linux system?
A: You can run the scripts with Python 3 using the following command:
python3 script_name.py
Replace script_name.py
with the name of the script you want to run, such as pzem_reading.py
or change_settings.py
.