I had ordered months ago a XY-MD02 Temperature and Humidity Transmitter Detection Sensor Module Modbus SHT40 Temperature Sensor from some Chinese source (it is available from many on-line shops). Now I had finally some time to test it.
Parameters:
Product name: temperature and humidity transmitter
DC power supply: DC 5V-30V
Output signal: RS485 signal
Temperature accuracy: ±0.5℃ (25℃)
Humidity accuracy: ±3%RH
Temperature range: 0%RH-80%RJ
Temperature resolution: 0.1℃
Humidity resolution: 0.1%RH
Equipment power consumption: ≤0.2W
Communication address: 1-247 can be set, default 1
Communication protocol: Modbus-RTU protocol and custom common protocol
Baud rate: configurable, default 9600, 8-bit data, 1-bit stop, no parity
This product integrates the MODBUS protocol and the common protocol Using RS485 hardware interface. The user can choose the communication protocol. The product adopts industrial grade chip, high-precision SHT40 temperature and humidity sensor.
My plan was to first test it with Modbus protocol. I wired this sensor to PC using a cheap “no name” USB to RS-485 adapter. For powering the sensor I used 5V from USB port (wired to sensor with cut USB cable).
Here is the overview of the supported Modbus communications protocol.
I think I need to read the temperature and humidity register. To use it I need some software to handle Modbus communications and help testing if it works.
CAS Modbus Scanner is a free proprietary application from Chipkin Automation Systems that I used as first tool to verify that basic Modbus communications works and devices could be found on but. It’s Discover functionality allowed to find that device is there, but for some reason the software did not seem to get successfully data from it.
So it seems that I needed some other tool to make communications work. PowerHud Mobbus Tester from https://www.modbustester.com/ could read the data successfully from the sensor.
How to interpret data info from https://www.aliexpress.com/item/1005001475675808.html
In addition to Modbus protocol, there is another protocol called common protocol. That “common protocol” is a simple ASCII protocol that can be used with any common serial port terminal program. I followed the instructions from XY-MD02 Temp Humidity Serial UART Communication article and video. Here is the most important takeout of special Putty settings in addition to serial port (9600 BPS 8N1) needed to get communications to work:
I got this other protocol to work with Putty program. The READ command reads the temperature and humidity values.
The common protocol has said to have an automatic upload function (connecting RS485 through the serial port adjustment tool will automatically output temperature and humidity). That can be started using command AUTO.
Links to more material:
XY-MD02 Sensor Setting – Modbus RTU Network
https://accautomation.ca/xy-md02-sensor-setting-modbus-rtu-network/
XY-MD02 Temp Humidity Serial UART Communication
https://accautomation.ca/xy-md02-temp-humidity-serial-uart-communication/
https://www.instructables.com/XY-MD02-Temperature-and-Humidity-Sensor-Module-Mod/
Product pages with data:
https://www.aliexpress.com/item/1005001475675808.html
Videos:
https://www.youtube.com/watch?v=V0_IqkWIPG0
https://www.youtube.com/watch?v=e_1QHtkOf6k
Source code links:
https://github.com/TitusSetiawan/XYMD02-ESP32-modbus
https://github.com/cesgarma/modbus-XY-MD02
1 Comment
Jim says:
I have a few of these XY-MD02 sensors and have been able to read the temp and humidity from both modbus with NodeRed (node-red-contrib-modbus) and using UART with minicom. In modbus I was not able read anything from the 3 register at all. I polled all the way up to address 1000 on both 3 and 4 and the only data I got back was for temp and humidity.
In UART I can read and change the temp and humidity correction, enable and disable polling and the rate.
The issue I am facing now is that UART does not appear to allow for changing the units address away from default one, and modbus should support it, but appears not to. As such, I cannot change the modbus address and this means I cannot attach multiple sensors to the same RS485 wire.
Any suggestions?