Arduino communication with solar charge controller

Hi,

I'd like to connect arduino with a solar converter. The solar converter is of the following type:

https://www.wish.com/product/5dab3c862ba80516121d5456?hide_login_modal=true&from_ad=goog_shopping&_display_country_code=CZ&_force_currency_code=CZK&pid=googleadwords_int&c={campaignId}&ad_cid=5dab3c862ba80516121d5456&ad_cc=CZ&ad_curr=CZK&ad_price=1353.00&campaign_id=9038860043&gclid=CjwKCAiA1rPyBRAREiwA1UIy8AU9nEhtK5bahFfeTBCS-qnD-yY0SJ-1XRfuVGp8-sausmN4UmKtrBoCx8kQAvD_BwE

I found no manual for it. The plate is marked CPK2420-V2.5.

According to available documentation, the solar converter should read RS485. However, it does not work, I tried it several times according to available information for similar projects.

//Rs485

//Arduino modbus master 

//Knihovny 
#include <ModbusMaster.h>               //Library for using ModbusMaster

//
#define MAX485_DE      3
#define MAX485_RE_NEG  2

//
ModbusMaster node;                    //object node for class ModbusMaster

//
int pocet = 59; // pocet registru k vycteni       

int8_t j, result;
int16_t data[59];

//
void preTransmission() {           //Function for setting stste of Pins DE & RE of RS-485
 digitalWrite(MAX485_RE_NEG, 1);             
 digitalWrite(MAX485_DE, 1);
}

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

//
void setup() {
 Serial.println("CIRCUIT DIGEST");
 Serial.println("Arduino");
 Serial.println("Modbus Master");
 delay(1000);

 //
 pinMode(MAX485_RE_NEG, OUTPUT);
 pinMode(MAX485_DE, OUTPUT);


 //
 digitalWrite(MAX485_RE_NEG, 0);
 digitalWrite(MAX485_DE, 0);

 //
 Serial.begin(115200);             //Baud Rate as 115200

 //
 node.begin(1, Serial);            //Slave ID as 1
 node.preTransmission(preTransmission);         //Callback for configuring RS-485 Transreceiver correctly
 node.postTransmission(postTransmission);

 //
 Serial.println("Start");
}

void loop(){
 //
 uint8_t j, result;
 int16_t data[pocet];
 //result = node.readHoldingRegisters(0, pocet);

 Serial.println();
 Serial.print("Co tam mam?"); 

 result = node.readHoldingRegisters(0, pocet);  
 if (result == node.ku8MBSuccess)
 {
 Serial.println("1_??");
 }

 //
 result = node.readInputRegisters(0x3100, 10);
   if (result == node.ku8MBSuccess)
 {
 Serial.println("2_??");
 }
 
 //
 result = node.readInputRegisters(0x311A, 2);
   if (result == node.ku8MBSuccess)
 {
 Serial.println("3_??");
 }

 //
 result = node.readHoldingRegisters(0x9000, 14);
   if (result == node.ku8MBSuccess)
 {
 Serial.println("4_??");
 }

 delay(2000);        //delay 2s

}

After several attempts, I found that I could read the serial line (only Rx, Tx).

//Serial

int16_t incomingByte = 0; // for incoming serial data
int c = 0;
void setup() {
 // put your setup code here, to run once:
 Serial.begin(115200);
 Serial.println("Start");
}

void loop() {
 // put your main code here, to run repeatedly:

 //
 //Serial.println("data");
 
 if (Serial.available())
 {
   c++;
   //Serial.println("neco");
   //
   incomingByte = Serial.read();

   // say what you got:
   //Serial.print("I received: ");
   //Serial.println(incomingByte, DEC);
   Serial.println(incomingByte);

   if(c>=46){
     c = 0;
     Serial.println("Start");
   }
 }else{
   //c = 0;
 }
 //delay(1000);
}

After reading, I get this data ... The number of data is not always the same so I don't know how to sort them to match the real state.

//Data

08:27:53.581 -> Start
08:27:53.581 -> 3
08:27:53.581 -> 1
08:27:53.581 -> 0
08:27:53.581 -> 3
08:27:53.581 -> 43
08:27:53.615 -> 26
08:27:53.615 -> 2
08:27:53.615 -> 23
08:27:53.615 -> 64
08:27:53.615 -> 0
08:27:53.615 -> 0
08:27:53.615 -> 0
08:27:53.615 -> 0
08:27:53.615 -> 0
08:27:53.615 -> 3
08:27:53.615 -> 0
08:27:53.615 -> 244
08:27:53.615 -> 0
08:27:53.615 -> 10
08:27:53.615 -> 0
08:27:53.615 -> 0
08:27:53.615 -> 0
08:27:53.615 -> 0
08:27:53.615 -> 0
08:27:53.615 -> 181
08:27:53.615 -> 0
08:27:53.615 -> 0
08:27:53.615 -> 0
08:27:53.615 -> 40
08:27:53.615 -> 0
08:27:53.615 -> 0
08:27:53.615 -> 2
08:27:53.615 -> 43
08:27:53.615 -> 26
08:27:53.615 -> 3
08:27:53.615 -> 1
08:27:53.615 -> 0
08:27:53.615 -> 3
08:27:53.615 -> 43
08:27:53.681 -> 26
08:27:53.681 -> 3
08:27:53.681 -> 1
08:27:53.681 -> 0
08:27:53.681 -> 3
08:27:53.681 -> 43
08:27:53.748 -> 26

I would like to ask if anyone has encountered a similar problem? Does anyone know how to solve this problem?

Thank you in advance for your reply

Regards
Hynek

Serial.begin(115200); //Baud Rate as 115200
node.begin(1, Serial); //Slave ID as 1

Does your charger really have a baud rate of 115200 configured? I have my doubts...
Did you check that the slave id is set to 1?

 result = node.readHoldingRegisters(0, pocet);  
 if (result == node.ku8MBSuccess)
 {
 Serial.println("1_??");
 }

You must not use the serial interface for two different tasks! In your setup you use it for the Modbus communication (which makes sense), so you must do the debugging on another channel. Add a display or use another Arduino model with more than one serial interface (Leonardo, Micro, Mega2560, etc.).