Recieving Data from Serial Object on a PC

Hello Community, this is my first post.

I have a little problem with a serial communication on my Arduino Mega. Here is my code which I used for testing:

int module1 = 22;                       //Module1

void setup() {
  Serial.begin(9600);                  //Serial Object for PC Communication
  Serial1.begin(115200);               //Serial Object for inverter module
  pinMode(module1, OUTPUT);             
  digitalWrite(module1, HIGH);         //Set the Select Pin on the Header of the Module on HIGH to
                                         enable the Serial communication
}
void loop() {
  if (Serial1.available()){

    
    while (Serial1.available()){
      Serial1.println("%in+CR+NL");         //this is a command to read serial number
      Serial.println(Serial1.read());
      delay(200);

I have a serial Object (in this case it's an inverter from the company Flexiva) and I want to control it with the Mega. The company supplies a software, to configure the modules via RS232. I used a PL2303HX to communicate with it and it works fine. Now I want to use my arduino to send and recieve data from the module (115200 Baudrate) and read the answer via USB (9600 Baudrate).

I can send data to the module, but I recieve only numbers which doesn't make any sense. Does anybody have experience with two serial communications and how to send data from one to another ?

The idea is to use a raspberry pi to control the inverter at the end.

Thank you

c0nr3f:
I can send data to the module, but I recieve only numbers which doesn't make any sense. Does anybody have experience with two serial communications and how to send data from one to another ?

Have a look at the examples in Serial Input Basics - simple reliable non-blocking ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.

...R

Also, if the data stream you get back is not readable, there may be a special serial configuration in use (start bits/stop bits etc.).

See Serial.begin() - Arduino Reference

you appear to be reading information from Serial1 at 115200baud and displaying it on the serial monitor at 9600baud possibly loosing information?
you also have delays in the your loop() function which could cause problems

I got the problem solved by several steps I took:

At first I had TXD and RXD connected the wrong way ::slight_smile:

Then there was a missunderstanding with the protocol the module used, because I was not supposed to use the "+" when I post the commands.

Thank you for your suggestions but in the end, it was just some stupidity and an error in my protocol. :slight_smile: