Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
RS485 not receiving anything
#1
Question 
Hi,

I have the A16 wired up to a RS485 expansion board (16 inputs, 16 outputs) that is controlled by modbus RTU.

I have the ESP32 programmed with ESPHome. I can send commands to the expansion board, and I have control over the outputs (I see the onboard output-LEDs toggling), and I can see from the onboard communication LED on the expansion board that the expansion board sends a modbus response, but the ESP32 on the A16 does not receive anything on pin 16 (485RX).

I have verbose logs activated on the UART defined in ESPHome. I can see the raw bytes leaving on pin 13 (485TX), but no bytes are arriving on pin 16.
Obviously, I also cannot read the inputs of the expansion board (as that would require receiving the modbus response).

Are you sure that the RX pin number is correct? Could it be that I have a broken pcb trace?

Best regards,

Victor

P.S. Below is the relevant part of the esphome configuration

Code:
logger:
  level: VERY_VERBOSE

uart:
  id: mod_bus
  tx_pin: 13
  rx_pin: 16
  baud_rate: 9600 #115200
  stop_bits: 1
  debug:
    direction: BOTH
    dummy_receiver: false
    after:
      timeout: 1s
    sequence:
      - lambda: UARTDebug::log_hex(direction, bytes,' ');

modbus:
  id: modbus1
  send_wait_time: 250ms
  disable_crc: true

modbus_controller:
  - id: eletechsup
    ## the Modbus device addr
    address: 0x1
    modbus_id: modbus1
    setup_priority: -10

sensor:
   - platform: modbus_controller
     modbus_controller_id: eletechsup
     name: "read channel 1 state"
     id: eletech_channel1_state
     custom_command: [ 0x01, 0x03, 0x00, 0x01, 0x00, 0x01 ]
     value_type: U_WORD

switch:
  - platform: modbus_controller
    modbus_controller_id: eletechsup
    id: eletech_toggle_1
    name: "Eletech toggle 1"
    icon: "mdi:toggle-switch"
    address: 0x1
    register_type: holding
    skip_updates: 0
    lambda: |-
      return true;
    write_lambda: |-
      ESP_LOGD("main","Modbus Switch incoming state = %f",x);
      // return false ; // use this to just change the value
      payload.push_back(0x1);  // device address
      payload.push_back(0x6);  // write register
      payload.push_back(0x0);  // high byte address of the register
      payload.push_back(0x1);  // low byte address of the register
      payload.push_back(0x3);  // command (3=toggle)
      payload.push_back(0x0);  // delay (0)
      return true;
Reply
#2
i will test RS485 with a relay board, later feedback to you.
Reply
#3
Thanks.

FYI: I'm using this board
https://www.aliexpress.com/item/1005003432158161.html

Modbus command reference attached in zip file.


Attached Files
.zip   Electhsup N4D3E16.zip (Size: 9.34 MB / Downloads: 306)
Reply
#4
I have use KC868-A16 work with KC868-H32BS by RS485 cable via modbus.
   
   
I edit config files. mainly command at here:

uart:
  id: mbus
  tx_pin: GPIO13
  rx_pin: GPIO16
  baud_rate: 9600


modbus:
  id: modbus1
  uart_id: mbus
  send_wait_time: 200ms


modbus_controller:
- id: h32bs
  address: 1
  modbus_id: modbus1
  update_interval: 3s


switch:
  - platform: modbus_controller
    name: 'modbus-switch1'
    address: 0  # 0:relay1  1:relay2 ......
    register_type: coil
    bitmask: 1


.txt   ESPHome_A16_modbus_relay.txt (Size: 6.5 KB / Downloads: 227)

this is a demo , i have created one switch button in ESPHome, you can create many others.

H32BS use modbus command:
01 05 00 00 FF 00   turn on relay1
01 05 00 00 00 00   turn off relay1

make sure your relay board as these:
ON = 0xFF00 OFF=0000

if your relay board not use by this protocol. you can also write esphome as "write_lambda" way. i have tested, "write_lambda" to create switch also work fine. just need to create ON and OFF two command.
Reply
#5
Hi,

Thanks for testing this!

In my case, the device represents the inputs/outputs as registers, not coils. I used the write_lambda in debugging the problem to make sure that I get the correct modbus command (which I know is now correct because the output actually toggles).

Have you checked if you can also read the inputs from the KC868-H32BS via RS485?

The weird thing in my case is that nothing comes in on the UART. Can you confirm that if you add this code to the UART definition in esphome, that you then can see incoming messages in addition to the outgoing messages?

Code:
logger:
  level: DEBUG

  debug:
    direction: BOTH
    dummy_receiver: false
    after:
      timeout: 1s
    sequence:
      - lambda: UARTDebug::log_hex(direction, bytes,' ');
Reply
#6
read the "inputs" from the KC868-H32BS via RS485?
the "INPUTs" means digital input? or you want to read OUTPUT relay state?
Reply
#7
I meant 'digital input', yes. But reading back the OUTPUT relay state is a similar test, because that also requires the reception of a modbus reply.
Reply
#8
about OUTPUT relay state update, just use by these config. that means every 3 seconds refresh OUTPUT status for home assistant dashboard. you can change the interval time.

modbus_controller:
- id: h32bs
address: 1
modbus_id: modbus1
update_interval: 3s
Reply
#9
Hi,

It took me a while to source an RS485-USB adapter. Now I can see follow the communication between the A16 and the expansion board.

Physically, I can confirm that the A16 sends a request: 01 03 00 01 00 01 d5 ca
And that the expansion board sends a response: 01 03 02 00 01 79 84

That totally makes sense. But in the esphome log I confirm see that the response is not received by the UART (and therefore not handled by esphome).

Code:
14:47:01    [V]    [modbus_controller:036]   Sending next modbus command to device 1 register 0x01 count 1
14:47:01    [VV]    [uart.arduino_esp32:151]  Flushing...
14:47:01    [V]    [modbus:199]              Modbus write: 01.03.00.01.00.01.D5.CA (8)
14:47:01    [V]    [modbus_controller:486]      Command sent 3 0x1 1
14:47:02    [D]    [uart_debug:114]      >>> 01 03 00 01 00 01 D5 CA
14:47:03    [D]    [modbus_controller:032]      Modbus command to device=1 register=0x01 countdown=0 no
                                                  response received - removed from send queue

Also, with a modbus test program (CAS Modbus Scanner) I can confirm the working of the expansion board. Reading and writing works.

Do you agree that the only remaining conclusion is that there must be something wrong on the board between the RS485 chip and the ESP32 input?
Reply
#10
It took me a while to source an RS485-USB adapter. Now I can see follow the communication between the A16 and the expansion board. --> if you can do this, monitor data from A16--> expansion board , and data A16 <-- expansion board. that means ESP32 and RS485 circuit is good.
maybe you can change setting of ESPHome's log output level.
Reply


Forum Jump:


Users browsing this thread: