Huawei Inverter sun2000 12ktl Modbus RS485

I want to read the ACTIVE POWER Information for a Power Management but i get only unpossible Numbers

I have the DTSU666-H 250 A/50mA Smart
Power Sensor and there is a RS485 Communication between Smart Meter and Inverter.

I bought a MAX485 Module and wired it with Arduino uno

The Parameters of the Inverter:

The Smartmeter:

My Code is:

#include <ModbusMaster.h>

#define MAX485_DE 3 // pin Name zwischen MAX485 und 
#define MAX485_RE_NEG 2

ModbusMaster node;

void preTransmission()
{
  digitalWrite(MAX485_RE_NEG, 1);
  digitalWrite(MAX485_DE, 1);
}

void postTransmission()
{
  digitalWrite(MAX485_RE_NEG, 0);
  digitalWrite(MAX485_DE, 0);
}

void setup() {
  pinMode(MAX485_RE_NEG, OUTPUT);
  pinMode(MAX485_DE, OUTPUT);
  //Init receive mode
  digitalWrite(MAX485_RE_NEG, 0);
  digitalWrite(MAX485_DE, 0);

  //Modbus communication runs at 9600 baud
  Serial.begin(9600);

  //Modbus slave ID 1
 node.begin(1, Serial);
  //Callbacks allow us to configure the RS485 transceiver correctly

node.preTransmission (preTransmission);
node.postTransmission (postTransmission);
 
}

void loop() 
{
uint8_t resultMain;
resultMain = node.readInputRegisters(0X40525,11); //       SSSSSSSSSSSSSSSSSSSSSS
if (resultMain == node.ku8MBSuccess)
{
  Serial.println("-");
  Serial.println("Active Power kw:");
  Serial.println(node.getResponseBuffer(0x03) / 100.0f); //SSSSSSSSSSSSS
  
}
delay (1000);
}

I think there are many mistakes in my code.... does anybody has an solution? I ´d be very thankful

Hoerb

1 Like

but

It's a bad idea to use the same serial interface you communicate with the Modbus device to print out debugging information.

What do you expect from this request? It doesn't match the datasheet information.

Thank you very much Pylon for your solutions. I think i have to buy an arduino Mega, so that i can use 2 serial interfaces.


I have the Datasheet informations from Huawei but i have completle no idea how i can use this registers. I need the "Active Power" Register 40525, 16Bit, Command 0X03, Quantity 2

Please, please show to my Problem again, i just need this "Active Power" Variable and my absolute basic knowledge is not enough to solve this.
Everything else ist no Problem for me.
Kind Regards Hoerb

I solved the Problem with the 2 serial interfaces by using
SoftwareSerial :slightly_smiling_face:

But I have Problems to understand Addresses and Registers.

The Huawei Info to read Modbus:
*Active Power
*Address 40525,
*I32
*16Bit
*Command 0X03,
*Quantity 2

How can i integrate this Info in my Code? I used questions marks ?????? in my code, where i think that is important:

#include <ModbusMaster.h>
#include <SoftwareSerial.h>

#define MAX485_TX_ENABLE  7  // EIA-485 transmit control pin; MAX485 Module PIN DE and RE
#define EIA485_RX         9  // EIA-485 serial receive pin ; MAX485 Module PIN RO
#define EIA485_TX        10  // EIA-485 serial transmit pin ; MAX485 Module PIN DI

ModbusMaster node;
SoftwareSerial RS485Serial(EIA485_RX, EIA485_TX); // Hier wird der serielle Port beschrieben

void preTransmission() {
  digitalWrite(MAX485_TX_ENABLE, true);// Vor der Übertragung wird Pin 7 auf High gesetzt.
}

void postTransmission() {
  digitalWrite(MAX485_TX_ENABLE, false);// Nach der Übertragung wieder auf Low
}


void setup() {

  
  pinMode(MAX485_TX_ENABLE, OUTPUT);
  digitalWrite(MAX485_TX_ENABLE, false);

  Serial.begin(9600);
  RS485Serial.begin(9600); //Baudrate des Sensors auf 9600

  node.begin(1, RS485Serial);//Start der seriellen Schnittstelle, Slave ID 1 //???????????? Huwaei DTH666 says 11?????
  node.preTransmission(preTransmission);
  node.postTransmission(postTransmission);

  Serial.print("");// Bezeichnung meines Sensors
}


void loop() {
float result;
//uint16_t result;


  result = node.readInputRegisters(40525, 2);//Funktion : Read Input Registers, Modbus Adressen 2 //???????? no idea if it is right
 if (result == node.ku8MBSuccess)
  {
    
    Serial.print("Active Power: ");
    Serial.println(node.getResponseBuffer(0)*0.1,1);// 1. Part????????????
    Serial.println(node.getResponseBuffer(1)*0.1,1); // 2. Part???????????
    Serial.println(" kw");


  }
  else {
  Serial.print("Fehler beim Auslesen des Sensors\n");
  }

  delay(2000);//Aktualisierung alle 2 Sekunden
}


Nice Greetings, hoerb

Try this code:

int32_t power = node.getResponseBuffer(0);
power <<= 16;
power |= node.getResponseBuffer(1);
Serial.println(power);

Thank you very much for your Answer. But i do not come into the loop because
if (result == node.ku8MBSuccess) is not true -> so I think the 40525 falue must be false

result = node.readInputRegisters(40525, 1);//Read Input Registers, Modbus Addresses - sure not right
 if (result == node.ku8MBSuccess)
  {
    
    Serial.print("Active Power: ");
    int32_t power = node.getResponseBuffer(0);
    power <<= 16;
    power |= node.getResponseBuffer(1);
    Serial.println(power);
    Serial.println(" kw");
  }
  else {
  Serial.print("Error Data\n");

I found a new Address for the Active Power in an other dokumentation and will try it: 37113 instead of 40525

Hi Pylon, i was reading

Is my project impossible because the Registeradress is over 0-32767?

Try 525 instead. The 40000 addition is often made only for a few incompetent PLC manufacturers that couldn't implement a free addressing.

It would also help to print out the error code, it may be a hint to the cause of the error.

No, your library doesn't have such a limitation, it supports the complete range of addresses.

Thank you Pylon,

Now i get sometimes random Numbers - with very short Registernumbers (for example 1 or 25)
But the actual Register is: 37113
Insteat of 37113 i used 113.
The output was: Error Data

I didn't tell you to simply remove the first two digits, that doesn't work. 40000 is a known offset, 37000 isn't.

Where is the 37113 from? in the posted excerpt other register numbers are used.

I´m very sorry i had an elder version/model info from Huawei. I made this mistake.

Newest Info:
Solar-Inverter-Modbus-Interface-Definitions 12ktl.pdf (1,1 MB)

The new one is (please see pdf):

In this case I would use the register addresses as shown in the table.

Print the return value you get. It may hint you to the actual reason for the failure.

Does anyone know the Register-list RS485 for HUAWEI SUN2000-100KTL-M1?

Thank you in advance

Daniel

Hello Daniel, you can use the following link:
https://forum.arduino.cc/uploads/short-url/g80bOFCOJbpY2zKvpaA30EdGNDK.pdf

This is also for 100ktl :wink: - i renamed the official file. Please let me know if your arduino runs with the inverter. Thanks a lot
Kind regards,
Hörb

Hallo,
i also want to disign a Controller to control the Power. Can you please Tell me the Code that you have taken?
And what Adresse ist the active Power.
The Code at the top dosent work by my Inverter.
Thank you for you Help.

Hallo,

Today i have still no funktional code. But this weekend i dry it again :wink: . It seem to be important to login with the installer login to the sun2000 app to enable the modbus output. HAve you allready logged in in this way?
The register for active power adress is: 37113

look at this:
manual to enabel modbus tcp with huawei inverter

please let me know if you find the solution

Hello everyone,
I'm dealing with the same issue, below my hardware:

  • Inverter HUAWEY SUN2000-4KTL-L1
  • Power Meter DDSU666-H
  • Arduino UNO
  • Module MAX485

Attached the code and some pictures. Any advice is welcome :sweat_smile: :sweat_smile:

#include<ModbusMaster.h>
#include<SoftwareSerial.h>

  #define MAX485_DE      2
  #define MAX485_RE_NEG  3
  #define RX  10
  #define TX  11
  
  ModbusMaster node;
  SoftwareSerial RS485Serial(RX,TX);

  void preTransmission()
  {
    digitalWrite(MAX485_RE_NEG, 1);
    digitalWrite(MAX485_DE, 1);
  }

  void postTransmission()
  {
    digitalWrite(MAX485_RE_NEG, 0);
    digitalWrite(MAX485_DE, 0);
  }

  void setup() {
    pinMode(MAX485_RE_NEG, OUTPUT);
    pinMode(MAX485_DE, OUTPUT);
    // Init in receive mode 
    digitalWrite(MAX485_RE_NEG, 0);  
    digitalWrite(MAX485_DE, 0);  
  
    Serial.begin(9600); 
    RS485Serial.begin(9600); 
    //slave ID 1 ?????????? 
    node.begin(1, RS485Serial); // ??????? I DON'T KNOW WHAT IS THE ADDRESS I HAVE TO insert???????? 

    Serial.println("Starting Modbus:");  
    node.preTransmission(preTransmission);  
    node.postTransmission(postTransmission);  
  }

  void loop() {
    static uint32_t i;
    uint8_t j, result;
    uint16_t data[10];

    i++;

    result = node.readInputRegisters(37113,2);  // ??????? SOME DOUBT ABOUT THE REGISTER ???????? 

    Serial.println("");
  
    if (result == node.ku8MBSuccess) {
      Serial.print("Success, Received data: ");
      for (j = 0; j < 2; j++) {
        data[j] = node.getResponseBuffer(j);
        Serial.print(data[j], HEX);
        Serial.print(" ");
      }
      Serial.println("");
    } else {
      Serial.print("Failed, Response Code: ");
      Serial.print(result, HEX);
      Serial.println("");
      delay(5000); 
    }
    delay(1000);
  }
![PIN A and B MAX485 and schematic|627x500](upload://22MpMP2eN4cshgOi1vOjzvHFL1B.jpeg)