Communicating with RS 232 port on the Infinisolar Hybrid Inverter using Arduino

Hi guys,

I have a solar system installed at my home with an infinisolar V 5KW hybrid inverter. The inverter has two communication ports on it, 1 - USB and 2 - -RS 232 (RJ - 45) style connector. An RS 232 cable is provided which has an RJ 45 connector on one end and an RS 232 female connector on the other.

My problem is that i have written a small program in python which can communicate with the inverter without problem using the above said RS 232 cable coupled with a prolific USB to Serial Converter cable and responds to the command as it should.

I want to monitor the inverter using a NodeMCU or an Arduino Nano, UNO or MEGA 2560 coupled with a wifi module. I have tried using softwareserial library as well has hardware serials on MEGA but the inverter would not respond to any form of arudino. I have used TTL to Serial Converter module but to no avail.

I have also had success when sending commands through a terminal like RealTerm etc.

The only difference i can see in above two schemes is the Prolific USB to Serial Converter which is not being used in case of arduino or NodeMCU, OR
May be python and arduino transmit serial data in different ways (i have not clue about this).

I have tested the arduino circuit by hooking up the TTL to Serial Converter to the USB to Serial Converter and reading the data in the RealTerm software. The data is received correctly and the response is sent to the arudino correctly. but the inverter does not respond not even with NAKss.

I have invested almost two months now in sniffing the right protocol for my inverter and need your help in solving this issue. so

Please help, I'll be very very thankful. I am including my python code and the arduino code for your consideration.

Arduino Code Running on UNO

#include<SoftwareSerial.h>
#include<string.h>


SoftwareSerial mySerial(4, 5); 

String response = ""; 


String commandstring = "\x5E\x50\x30\x30\x35\x47\x53\x58\x14\x0D";
String P005PI = "\x5E\x50\x30\x30\x35\x50\x49\x69\x0A\x0D";


void setup() 
{
 Serial.begin(9600);
 
 mySerial.begin(2400);

 establishcontact();

}

void loop() 
{
 Serial.print("\n sending the command to inverter: ");
 Serial.println(commandstring);  

 delay(5000);
 
 mySerial.print(commandstring);

 while(mySerial.available()>0)
 {
  int data = mySerial.read();
  
  response += (char)data;

  
  if (data == '\r')
  {
    Serial.print ("\n\nThe reponse received from the inverter is: ");
    Serial.println(response);

    response = "";
     
  }
  
  
 }

}

void establishcontact()
{
  while(mySerial.available()<=0)
  {
    Serial.println ("establishing contact");
    mySerial.print("\x5E\x50\x30\x30\x35\x49\x44\x0D");
    delay(300);
  }
}

Python Code:

import serial


ser = serial.Serial("COM8", 2400)

ser.close()
ser.open()


command3 = b'\x5E\x50\x30\x30\x35\x47\x53\x58\x14\x0D'


ser.write(command3)


s = ser.read(111)	#The response is 111 charachters long string


print(s)

Monitor.ino (1.51 KB)

Python Code.txt (246 Bytes)

Please understand RS-232. It transports the serial signals (RX, TX) at +-12V levels and inverted polarity. You need a RS-232 to TTL converter for proper signal conditioning.

1 Like

DrDiettrich:
Please understand RS-232. It transports the serial signals (RX, TX) at +-12V levels and inverted polarity. You need a RS-232 to TTL converter for proper signal conditioning.

I am already using and TTL To RS 232 Converter. Can you please have a look at the attachment and see if it is the right one.

thehrao:
I am already using and TTL To RS 232 Converter. Can you please have a look at the attachment and see if it is the right one.

Links to the device specifications are so much more important than pictures!

Paul

Paul_KD7HB:
Links to the device specifications are so much more important than pictures!

Paul

Hi Paul,

Its a Max3232 based TTL to RS 232 Converter module with a female DB 9 connector which is being converted to male by using a gender changer. The Link to the device is given below:

https://www.aliexpress.com/item/33041033383.html?spm=a2g0o.productlist.0.0.692b74cd0wFD4I&algo_pvid=93a0286a-1369-4952-ac1f-f6c5de48a0fa&algo_expid=93a0286a-1369-4952-ac1f-f6c5de48a0fa-3&btsid=4658cea1-6903-4548-afaa-125800d032d8&ws_ab_test=searchweb0_0,searchweb201602_5,searchweb201603_52

@OP

Please, interface your 'inverter cable' (RS232/RJ45) with the Arduino as per following diagram using a MAX232 chip (TTL<--->RS232 logic converter). I hope, you will be OK!
db9x.png

db9x.png

GolamMostafa:
@OP

Please, interface your 'inverter cable' (RS232/RJ45) with the Arduino as per following diagram using a MAX232 chip (TTL<--->RS232 logic converter). I hope, you will be OK!

Hi, Golam Mostafa,

I have just checked my TTL - RS 232 converter and it is wired exactly as you have shown in your post. Still doesnt work. and i have no clue why.

did you wire the TTL side of the converter with the Arduino RX to TX?
what baud rate do you use in the python script?

Juraj:
did you wire the TTL side of the converter with the Arduino RX to TX?
what baud rate do you use in the python script?

Yes i did wire wit RX and TX swapped. The inverter talks only 2400 baud so python uses 2400 baud and so does the arduino.

@OP

This is SUART Port you have created:

SoftwareSerial mySerial(13, 15);

Which Arduino are you using?

Which pin (13 or 15) is the SRX pin?

If you have a UNO, upload the following simple sketch and check if there is anything that comes on the Serial Monitor.

#include<SoftwareSerial.h>
SoftwareSerial mySerial(4, 5);     //SRX = DPin-4, STX = DPin-5

void setup()
{
    Serial.begin(9600);
    mySerial.begin(2400);
}

void loop()
{
   byte n = mySerial.available();
   if(n !=0)
   {
       Serial.println(n, DEC);       //if shows 1 means one byte data has come from your inverter
       byte x = mySerial.read();
       Serial.print(x, HEX);
   }
   delay(1000);     //test interval
}

Hi, I have tested your code with Uno and no response is received from the inverter. Yet with python code already posted in my original post, it works like a charm.

I am unable to understand as to why the inverter wont respond to the arudino.

between, the 13 and 15 pins i was using were on a NodeMCU, 13 is the SRX and 15 is STX.

use text commands, not the binary strings

I have tried using text strings but the problem is that a CRC has to be sent with every command and while it is easy for me to calculate a CRC in hex format, the text equivalent is sometimes not so easy.

Even if the command is not recognised by the inverter, if the command is reaching the inverter it should return with a ^0 or NAKss but the inverter is totally silent. i suppose, its a matter of arduino not have a native usb port. Any idea how to solve that issue.

If the device implements a full blown RS-232 interface, it may be required to feed the expected signal levels to the RTS etc. pins, see response #5.

The RJ 45 connector has only three wires i.e. RX, TX and GND.

OP's .ino file, so those (most?) of us reading the forum on phones & tablets can see it

#include<SoftwareSerial.h>
#include<string.h>

uint16_t grid_voltage[4]; 
uint16_t grid_frequency[3];
uint16_t output_voltage[4];
uint16_t output_frequency[3];
uint16_t output_KVA[4];
uint16_t output_KW[4];
uint16_t output_load[3];
uint16_t bat_voltage[3]; 
uint16_t bat_dis_cur[3];
uint16_t bat_cha_cur[3];
uint16_t bat_cap[3];
uint16_t PV1_watts[4];
uint16_t PV2_watts[4];
uint16_t PV1_volts[4];
uint16_t PV2_volts[4];
bool power_direction;

SoftwareSerial mySerial(13, 15); 
String response = ""; 

char command[] = {0x5E, 0x50, 0x30, 0x30, 0x35, 0x47, 0x53, 0x58, 0x14, 0x0D};
String commandstring = "\x5E\x50\x30\x30\x35\x47\x53\x58\x14\x0D";
String P005PI = "\x5E\x50\x30\x30\x35\x50\x49\x69\x0A\x0D";


void setup() 
{
 Serial.begin(9600);
 
 mySerial.begin(2400);

 establishcontact();

}

void loop() 
{
 Serial.print("\n sending the command to inverter: ");
 Serial.println(commandstring);  
 //Serial.println(P005PI);  

 delay(5000);
 
// Serial.println(command, sizeof(command));
 mySerial.print(commandstring);
 //mySerial.print(P005PI);

 while(mySerial.available()>0)
 {
  int data = mySerial.read();
  //if (isAlphaNumeric(data))
  {
    response += (char)data;
  }
  
  if (data == '\r')
  {
    Serial.print ("\n\nThe reponse received from the inverter is: ");
    Serial.println(response);

    response = "";
     
  }
  
  
 }

}

void establishcontact()
{
  while(mySerial.available()<=0)
  {
    mySerial.print(P005PI);
    delay(300);
  }
}

Try deleting the call to establishcontact() in setup()?

Thanks for doing that, I tried to post the code this way but i am new to this forum and have no clue how to do this.

I first wrote the code without the establishcontact() but it didnt work either.

thehrao:
Thanks for doing that, I tried to post the code this way but i am new to this forum and have no clue how to do this.

Can you please tell us your reasons for not reading the "how to use this forum" post that you saw before you posted? If we can understand the most common reasons, perhaps we can address them.

Severe shortage of time.  :sweat_smile:  :sweat_smile:  :sweat_smile: