Introduction: This article gives the process of forming a multimeter networking conversion module in ESP32. After the transformation, the universal networking data can be accessed through UDP.
关键词
: Multimeter , ESP32
01 Multimeter networking
1. Background introduction
Because the computer suddenly could not detect the USB serial port line , I made a module to read the serial port using CH340 in Read Multimeter USB Serial Port Module, but this serial port module could not be recognized later. Now use the ESP32 module used in the use of ESP32 to construct a ZIGBEE network transmission transfer and convert it to an RS232 serial port in a WiFi, so that you can get rid of the dependence on the computer UART and directly use the WiFi in the laboratory to complete the multimeter network. access to obtain multimeter measurement information.
2. Making the transfer board
1. ESP32 adapter module
The ESP32 MicroPython module uses the ESP32 module adapter board to build the interface circuit with the MAX3232 on the breadboard.
▲ 图1.2.1 基于ESP32的MicroPython测试模块
(1) ESP32 module
Later, I found an ESP32 timing system for debugging, and the following is based on this module to complete the module transformation.
▲ 图1.2.2 ESP32计时系统
It is more convenient to use the UART1 to go out and lead out the interface.
▲ 图A1.2.3 改造ESP32输出接口
(2) Outgoing interface
Ⅱ. Outgoing interface definition
PIN1 | PIN2 | PIN3 | PIN4 |
---|---|---|---|
3.3V | GND | RXD | TXD |
Ⅲ. Soldering output pins
According to the schematic diagram of the ESP32 timing system, the interface of UART1 is drawn as follows.
▲ 图1.2.4 焊接引出UART1接口
The corresponding pins of the UART of ESP32 are:
▲ 图1.2.5 ESP32 UART 缺省管脚
After testing, there is no output on PIN9 and PIN10 using UART1 directly. Now the modified mode is to use UART2 to complete the input and output settings on GPIO12 (RX) and GPIO14 (TX).
(3) ESP32 flash firmware
Flash the ESP32 firmware with Thonny. For specific methods, please refer to the Debugging Instructions of the ESP-12F Module Adapter Board Beta Version and download the MicroPython program. ESP8266-12F .
2. Test the ESP32 module
Test the UART1 function of the ESP32. After testing, verify that the UART is functioning properly.
from machine import Pin,UART
import time
import machine
machine.freq(240000000)
uart1 = UART(2, baudrate=115200, rx=12, tx=14, timeout=10)
bz1 = Pin(21, Pin.OUT)
bz1.on()
time.sleep_ms(50)
bz1.off()
print("Test LED")
while True:
uart1.write('hello')
b = uart1.read(5)
print(b)
time.sleep_ms(250)
3. MAX3232 adapter module
Since the MAX3232 modules used are surface-mount modules, a one -minute pattern-making method is used to build a small board with a 100mil test pin interface, which is convenient to connect with the front ESP32 test board on the breadboard.
(1) Adapter board design
Design the adapter board, the schematic diagram and the PCB design diagram for rapid plate making are given below.
AD\Test\2022\MAX3232SIP.SchDoc
▲ 图1.2.3 Altium Design设计的转接板
(2) Adapter board debugging
The function of the level transfer board is tested below. Send and receive the "hello" string using the UART of the ESP32 above. Measure the level of the output signal and short-circuit the RX and TX pins of the UART. Can get sent and received strings.
▲ 图1.2.7 焊接后测试RS3232功能
▲ 图1.2.8 测试转接板的输出RS232信号
3. Connect the multimeter network
1. Read data
According to the original multimeter reading program: ShowPannelResult() , obtain the multimeter network reading protocol. The following program shows that the cycle of reading the multimeter is 25ms.
//---------------------------------------------------------------------------
void __fastcall TMainForm::Timer1Timer(TObject *Sender) {
static int nShowResultCount = 0;
if((nShowResultCount ++) >= 25) {
nShowResultCount = 0;
if(m_nShowResultFlag) {
ShowPannelResult();
}
}
}
Read data and parse data program fragments.
int GetMeterValueAll(double * lfResult) {
unsigned char ucBuffer[1024];
ClearPort(PORT1);
SendChar(0x55, PORT1);
unsigned char ucChar;
if(ReceCharL(&ucChar, PORT1, 20)) return 0;
if(ucChar != 0x55) return 0;
unsigned char ucMask;
if(ReceCharL(&ucMask, PORT1, 20)) return 0;
int nLength = ucMask;
int i;
for(i = 0; i < nLength; i ++) {
if(ReceChar(&ucChar, PORT1)) return 0;
ucBuffer[i] = ucChar;
ucMask += ucChar;
}
if(ReceChar(&ucChar, PORT1)) return 0;
if(ucChar != (ucMask ^ 0xff)) return 0;
if(ReceChar(&ucChar, PORT1)) return 0;
if(ucChar != 0xaa) return 0;
float * p;
int nNumber = nLength / 4;
for(i = 0; i < nNumber; i ++) {
p = (float *)&ucBuffer[i * 4];
*(lfResult + i) = *(p);
}
return nNumber;
}
2. Definition of connection interface
Define the RS232 interface definition for networking with the multimeter. Define this interface the same as the PC UART definition. That is, the pins of DB9 are defined as:
- PIN2:RXD
- PIN3:TXD
- PIN5:GND
▲ 图1.3.1 接口定义
3. Test and read the multimeter network
Use the following program to receive the following data after sending 0x55 characters.
from machine import Pin,UART
import time
import machine
machine.freq(240000000)
uart1 = UART(2, baudrate=115200, rx=12, tx=14, timeout=100)
bz1 = Pin(21, Pin.OUT)
bz1.on()
time.sleep_ms(50)
bz1.off()
print("Test LED")
while True:
_ = uart1.write(bytes([0x55]))
b = uart1.read(50)
print(b)
time.sleep_ms(10)
Below is the information received from the multimeter.
b'U\x10\x83\xa8{7\xd6\xe5\x9484\x807\xba\x00\x00\x00\x00\xe6\xaa'
b'U\x10\x83\xa8{7\xd6\xe5\x9484\x807\xba\x00\x00\x00\x00\xe6\xaa'
b'U\x10\x8b\xe1j7\x93\x17\x9984\x807\xba\x00\x00\x00\x00\xc2\xaa'
b'U\x10:\x9b\x8e7\x93\x17\x9984\x807\xba\x00\x00\x00\x005\xaa'
b'U\x10:\x9b\x8e7\x93\x17\x9984\x807\xba\x00\x00\x00\x005\xaa'
b'U\x10\x83\xa8{70b\x9f84\x807\xba\x00\x00\x00\x00\x04\xaa'
b'U\x10:\x9b\x8e70b\x9f84\x807\xba\x17\xb7\xd1\xb8\xf0\xaa'
b'U\x10:\x9b\x8e70b\x9f84\x807\xba\x17\xb7\xd1\xb8\xf0\xaa'
b'U\x100b\x9f7\x93\x17\x998RI\x1d\xba\x00\x00\x00\x00\x9a\xaa'
b'U\x100b\x9f7\x93\x17\x998RI\x1d\xba\x00\x00\x00\x00\x9a\xaa'
b'U\x10:\x9b\x8e7r0\x9b8RI\x1d\xba\x00\x00\x00\x00n\xaa'
Fourth, UDP connection and transmission
1. Forward Python program
Below is the final ESP32 MicroPython program.
from machine import Pin,UART
import time
import machine
import usocket,network
machine.freq(240000000)
uart1 = UART(2, baudrate=115200, rx=16, tx=17, timeout=50)
bz1 = Pin(21, Pin.OUT)
bz1.on()
time.sleep_ms(50)
bz1.off()
wlan = network.WLAN(network.STA_IF)
wlan.active(False)
wlan.active(True)
time.sleep_ms(100)
wlan.connect('TENDA626A', 'gniqouhz')
bz1.on()
while not wlan.isconnected():
time.sleep_ms(100)
wlan.ifconfig()
bz1.off()
us = usocket.socket(usocket.AF_INET, usocket.SOCK_DGRAM)
sockaddr = usocket.getaddrinfo('0.0.0.0', 7654)[0][-1]
us.bind(sockaddr)
count = 0
while True:
data,addr = us.recvfrom(1024)
if len(data) > 0:
_ = uart1.write(bytes([0x55]))
count += 1
if count >= 10:
count = 0
bz1.on()
time.sleep_ms(5)
bz1.off()
b = uart1.read(50)
if type(b) == bytes:
if len(b) > 0:
us.sendto(b, addr)
2. Modify the MEGA program
PC software:
D:\zhuoqing\window\cb\MyResearch\Test\TestAD5344\M8BL_BAS\M8BL_BAS.exe
The modified program can complete the original program function based on UART.
▲ 图1.4.1 测试后的程序
※ Summary ※
This article gives the process of forming a multimeter networking conversion module in ESP32. After the transformation, the universal networking data can be accessed through UDP.
■ Links to related literature:
- USB to UART module driver problem: Z-TEK
- Read multimeter USB serial port module
- Use ESP32 to construct a ZIGBEE network transmission transfer
- ESP32 module adapter board
- Debugging instructions for the beta version of the ESP-12F module adapter board, download the MicroPython program. ESP8266-12F
- One minute plate making method
● Links to related charts:
- Figure 1.2.1 MicroPython test module based on ESP32
- Figure 1.2.2 ESP32 timing system
- Figure A1.2.3 Modify ESP32 output interface
- Figure 1.2.4 Soldering the UART1 interface
- Figure 1.2.5 ESP32 UART default pins
- Figure 1.2.3 Adapter board designed by Altium Design
- Figure 1.2.7 Test RS3232 function after soldering
- Figure 1.2.8 Test the output RS232 signal of the adapter board
- Figure 1.3.1 Interface Definition
- Figure 1.4.1 Procedure after testing