Troubleshooting ESP32 and Modbus Integration 🙏

Hey everyone,

I’m relatively new to the scene and don’t have much experience with electronics and programming, but I’m currently working on a project that involves an ESP32 microcontroller, a specific pinout configuration, and a power meter. However, I’ve encountered an issue and could really use some guidance. Here’s what I have:

  1. ESP32 with the following pinout: ESP32_DevKit_C_V4_Pinout.pdf (shopify.com)

  2. A power meter with the instructions available here: Eastron SDM220M* User Manual (xn–stromzhler-v5a.eu) an TTL to RS485 module:

  3. I have wired everything according to this diagram (of course the ESP and the power meter are connected to power supply):

In my ESPHome configuration, I have the following code for this setup:

esphome:
  name: rs485
  friendly_name: Rs485

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:
  baud_rate: 0

uart:
  id: mod_bus
  tx_pin: GPIO1
  rx_pin: GPIO3
  baud_rate: 9600
  stop_bits: 2

modbus:
  flow_control_pin: GPIO0
  id: modbus1

modbus_controller:
  - id: controller
    ## the Modbus device addr
    address: 0x1
    modbus_id: modbus1

sensor:
  - platform: modbus_controller
    modbus_controller_id: controller
    name: "Currents sum"
    id: currents_sum
    address: 30049
    register_type: holding
    value_type: U_DWORD
    unit_of_measurement: "A"
    

# Enable Home Assistant API
api:
  encryption:
    key: "P/LTB5girwA0bT84O0lL7bLzGszImPRhWTBNQaSTeIs="

ota:
  password: "410734d9197a1988aea69177ccb0269c"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Rs485 Fallback Hotspot"
    password: "lRKwYkASr0kA"

captive_portal:
    

However, when I check the logs, I see the following error message:
[D][modbus_controller:032]: Modbus command to device=1 register=0x1683 countdown=0 no response received - removed from send queue

Additionally, the entity associated with the power meter shows a status of “Unknown.”

I’m trying to figure out what I might be doing wrong here. Any tips or suggestions would be greatly appreciated. Thank you in advance!

Best regards, Felix

First, try reversing the TX and RX lines from the ESP32 to the RS485 board. Some of these boards are mis-labelled.

Hello, sadly this doesn’t change anything :frowning:
Is it normal that when I set 0x0006 as the sensor address, the resulting error message has 0x06 as its address?

Better use a XY-017 as it only needs 3.3 V volt power instead of 5V of the one you have now
Also it doesn’t need the flow control pin anymore
Inexpensive RS485 interface board for ESP8266/ESP32/Arduino | Жизнь, бизнес и IT (bizkit.ru)
RS485 naar RX-TX TTL 3.3V 5V omvormer module SP3485 (domoticx.nl)

I have made many espboards with this ttl to rs485 and found no problems.
With the other board i have had many CRC errors.

You might want to try sdm_meter
Eastron SDM Energy Monitor — ESPHome

esphome/sdm_meter_registers.h at dev · esphome/esphome · GitHub

Yea will try that.
Untill these arrive, no solution. :frowning:

if it is the 3.3v vs 5v i wonder is a logic level shifter would help? i know i have quite a few laying around and my local electronics store has them in stock… saves waiting for parts from overseas

I have some xy-017 at home. If you live in the Netherlands/Belgium i could send one.
Also have fully assembled PCB’s with esp32 (mh-et-live)

Not tested with a level shifter, as it is another component added to the material lists :wink:

Update:
It somehow started to work perfectly. ¯_(ツ)_/¯
Maybe I forgot to connect DE and RE

1 Like

May i ask how you connected DE and RE? to which pins on the ESP 32?

It looks like he connected GPIO0 (flow_control_pin) to RE and bridged RE and DE.
Another ref: microcontroller - Correctly using RE and DE with RS485 - Electrical Engineering Stack Exchange