Figure out how to control Lyngdorf amplifier using UART from ESP32

HI all, need some pointers to get me going!

My pet project is to control my Lyndorf SDAI 2175 amplifier over the serial interface it has (RS232) using a ESP32. I have managed to set up the ESP32 using ESPHome, also configured UART with the RX/RT pins U2RX/U2TX.

So what would be the next step here? I have the manual for the amplifier RS232 codes, done the cabling to connect to the amp from the pins on the ESP32, but no clue as to what to do next.

Not a dev, so skills are limited regarding coding and also new to both HASSIO and ESPHome, but really want to make this work.

Have the following setup:
Raspberry PI3 running HASSIO OS 9.3
ESPHome 2022.11.3
ESP-32 Dev Kit C V4 ( ESP32 Dev Kit C V4 Nodemcu WiFi Development Board – AZ-Delivery)

ESP config:

esphome:
  name: esp-stereo
  build_path: .esphome/build/esp-stereo
  platformio_options: {}
  includes: []
  libraries: []
  name_add_mac_suffix: false
  min_version: 2022.11.3
esp32:
  board: esp32dev
  framework:
    version: 1.0.6
    source: ~3.10006.0
    platform_version: platformio/espressif32 @ 3.5.0
    type: arduino
  variant: ESP32
logger:
  baud_rate: 115200
  tx_buffer_size: 512
  deassert_rts_dtr: false
  hardware_uart: UART0
  level: DEBUG
  logs: {}
uart:
- baud_rate: 57600
  tx_pin:
    number: 17
    mode:
      output: true
      input: false
      open_drain: false
      pullup: false
      pulldown: false
    inverted: false
  rx_pin:
    number: 16
    mode:
      input: true
      output: false
      open_drain: false
      pullup: false
      pulldown: false
    inverted: false
  rx_buffer_size: 256
  data_bits: 8
  parity: NONE
  stop_bits: 1
  debug:
    direction: BOTH
    dummy_receiver: false
    after:
      delimiter: !!binary |
        Cg==
      bytes: 150
      timeout: 100ms
    sequence:
    - then:
      - lambda: !lambda |-
          UARTDebug::log_string(direction, bytes);
api:
  encryption:
    key: xxxxxxxx
  port: 6053
  password: ''
  reboot_timeout: 15min
ota:
  password: xxxxxxx
  safe_mode: true
  port: 3232
  reboot_timeout: 5min
  num_attempts: 10
wifi:
  ap:
    ssid: xxxxxxxx
    password: xxxxxxxxx
    ap_timeout: 1min
  domain: .local
  reboot_timeout: 15min
  power_save_mode: LIGHT
  fast_connect: false
  networks:
  - ssid: !secret 'wifi_ssid'
    password: !secret 'wifi_password'
    priority: 0.0
  use_address: esp-stereo.local
captive_portal: {}

Link to Lyngdorf manual with RS232 documentation: RS232 Command Codes - User.pdf - Google Drive

Any help and pointers would be appreciated.

Br
/Micke

Are you getting anything in your logs with your uart debug?

Did you find/try sending some uart commands yet (maybe set up some ESPHome buttons for testing).

Thanks for the answer, no have not tried anything, right now mostly confused on how to just send some test messages, not even sure how to do that, also really confused on the message format as well, do not get how they should be formatted when looking at the manual and comparing to the few examples I have found (hex code, etc).

Make sure you use a ttl to rs232 converter. Rs232 can be up to 25v, and will let the magic smoke out of your esp32.

Ok, thanks, thought the standard was 5V when I read up on it. A bit confusing that the ground is not used in the instructions for ESPHome, is it not needed?

Have you read this page? Custom UART Text Sensor — ESPHome or this Custom UART Device — ESPHome

Read but not understood :slight_smile: , probably trying to do something that is way out of my competence, but will still try to make it work.
Would this be to enable interaction from HASSIO to the ESPHome to enable sending commands over UART to the amplifier?

I had the naive thought that I could use standard “sensors” and just make sure that I was sending the correct hex with the commands. and then get the output for state. Have you looked at the codes for the amp as well?

My assumption was that I could set up the ESP32 UART to basically just send serial input and get serial output over RS232 and test the commands from HASSIO and have a function to print the output as a starting point, then do the sensors for controlling the different things I would like to steer.

Just so I understand, do I need to do the full config of everything in the ESPHome conf for the ESP32 with all commands as “sensors” to be able to use them in HASSIO?

I think either way could work. If you look at uart bus docs, try to enable dummy_receiver and see what you get in the logs.

Thanks, will try that as the first step

There’s also this alternative approach for UART sensors.

Potentially an easier entry point.

2 Likes

Yes I was just looking for that :slight_smile:

2 Likes

Looking at the linked information for the protocol the alternative approach using the uart debugging will not be a good fit. The packets are all binary format of variable length, so there is no good delimiter to split the data. If the amp only responds with one packet to each request the timeout might work.

Here were two esphome custom components with multiple different sensors that implement binary protocols. Might be able to leverage some of this for your project.

I’d also search to see if there are any existing c++ projects that implement the controls for the amp. Might be able to migrate that into esphome.

2 Likes

Thanks, will have a look!

Ok, so not making much progress here sad to say. Have built a physical connector that I think is pinned correctly between the ESP32 and RJ12 connector, plugged it in and nothing exploded :slight_smile: . Did it with a cross over setup, rx-tx and tx-rx, guess that is the right way to do it?

Interesting the ground pin is not mentioned in the ESPHome UART docs, should this NOT be used, it is standard for RS232?

Still struggling to figure out how to send and receive, so right now not even capable of figuring out is anything is actually getting to the AMP and if the pinout is correct.

Testing a simple swith to send a “power off” command (think I got it right), but can see no responses from the AMP.

This is the current config:

esphome:
  name: esp-stereo

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

# UART Serial interface
uart:
  baud_rate: 57600
  tx_pin: GPIO17
  rx_pin: GPIO16
  rx_buffer_size: 256
  data_bits: 8
  parity: NONE
  stop_bits: 1
  debug:
    direction: BOTH
    dummy_receiver: false
    sequence:
      - lambda: UARTDebug::log_binary(direction, bytes, ',');

# Enable Home Assistant API
api:
  encryption:
    key: "xxxxxx"

ota:
  password: "xxxxxx"

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

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Esp-Stereo Fallback Hotspot"
    password: "xxxxxx"

captive_portal:

#test serial hex input, request for power toggle

switch:

  - platform: uart
    name: "Off"
    data: [0x06, 0x01, 0x00, 0x75, 0x00, 0x7C]'

And this is the log I get when toggling the switch:

INFO Reading configuration /config/esphome/esp-stereo.yaml...
INFO Starting log output from esp-stereo.local using esphome API
INFO Successfully connected to esp-stereo.local
[12:30:59][I][app:102]: ESPHome version 2022.11.3 compiled on Nov 28 2022, 09:13:40
[12:30:59][C][wifi:504]: WiFi:
[12:30:59][C][wifi:362]:   Local MAC: C8:F0:9E:9E:10:4C
[12:30:59][C][wifi:363]:   SSID: [redacted]
[12:30:59][C][wifi:364]:   IP Address: 192.168.2.59
[12:30:59][C][wifi:366]:   BSSID: [redacted]
[12:30:59][C][wifi:367]:   Hostname: 'esp-stereo'
[12:30:59][C][wifi:369]:   Signal strength: -35 dB ▂▄▆█
[12:30:59][C][wifi:373]:   Channel: 6
[12:30:59][C][wifi:374]:   Subnet: 255.255.255.0
[12:30:59][C][wifi:375]:   Gateway: 192.168.2.1
[12:30:59][C][wifi:376]:   DNS1: 192.168.2.1
[12:30:59][C][wifi:377]:   DNS2: 0.0.0.0
[12:30:59][C][logger:293]: Logger:
[12:30:59][C][logger:294]:   Level: DEBUG
[12:30:59][C][logger:295]:   Log Baud Rate: 115200
[12:30:59][C][logger:296]:   Hardware UART: UART0
[12:30:59][C][uart.arduino_esp32:108]: UART Bus 1:
[12:30:59][C][uart.arduino_esp32:109]:   TX Pin: GPIO17
[12:30:59][C][uart.arduino_esp32:110]:   RX Pin: GPIO16
[12:30:59][C][uart.arduino_esp32:112]:   RX Buffer Size: 256
[12:30:59][C][uart.arduino_esp32:114]:   Baud Rate: 57600 baud
[12:30:59][C][uart.arduino_esp32:115]:   Data Bits: 8
[12:30:59][C][uart.arduino_esp32:116]:   Parity: NONE
[12:30:59][C][uart.arduino_esp32:117]:   Stop bits: 1
[12:30:59][C][uart.switch:040]: UART Switch 'Off'
[12:30:59][C][captive_portal:088]: Captive Portal:
[12:30:59][C][mdns:103]: mDNS:
[12:30:59][C][mdns:104]:   Hostname: esp-stereo
[12:30:59][C][ota:093]: Over-The-Air Updates:
[12:30:59][C][ota:094]:   Address: esp-stereo.local:3232
[12:30:59][C][ota:097]:   Using Password.
[12:30:59][C][api:138]: API Server:
[12:30:59][C][api:139]:   Address: esp-stereo.local:6053
[12:30:59][C][api:141]:   Using noise encryption: YES
[12:32:16][D][switch:013]: 'Off' Turning ON.
[12:32:16][D][switch:037]: 'Off': Sending state ON
[12:32:16][D][uart.switch:020]: 'Off': Sending data...
[12:32:16][D][switch:037]: 'Off': Sending state OFF
[12:32:16][D][uart_debug:196]: >>> 0b00000110 (0x06),0b00000001 (0x01),0b00000000 (0x00),0b01110101 (0x75),0b00000000 (0x00),0b01111100 (0x7C)

I have read so many threads (including the ones you guys pointed to, thanks!), but no luck and getting more confused rather than less :slight_smile:, the best one I have found that seemed to be close to my case is : Need Help using RS232 to control a receiver - Configuration - Home Assistant Community (home-assistant.io), if you scroll down to Nathan Carr post in that thread.

I right now would need help with the following:

  • to ensure that the command I´m sending is correct according to the command code manual I linked to earlier (do not get the address thing they write about in the beginning, cannot see it in the example they include)
  • be sure that my config would capture any ack comming back from the AMP is my command gets to it

Thanks for the help.
Br
/Micke

Like Nick said, first step is probably too try to see some data being received in the debug.

Did you tinker much with that?

I notice you have dummy_receiver: false
I think it needs to be true.

While it sounds like the debug approach won’t be useful for your solution, it’s probably still the best first step to confirm your wiring is ok.

For a start, the manual says on page two that no ACK is received on a power off command.

But fundamentally I think the problem is that you need the address of the amplifier. To get that I think you need to send command 66 and observe the return packets. (see page 13).

Lol, feel a bit stupid, yes you are correct, but have tried commands that do have an ack, same result. Will check the reference you pointed to.

The rx-tx crossover looks correct, the GND needs to be shared.

Were you using a ttl to rs232 converter? ESP32 should be on the ttl side and amp on the rs232 side.

With the esp32 connected to the ttl to rs232 converter you can jumper the rs232 rx and tx together to get a loop back of the sent data. That will confirm the all the wiring to and from the amp.

1 Like