klatremis / esphome-for-deye

Esphome component for Deye 3 phase inverters for Home Assistant
131 stars 31 forks source link

Issues when communicating with inverter #33

Closed marval closed 5 months ago

marval commented 6 months ago

Hello,

New to Deye, but generally not new to electronics or ESP programming. I have recently purchased a 12kW hybrid inverter and it should obviously integrates to HA so this code was on my favorites even before the purchase.

After getting the inverter I soldered my 485 to TTL module on an ESP32 I had laying around and connected it using the diagrams in the manual (pin 1 and pin 2 on RJ45) and put it in the Modbus port on the inverter. The ESP kept sending but never received anything (LED lights) so even though I was sure about the connections I exchanged the TX and RX - still not working. I then returned the RX and TX wires to their original placement and started plugging the RJ45 in the other ports. Only the Meter485 port worked for me, but even this was not 100%. I could read all the values, but whenever I wrote something it got overwritten with the old value after a few seconds.

Am I doing something wrong or missing a small detail somewhere?

Here is a picture of my FW version. 434243128_980765883491979_7588102023907401539_n

luckylinux commented 6 months ago

@marval

Did you connect the GND Port / Wire as well (Pin 3 if you used Pin 1 + 2 for TX/RX) ?

image

Are you sure you don't have a 3.3V/5V issue for instance, both for NOT damaging the Deye, as well as the Operating Voltage of your Transceiver ? E.g. MAX485 is NOT meant to operate at 3.3 V, you should use MAX3485 for that in theory (although MAX485 could work and sometimes does).

Other options is the Pinout on the ESP32 side (GPIO mappings)

I tried to do my own fork at https://github.com/luckylinux/esphome-for-deye with a more modular approach (using ESPHome Packages) and since I work off-grid I had a lot more registers to consider.

I will be testing in a few days when I get the 10m RJ45 Cables that I ordered. I was too lazy to crimp them myself :D. I will be using a M5Stack Atom S3 Lite with Galvanically Isolated RS485 to have some extra safety.

EDIT 1: Make sure you are NOT using a Cross-Over Cable (or you are doing a Cross-Over Cable yourself by following TIA 568a on one side and TIA 568b on the other): image

Otherwise, as you can see, Pin 1+2 would go completely out of place on the other end.

EDIT 2: Try to use another USB AC Power Supply (Charger): I have seen many posts here about using the 12V on the CN2 Power Connector via a DC-DC converter to get 5V for USB Supply. Try with a Decent 5V/3A Power Supply to exclude everything else (1A should be enough, but I would try with 5V/2A+ e.g. Raspberry Pi micro-USB / USB-C AC Adapter which is 5V/3A). O

EDIT 3: You should really only be using the ModBus Port for this monitoring/control system, NOT the Meter/BMS Port !

EDIT 4: There is a note about automatic flow control and a corresponding setting in the YAML file. Did you also check that ?

uart:
  id: mod_bus
  tx_pin: 17
  rx_pin: 16
  baud_rate: 9600
  stop_bits: 1

modbus:
  id: modbus1
# flow_control_pin: 4 #for use when you use a rs485 board without auto flow control. Like the rs485 max board.

modbus_controller:
  - id: ${modbus_controller_id}
    address: 0x1
    modbus_id: modbus1
    setup_priority: -10
    update_interval: 15sec

I'd suggest you also address the STACK size (ESP32 and others) and DIO (ESP32S3) issue in your config file, as I ran into many issues on a separate project when many sensors are included the YAML file:

esphome:
  name: ${name}
  platformio_options:
    board_build.flash_mode: dio
    build_flags:
      - -DCONFIG_ARDUINO_LOOP_STACK_SIZE=32768
  comment: ${device_description}
  project:
    name: !secret project_name
    version: !secret project_version

I will be using this for myself (NOT the Arduino Framework):

esp32:
  board: esp32-s3-devkitc-1 # Works for Atom S3 Lite
  variant: esp32s3          # Works for Atom S3 Lite
  framework:
#    type: arduino # Original
    type: esp-idf # Testing

EDIT 5: For automatic flow control, I Googled a bit and these Information could be useful to you, in case you already don't have have automatic flow control implemented:

https://community.home-assistant.io/t/troubleshooting-esp32-and-modbus-integration/576879/8

https://electronics.stackexchange.com/questions/153500/correctly-using-re-and-de-with-rs485

Also a good reference here: https://protosupplies.com/product/max485-ttl-to-rs-485-interface-module/

luckylinux commented 5 months ago

@marval

For what it's worth, I could successfully upload my forked version (on the Modbus port) and it worked out of the box on the Atom S3 Lite with the Isolated RS485 Module/Unit.

Pinout was correct from the start and communication was immediately established.

The minor fix I needed was to change device_type so it had a unique ID since I have 3 inverters otherwise that would generate conflicts in MQTT / Home Assistant (obviously).

But all of it is now included in my latest version.

https://github.com/luckylinux/esphome-for-deye

marval commented 5 months ago

Just an update from my side. It seems the issue was neither HW or FW specific. I did two things and my problems are now gone

  1. @luckylinux got me thinking about the ID so I checked and it was 01. Decided to change it to 05 and then back to 01 while keeping rhe inverter as a “Slave” (how come they only updated the branch names and not these uses of the words 🤔) image
  2. Changed to pin 7 and 8 (the brown pair). This then worked in the Modbus port which was otherwise dead.

Now everything works and I am happy with how it turned out. Thanks @klatremis for his effort on setting up things so that they are easy for (the most of 😬) us.

luckylinux commented 5 months ago

@marval I'm glad that you got it solved, however for the first change you did I'm not sure why that should have any influence.

That's the ID for master/slave setup when using parallel inverters setup.

I do not see how that should relate to the Modbus port image

More likely than not, in my opinion, you counted in the "wrong" way the pins (look at RJ45 plug with locking tab up/down, from the front/back, etc) on the RJ45 plug and/or other end of the cable AND you used TIA 568A wiring.

In your original cabling, were you maybe using the Green / White-Green Wires as in TIA 568B ? That would explain why they are going nowhere if you did TIA 568A on the other end: image

The end result is that you had a cross-over cable.

Because for TIA 568B, if the Deye schematics is correct, then it should also have worked from the start, since the pins are bridged internally to the device: image

image

Pin 1 is bridged with Pin 8 (RS485_B) and Pin 2 is bridged with Pin 7 (RS485_A).

Impossible to know since you did not provide any pictures of the RJ45 plug or the ESP32 RS485 Transceiver end, nor any details on the cable wiring type (TIA 568A or TIA 568B) ...

marval commented 5 months ago

I was using TIA 568B and I am pretty confident in the counting and identifying pins. As stated before - I could see both the TX and RX on the transceiver blink so I assume the communication was established.

No idea how the parallel setup has affected this. If I find some spare time I will try to reverse the changes one by one to see what made the difference.

luckylinux commented 5 months ago

Alright, thanks for the quicky reply. I'm interested to see what was really causing this.

Any chance that the crimping on the RJ45 on Pin 1+2 was somewhat not properly made ? I once had an intermittent issue on a CCTV camera, turned out it was (just) the RJ45 with come pins/contacts not properly crimped (while other pins were working correctly).

Edit 1: FYI I was too lazy to do crimp a cut-to-length RJ45 Cable (Solid Copper) for this temporary routing that I have at the moment so I just ordered some RJ45 to Terminal Blocks adapter and some standard RJ45 Cat6 S/FTP Cables: https://www.digikey.dk/en/products/detail/dfrobot/FIT0849/15848077?s=N4IgTCBcDaIIwHYDMAOAtAMQJIBUAMKALAJxoByAIiALoC%2BQA image