UPDATE: Resolution below
I cannot integrate this flow meter into ESPhome via MODBUS. The flow meter is TUF-2000M on aliexpress or Amazon.
Everything is hooked up correctly to my ESP8266. I followed the instructions here:
Using the ESP8266 Arduino code in that blog, I can read various registers such as the Flow, temperature inlet, etc. The TUF-2000M MODBUS registers are here on page 39: https://images-na.ssl-images-amazon.com/images/I/91CvZHsNYBL.pdf.
However, when I try to integrate into ESPhome, I get CRC check errors and “no response received”. I am using uart pins D2/D3 for my RX/TX pins so that it does not interfere with the serial logger. I’ve also tried to play with output data type, register counts, and response sizes.
Here is my ESPhome MODBUS code:
esphome:
name: tuf-2000m-flowmeter
esp8266:
board: nodemcuv2
# Enable logging
logger:
level: VERY_VERBOSE
#hardware_uart: UART0_SWAP
uart:
id: mod_bus_uart
tx_pin:
number: D3
#number: GPIO1
rx_pin:
number: D2
#number: GPIO3
baud_rate: 9600
stop_bits: 1
parity: none
modbus:
id: modbus1
uart_id: mod_bus_uart
send_wait_time: 500ms
modbus_controller:
- id: tuf2000m
## the Modbus device addr
address: 0x1
modbus_id: modbus1
setup_priority: -10
update_interval: 15s
sensor:
- platform: modbus_controller
modbus_controller_id: tuf2000m
name: "Inlet Temp"
id: inlet_temp
register_type: holding
address: 0x21
register_count: 2
response_size: 2
value_type: FP32
Here is the output of the log:
[15:40:54][C][logger:275]: Logger:
[15:40:54][C][logger:276]: Level: VERY_VERBOSE
[15:40:54][C][logger:277]: Log Baud Rate: 115200
[15:40:54][C][logger:278]: Hardware UART: UART0
[15:40:54][C][uart.arduino_esp8266:102]: UART Bus:
[15:40:54][C][uart.arduino_esp8266:103]: TX Pin: GPIO0
[15:40:54][C][uart.arduino_esp8266:104]: RX Pin: GPIO4
[15:40:54][C][uart.arduino_esp8266:106]: RX Buffer Size: 256
[15:40:54][C][uart.arduino_esp8266:108]: Baud Rate: 9600 baud
[15:40:54][C][uart.arduino_esp8266:109]: Data Bits: 8
[15:40:54][C][uart.arduino_esp8266:110]: Parity: NONE
[15:40:54][C][uart.arduino_esp8266:111]: Stop bits: 1
[15:40:54][C][uart.arduino_esp8266:115]: Using software serial
[15:40:54][C][modbus:150]: Modbus:
[15:40:54][C][modbus:152]: Send Wait Time: 500 ms
[15:40:54][C][modbus_controller.sensor:010]: modbus_controller.sensorModbus Controller Sensor 'Inlet Temp'
[15:40:54][C][modbus_controller.sensor:010]: modbus_controller.sensor State Class: ''
[15:40:54][C][modbus_controller.sensor:010]: modbus_controller.sensor Unit of Measurement: ''
[15:40:54][C][modbus_controller.sensor:010]: modbus_controller.sensor Accuracy Decimals: 0
[15:40:54][V][modbus_controller:035]: Sending next modbus command to device 1 register 0x21 count 2
[15:40:54][VV][uart.arduino_esp8266:180]: Flushing...
[15:40:54][V][modbus:205]: Modbus write: 01.03.00.21.00.02.94.01 (8)
[15:40:54][V][modbus_controller:487]: Command sent 3 0x21 2
[15:40:54][C][modbus_controller:276]: ModbusController:
[15:40:54][C][modbus_controller:277]: Address: 0x01
[15:40:54][C][modbus_controller:279]: sensormap
[15:40:54][C][modbus_controller:281]: Sensor type=3 start=0x21 offset=0x0 count=2 size=2
[15:40:54][C][modbus_controller:285]: ranges
[15:40:54][C][modbus_controller:287]: Range type=3 start=0x21 count=2 skip_updates=0
[15:40:54][V][modbus:058]: Modbus received Byte 1 (0X1)
[15:40:54][V][modbus:058]: Modbus received Byte 2 (0X2)
[15:40:54][V][modbus:058]: Modbus received Byte 0 (0X0)
[15:40:54][V][modbus:058]: Modbus received Byte 0 (0X0)
[15:40:54][V][modbus:058]: Modbus received Byte 128 (0X80)
[15:40:54][W][modbus:116]: Modbus CRC Check failed! 6021!=8000
[15:40:54][V][modbus:058]: Modbus received Byte 132 (0X84)
[15:40:54][V][modbus:058]: Modbus received Byte 224 (0Xe0)
[15:40:54][V][modbus:058]: Modbus received Byte 152 (0X98)
[15:40:54][V][modbus:058]: Modbus received Byte 0 (0X0)
[15:40:54][V][modbus_controller:035]: Sending next modbus command to device 1 register 0x21 count 2
[15:40:54][VV][uart.arduino_esp8266:180]: Flushing...
[15:40:54][V][modbus:205]: Modbus write: 01.03.00.21.00.02.94.01 (8)
[15:40:54][V][modbus_controller:487]: Command sent 3 0x21 2
[15:40:54][V][modbus:058]: Modbus received Byte 1 (0X1)
[15:40:54][V][modbus:058]: Modbus received Byte 2 (0X2)
[15:40:54][V][modbus:058]: Modbus received Byte 0 (0X0)
[15:40:54][V][modbus:058]: Modbus received Byte 0 (0X0)
[15:40:54][V][modbus:058]: Modbus received Byte 128 (0X80)
[15:40:54][W][modbus:116]: Modbus CRC Check failed! 6021!=8000
[15:40:54][V][modbus:058]: Modbus received Byte 136 (0X88)
[15:40:54][V][modbus:058]: Modbus received Byte 136 (0X88)
[15:40:54][V][modbus:058]: Modbus received Byte 146 (0X92)
[15:40:54][V][modbus:058]: Modbus received Byte 16 (0X10)
[15:40:55][D][modbus_controller:029]: Modbus command to device=1 register=0x21 countdown=0 no response received - removed from send queue
I have also tried using Custom Commands instead:
uart:
id: mod_bus_uart
tx_pin:
number: D3
#number: GPIO1
rx_pin:
number: D2
#number: GPIO3
baud_rate: 9600
stop_bits: 1
parity: none
modbus:
id: modbus1
uart_id: mod_bus_uart
send_wait_time: 500ms
modbus_controller:
- id: tuf2000m
## the Modbus device addr
address: 0x1
modbus_id: modbus1
setup_priority: -10
update_interval: 15s
sensor:
- platform: modbus_controller
modbus_controller_id: tuf2000m
name: "Inlet Temp"
id: inlet_temp
value_type: FP32
custom_command: [ 0x01, 0x03, 0x00, 0x21, 0x00, 0x02]
However. for some reason the register states “register=0xDC0”, which is not correct, but the Modbus write raw is correct “Modbus write raw: 01.03.00.21.00.02 (6)”:
[16:03:43][C][modbus_controller:276]: ModbusController:
[16:03:43][C][modbus_controller:277]: Address: 0x01
[16:03:43][C][modbus_controller:279]: sensormap
[16:03:43][C][modbus_controller:281]: Sensor type=0 start=0xDCD offset=0x0 count=2 size=4
[16:03:43][C][modbus_controller:285]: ranges
[16:03:43][C][modbus_controller:287]: Range type=0 start=0xDCD count=2 skip_updates=0
[16:03:43][D][modbus_controller:029]: Modbus command to device=1 register=0xDCD countdown=0 no response received - removed from send queue
[16:03:48][VV][scheduler:195]: Running interval 'update' with interval=15000 last_execution=10277 (now=25277)
[16:03:48][V][modbus_controller:159]: Updating modbus component
[16:03:48][VV][modbus_controller:163]: Updating range 0xDCD
[16:03:48][V][modbus_controller:125]: Range : DCD Size: 2 (0) skip: 0
[16:03:48][V][modbus_controller:035]: Sending next modbus command to device 1 register 0xDCD count 2
[16:03:48][VV][uart.arduino_esp8266:180]: Flushing...
[16:03:48][V][modbus:226]: Modbus write raw: 01.03.00.21.00.02 (6)
[16:03:48][V][modbus_controller:487]: Command sent 0 0xDCD 2
[16:03:48][V][modbus:058]: Modbus received Byte 1 (0X1)
[16:03:48][V][modbus:058]: Modbus received Byte 2 (0X2)
[16:03:48][V][modbus:058]: Modbus received Byte 0 (0X0)
[16:03:48][V][modbus:058]: Modbus received Byte 0 (0X0)
[16:03:48][V][modbus:058]: Modbus received Byte 128 (0X80)
[16:03:48][W][modbus:116]: Modbus CRC Check failed! 6021!=8000
[16:03:48][V][modbus:058]: Modbus received Byte 192 (0Xc0)
[16:03:48][V][modbus:058]: Modbus received Byte 176 (0Xb0)
[16:03:48][V][modbus:058]: Modbus received Byte 224 (0Xe0)
[16:03:48][V][modbus:058]: Modbus received Byte 248 (0Xf8)
[16:03:48][V][modbus_controller:035]: Sending next modbus command to device 1 register 0xDCD count 2
[16:03:48][VV][uart.arduino_esp8266:180]: Flushing...
[16:03:48][V][modbus:226]: Modbus write raw: 01.03.00.21.00.02 (6)
[16:03:48][V][modbus_controller:487]: Command sent 0 0xDCD 2
[16:03:48][V][modbus:058]: Modbus received Byte 1 (0X1)
[16:03:48][V][modbus:058]: Modbus received Byte 2 (0X2)
[16:03:48][V][modbus:058]: Modbus received Byte 0 (0X0)
[16:03:48][V][modbus:058]: Modbus received Byte 0 (0X0)
[16:03:48][V][modbus:058]: Modbus received Byte 128 (0X80)
[16:03:48][W][modbus:116]: Modbus CRC Check failed! 6021!=8000
[16:03:48][V][modbus:058]: Modbus received Byte 196 (0Xc4)
[16:03:48][V][modbus:058]: Modbus received Byte 208 (0Xd0)
[16:03:48][V][modbus:058]: Modbus received Byte 184 (0Xb8)
[16:03:48][V][modbus:058]: Modbus received Byte 192 (0Xc0)
[16:03:49][V][modbus_controller:035]: Sending next modbus command to device 1 register 0xDCD count 2
[16:03:49][VV][uart.arduino_esp8266:180]: Flushing...
[16:03:49][V][modbus:226]: Modbus write raw: 01.03.00.21.00.02 (6)
[16:03:49][V][modbus_controller:487]: Command sent 0 0xDCD 2
[16:03:49][V][modbus:058]: Modbus received Byte 1 (0X1)
[16:03:49][V][modbus:058]: Modbus received Byte 2 (0X2)
[16:03:49][V][modbus:058]: Modbus received Byte 0 (0X0)
[16:03:49][V][modbus:058]: Modbus received Byte 0 (0X0)
[16:03:49][V][modbus:058]: Modbus received Byte 128 (0X80)
[16:03:49][W][modbus:116]: Modbus CRC Check failed! 6021!=8000
[16:03:49][V][modbus:058]: Modbus received Byte 210 (0Xd2)
[16:03:49][V][modbus:058]: Modbus received Byte 228 (0Xe4)
[16:03:49][V][modbus:058]: Modbus received Byte 160 (0Xa0)
[16:03:49][V][modbus:058]: Modbus received Byte 128 (0X80)
[16:03:49][V][modbus_controller:035]: Sending next modbus command to device 1 register 0xDCD count 2
[16:03:49][VV][uart.arduino_esp8266:180]: Flushing...
[16:03:49][V][modbus:226]: Modbus write raw: 01.03.00.21.00.02 (6)
[16:03:49][V][modbus_controller:487]: Command sent 0 0xDCD 2
[16:03:49][V][modbus:058]: Modbus received Byte 1 (0X1)
[16:03:49][V][modbus:058]: Modbus received Byte 2 (0X2)
[16:03:49][V][modbus:058]: Modbus received Byte 0 (0X0)
[16:03:49][V][modbus:058]: Modbus received Byte 0 (0X0)
[16:03:49][V][modbus:058]: Modbus received Byte 128 (0X80)
[16:03:49][W][modbus:116]: Modbus CRC Check failed! 6021!=8000
[16:03:49][V][modbus:058]: Modbus received Byte 208 (0Xd0)
[16:03:49][V][modbus:058]: Modbus received Byte 66 (0X42)
[16:03:49][V][modbus:058]: Modbus received Byte 116 (0X74)
[16:03:49][V][modbus:058]: Modbus received Byte 0 (0X0)
[16:03:50][V][modbus_controller:035]: Sending next modbus command to device 1 register 0xDCD count 2
[16:03:50][VV][uart.arduino_esp8266:180]: Flushing...
[16:03:50][V][modbus:226]: Modbus write raw: 01.03.00.21.00.02 (6)
[16:03:50][V][modbus_controller:487]: Command sent 0 0xDCD 2
[16:03:50][V][modbus:058]: Modbus received Byte 1 (0X1)
[16:03:50][V][modbus:058]: Modbus received Byte 2 (0X2)
[16:03:50][V][modbus:058]: Modbus received Byte 0 (0X0)
[16:03:50][V][modbus:058]: Modbus received Byte 0 (0X0)
[16:03:50][V][modbus:058]: Modbus received Byte 128 (0X80)
[16:03:50][W][modbus:116]: Modbus CRC Check failed! 6021!=8000
[16:03:50][V][modbus:058]: Modbus received Byte 192 (0Xc0)
[16:03:50][V][modbus:058]: Modbus received Byte 6 (0X6)
[16:03:50][V][modbus:058]: Modbus received Byte 64 (0X40)
[16:03:50][V][modbus:058]: Modbus received Byte 96 (0X60)