Share this

Methods and Application Examples for Controlling Multiple Frequency Inverters Based on Modbus and Raspberry Pi

2026-04-06 06:16:36 · · #1

Methods and Application Examples for Controlling Multiple Frequency Inverters Based on Modbus and Raspberry Pi

Zhang Shuangchi, Pan Zhiwei

R&D Center of King Fung (China) Machinery Industry Co., Ltd.

Abstract: This paper details the hardware setup, software configuration, and coding methods for using a Raspberry Pi to expand RS485/GPIO modules to control multiple frequency inverters, through examples. The unique advantages and application prospects of this method are highlighted.

Keywords: Modbus_tk, Raspberry Pi, Huichuan frequency converter

1. Introduction

The Raspberry Pi was initially developed for educational purposes. It only had a single 40-pin serial port (GPIO), which limited its use to experiments and simple engineering applications. Now, by expanding the GPIO with an RS485/GPIO module to enable Modbus communication, it can control frequency converters in real time, allowing for the development of practical engineering projects.

Figure 1 is a partial block diagram of a punch press group control system, which is described below.

2. System Configuration

Figure 1 Hardware Configuration Diagram

Hardware configuration:

Inverter: Huichuan MD380+MD380IO1[1], Raspberry Pi: 3B+RS485/GPIOShieldForRPiV3.0.

Software configuration:

Modify Raspberry Pi configuration: Disable Bluetooth and console, dedicate the serial port to Modbus communication. Operating system: Linux; Programming software: Python 3.4.2; Communication software: Modbus tk 0.5.4; Interface programming software: PyQt5.

3. Code compilation

3.1 Configure Modbus_tk

Configure the Modbus_RTU communication mode and set the communication parameters to 9600, 8N1. After reading the inverter parameters, the data needs to be stored in memory for subsequent processing; therefore, import the log file.

importserial

import modbus_tk

import modbus_tk.define sascst

frommodbus_tkimportmodbus_rtu

PORT="/dev/ttyAMA0"

logger=modbus_tk.utils.create_logger('console')

master=modbus_rtu.RtuMaster(serial.Serial(port=PORT,baudrate=9600,bytesize=8,

parity='N',stopbits=1,xonxoff=0))

master.set_timeout(0.5)

master.set_verbose(True)

logger.info("connected")

importlogging

3.2 Splitting Log Files

The inverter's operating data is stored in log files. Over time, these files grow increasingly large, eventually causing system crashes. Therefore, it's necessary to split the log files. Splitting means retaining some records and discarding the rest to reduce file size. There are two splitting methods: ① splitting by file size and ② splitting by time interval. This example uses method ②, splitting every 2 seconds, retaining a maximum of 5 files.

The following code reads 12 data points from the starting address 7000H of inverter #1 and stores them in a log file named "pzw" (the split log file and backup are less than 0.2MB), which is placed in the same folder as the program file.

logger.info(master.execute(1,cst.READ_HOLDING_REGISTERS,28672,12))

fromlogging.handlersimportTimedRotatingFileHandler

if __name__=='__main__':

logFilePath='pzw'

logger = logging.getLogger('')

logger.setLevel(logging.INFO)

handler=TimedRotatingFileHandler(logFilePath,when='s',interval=2,backupCount=5)

formatter=logging.Formatter('%(asctime)s-%(message)s')

handler.setFormatter(formatter)

logger.addHandler(handler)

3.3 Processing Log Files

To accurately obtain the parameters of the five frequency converters, the log file "pzw" needs to be analyzed:

2018-05-25 19:42:11,200-->1-3-112-0-0-12-95-15

2018-05-25 19:42:11,306-<-1-3-24-0-0-14-16-16-232-0-0-0-0-0-0-0-0-0-0-0-1-252-1-240-0-134-87-101

2018-05-25 19:42:11,395-(0,3600,4328,0,0,0,0,0,0,508,496,134)

2018-05-25 19:42:11,396-->2-3-112-0-0-12-95-60

2018-05-25 19:42:11,485-<-2-3-24-0-0-10-140-15-127-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-135-13-10

2018-05-25 19:42:11,527-(0,2700,3967,0,0,0,0,0,0,0,0,135)

2018-05-25 19:42:11,528-->3-3-112-0-0-12-94-237

2018-05-25 19:42:11,614-<-3-3-24-0-0-10-240-15-217-0-0-0-0-0-0-0-0-0-0-0-0-2-0-1-0-32-7-88

2018-05-25 19:42:11,655-(0,2800,4057,0,0,0,0,0,0,2,1,32)

2018-05-25 19:42:11,656-->4-3-112-0-0-12-95-90

2018-05-25 19:42:11,743-<-4-3-24-0-0-13-72-12-7-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-4-33-208-137

2018-05-25 19:42:11,834-(0,3400,3079,0,0,0,0,0,0,0,0,1057)

2018-05-25 19:42:11,835-->5-3-112-0-0-12-94-139

2018-05-25 19:42:11,923-<-5-3-24-0-0-10-200-11-252-0-0-0-0-0-0-0-0-0-0-0-0-0-0-1-4-33-182-98

2018-05-25 19:42:11,965-(0,2760,3068,0,0,0,0,0,0,0,1,1057)

Discoveries: ① After removing the date and time header from each record, the first character is the inverter's station number. ② Records containing inverter parameters have a significantly larger character count than other records. Based on these two characteristics, the following code was developed:

withopen('pzw')asfile_object:

lines = file_object.readlines() # Read the file line by line and store the results in the table lines.

n = len(lines) # Get the length of the table

for i in range(n):

lines[i]=(lines[i])[27:]# Extract the 27th item to the end of the table and save it to the table.

iflen(lines[i])>63and(lines[i])[0]=='1': # Check if the station number and whether it is data

abc1=lines[i] # Store in table abc1

a1=abc1[7:]# Extracts the 7th item to the end of table abc1 and saves it to table a1.

b1 = a1.split('-') # Splits the string into new tables using '-' as the delimiter.

u0_00_1=str(float(int(b1[0])*256+int(b1[1]))/100)#Inverter output frequency

self.l1_1.setText(u0_00_1+'Hz') # Label display

...

u0_11_1=str((int(b1[22])*256+int(b1[23]))/4)#pt100 Left bearing temperature

self.l7_1.setText(u0_11_1+'℃')

iflen(lines[i])>63and(lines[i])[0]=='2':

.................

iflen(lines[i])>63and(lines[i])[0]=='3':

.................

iflen(lines[i])>63and(lines[i])[0]=='4':

.................

iflen(lines[i])>63and(lines[i])[0]=='5':

...................................

The code above checks each of the n records according to characteristics ① and ②, and finally uses five if statements to retrieve all records in the file "pzw" that meet the conditions. The code fully demonstrates the powerful table processing capabilities of the Python language and is the core of the entire application.

3.4 Obtaining Inverter Parameter Values

The function of the code in the rectangle is to further process the records that meet conditions ① and ②: discard the first 7 characters (e.g. 1-3-24-) and the remaining 26 bytes are the inverter parameter values ​​and check codes. The reading program can be compiled according to Table 1 [1].

Table 1:

3.5 Program Structure

Control signals such as “start”, “stop”, and “speed adjustment” are non-periodic commands, while reading inverter parameters and displaying data are periodic commands. Therefore, a main thread-sub-thread structure is adopted. Two timer modules QTimer[2] are defined, each with a timer of 2 seconds. During timer 1, the periodic reading command is executed, and during timer 2, the non-periodic command is executed. The process is shown in Figure 2, which constitutes a program execution process with a loop of about 2 seconds.

Figure 2 Control Flow

3.5 User Interface

Figure 3. Human-computer interface (partial view)

Figure 3 shows the operation interface. The output frequency of the inverter is set by the counter control QSpinBox[2]. You can easily set it by clicking the up and down arrows on the right or by directly entering numbers on the keyboard. The data in Figure 2 are: output frequency, running current, DI status, DO status, AI1, AI2, AI3.

4. Research and Development Experiences and Future Prospects

Read the inverter DI/AI signals (fault, flow, temperature, etc.), process them, obtain the operating status of the entire system equipment, display them on the interface, and then output switch signals or analog signals (open/close valve, start/stop pump, adjust valve opening, etc.) through DO/AO to control other equipment. Make full use of these ports, which is equivalent to adding a small PLC with: 50 DI, 25 DO, 15 AI and 10 AO. Due to space limitations, the specific usage will not be introduced in this article [1].

In the three-tier architecture of the Internet of Things (IoT), the PLC must rely on a gateway to connect to the external network. The Raspberry Pi integrates network functions (wired/wireless), essentially playing the dual role of controller and gateway.

Yeelink is currently the largest IoT cloud platform in China. It provides cloud services to the public for free. By developing related applications through the App interface provided by Yeelink, remote monitoring of products can be achieved.

Raspberry Pi is used in engineering projects, and it has great practical value and good development prospects in terms of both product cost and control capabilities.

References:

[1] Huichuan Technology: MD380 Series High-Performance Vector Inverter User Manual V1.4

[2] Wang Shuo and Sun Yangyang: PyQt5 Rapid Development and Practice, Electronic Industry Press, October 2017.

Read next

CATDOLL Himari Hard Silicone Head

The head made from hard silicone does not have a usable oral cavity. You can choose the skin tone, eye color, and wig, ...

Articles 2026-02-22