diyBMSv4ESP32 icon indicating copy to clipboard operation
diyBMSv4ESP32 copied to clipboard

PYLON LFP battery communication protocol over RS485

Open elmozwo opened this issue 2 years ago • 23 comments
trafficstars

Possibility to connect a Pylontech batterie via RS485 for inverters or Logger wich don't have a Can bus interface e.g. FSP Hybrid Power Manager and Plexlog.

Protokoll description: URL

If there are more informations required, just ask me. Possibly I can find them.

elmozwo avatar Mar 02 '23 16:03 elmozwo

Hi Stuart, I have a simple implementation of Pylontech protocol over RS485 integrated into diyBMS code and running with the PIP5048 / Voltronic VM III inverter.

The integration into diyBMS isn't perfect, I didn't know how to make it work together with existing RX/TX queues in main.cpp, so I commented those lines (I'm not using RS485 current shunt) and it's calling uart_read_bytes / uart_write_bytes directly.

What's implemented:

  • reporting of charge voltage and current limits to the inverter
  • alarm flags to stop charging or discharging.

What's not:

  • voltage and temperature monitoring per each cell
  • capacity & SOC reporting

Let me know what you need, I can share the code.

ruza87 avatar Mar 31 '23 16:03 ruza87

If you can do a GitHub pull request {PR) I can take a look

stuartpittaway avatar Mar 31 '23 16:03 stuartpittaway

Ok, will do.

ruza87 avatar Apr 03 '23 05:04 ruza87

@elmozwo do you have anyway to test the changes @ruza87 has made?

I don't have the necessary inverters/equipment to test the RS485 protocol.

stuartpittaway avatar Apr 13 '23 08:04 stuartpittaway

Yes, I have. If I get some time next days I can try. How can I get this build?

elmozwo avatar Apr 13 '23 16:04 elmozwo

@ruza87 can you help with some build instructions?

stuartpittaway avatar Apr 13 '23 16:04 stuartpittaway

@elmozwo Are you familiar with compiling of the sources in Visual Studio Code using PlatformIO addon? Clone the sources from https://github.com/ruza87/diyBMSv4ESP32/tree/pylon_rs485 and the next steps to build & flash are the same as in the original Stuart's repo.

Or you might try to use already compiled code from my (first, highly experimental:-) release. You can download it here https://github.com/ruza87/diyBMSv4ESP32/releases/download/v1.0.0/release_2023-04-14-09-07.zip and follow the original instructions to flash it: https://github.com/stuartpittaway/diyBMSv4ESP32/blob/master/ProgrammingHardware.md

ruza87 avatar Apr 14 '23 07:04 ruza87

How is it going? Also interested in this area...

Jestergnet avatar Apr 18 '23 22:04 Jestergnet

For people who want to test this (@Jestergnet and @elmozwo ) GITHUB actions have pre-compiled the release.

https://github.com/stuartpittaway/diyBMSv4ESP32/actions/runs/4740188233?pr=195

Look at the bottom of that page for "[DIYBMS-Compiled]"(https://github.com/stuartpittaway/diyBMSv4ESP32/suites/12332390974/artifacts/654416283)

And use this file for the controller. image

stuartpittaway avatar Apr 19 '23 08:04 stuartpittaway

Has anyone already tested the code? After the RS485 firmware, I don’t show any signs at all. Diybms acting as a host? Who is contacting whom? Inverter to BMS or BMS to inverter? After flashing the screen is terribly slow ...

Jestergnet avatar Apr 19 '23 15:04 Jestergnet

@Jestergnet I did. Mine is working with PIP 5048 (same as Voltronic VM III), the battery icon on the inverter is flashing, which means the communication is running OK. The inverter is a host, asking BMS for a reply.

Did you select PylonTech RS485 emulation on the diyBMS "Charge/Discharge configuration" page? Also, is your RS485 speed set correctly? For this inverter it needs to be set to 9600 baud, you can do it on "Current &Voltage Monitoring" page.

Regarding the screen issue - I don't have the screen attached so I cannot tell.

ruza87 avatar Apr 19 '23 16:04 ruza87

@Jestergnet I did. Mine is working with PIP 5048 (same as Voltronic VM III), the battery icon on the inverter is flashing, which means the communication is running OK. The inverter is a host, asking BMS for a reply.

Did you select PylonTech RS485 emulation on the diyBMS "Charge/Discharge configuration" page? Also, is your RS485 speed set correctly? For this inverter it needs to be set to 9600 baud, you can do it on "Current &Voltage Monitoring" page.

Regarding the screen issue - I don't have the screen attached so I cannot tell.

Ok, I'll try.

Jestergnet avatar Apr 19 '23 16:04 Jestergnet

Finaly I also get some time to test. It looks good! The only thing is that it produces many warning popups about discharging/ charging is prevented. Even check or uncheck the boxes will not change anything.

elmozwo avatar Apr 24 '23 20:04 elmozwo

Do you have an external temp sensor connected to the BMS, so it can measure battery temperature? Without any external temp sensor the charging/discharging is blocked.

ruza87 avatar Apr 25 '23 16:04 ruza87

I just have the two sensors from the batterie modules. Do I need a additional one?

elmozwo avatar Apr 25 '23 16:04 elmozwo

Two sensors are fine. Can you check all the rules to see if any of them is preventing the charging? Is the communication between your inverter and diyBMS working? What inverter model do you have?

ruza87 avatar Apr 28 '23 09:04 ruza87

Found a problem, after activating PylonTech RS485, the screen loses its refresh rate. If you disable this option, the screen returns to the normal refresh rate of the image. In order for one page to load, it probably takes 20 seconds, or even more ...

Logs: I (458680) diybms-webreq: API call: monitor2 I (458756) diybms-webreq: API call: chargeconfig I (460865) diybms: Task 1 W (461052) diybms-rules: Cell V>Max I (461053) diybms-rules: Set warning 9 I (461053) diybms-rules: Set warning 7 I (461053) diybms-rules: Set warning 8 I (462270) diybms-webreq: API call: monitor2 I (463361) diybms-webpost: API post: savechargeconfig W (463363) diybms-webfuncs: Missing key named 'stopchargebalance' W (463363) diybms-webfuncs: Missing key named 'socoverride' W (463366) diybms-webfuncs: Missing key named 'socforcelow' W (463372) diybms-webfuncs: Missing key named 'preventcharging' W (463377) diybms-webfuncs: Missing key named 'preventdischarge'

#photo_2023-06-14_17-30-21

Jestergnet avatar Jun 14 '23 14:06 Jestergnet

Hi @stuartpittaway, do you have any idea what could cause the issue described by @Jestergnet ? Could it be the modified loop in rs485_rx task consuming more CPU time? (code here: https://github.com/ruza87/diyBMSv4ESP32/blob/pylon_rs485/ESPController/src/main.cpp#L2772) I don't have the LCD to replicate the issue.

ruza87 avatar Jun 22 '23 14:06 ruza87

From a quick review of the code @ruza87 I think you are in a near-infinite loop waiting for serial data to arrive.

The original code uses this ulTaskNotifyTake(pdTRUE, portMAX_DELAY); as a delay (part of the RTOS) until the transmit function triggers (notifies) it.

stuartpittaway avatar Jun 23 '23 08:06 stuartpittaway

Oh, I see it now, thanks @stuartpittaway. I call uart_read_bytes when the RX buffer contains at least pylon protocol header. This is tested in uart_get_buffered_data_len. But, if the buffer is empty (or contains less data) the task is not suspended which leads to quick looping... I'll add vTaskDelay to pause the task in that case.

ruza87 avatar Jun 27 '23 09:06 ruza87

Oh, I see it now, thanks @stuartpittaway. I call uart_read_bytes when the RX buffer contains at least pylon protocol header. This is tested in uart_get_buffered_data_len. But, if the buffer is empty (or contains less data) the task is not suspended which leads to quick looping... I'll add vTaskDelay to pause the task in that case.

Let me know when you make a fix, I'll check.

Jestergnet avatar Jun 27 '23 10:06 Jestergnet

I fixed it in my repository. You can download the new release from here (https://github.com/ruza87/diyBMSv4ESP32/releases/tag/v1.0.1) or preferably wait for @stuartpittaway to approve GITHUB actions to create automated release.

ruza87 avatar Jun 30 '23 08:06 ruza87

I fixed it in my repository. You can download the new release from here (https://github.com/ruza87/diyBMSv4ESP32/releases/tag/v1.0.1) or preferably wait for @stuartpittaway to approve GITHUB actions to create automated release.

Hi, thanks for the fix. Checked, now the screen does not slow down.

Jestergnet avatar Jun 30 '23 09:06 Jestergnet