Arduino to RS232 interface issue

Talk about Arduino board, sheilds. Sharing Arduino projects, program, problems, solutions, suggestions..... many more, all are welcome.

Arduino to RS232 interface issue

Postby eujin888 » Fri Feb 05, 2016 8:51 pm

I am trying to interface an arduino mega via a level converter to a RS232 device. To activate the RS232 device, I found I have to send string of hex codes. When I send the codes direct from the PC to the RS232 device, I see data being read back. But when I send the codes from the arduino/level converter, the RS232 device sends nothing to the arduino serial monitor.

Codes sent to RS232 device:
0x55,0xAA,0x01,0x00,0x00,0x00,0x00,0x01,0x00

I expect the RS232 device to respond:
55 AA 01 00 00 00 25 00 01 00 01 00 5E 00 5E 00 00 00 00 00 00 00 22 00 22 00 22 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 49

The arduino program I used:
CODE: SELECT_ALL_CODE
#include <SoftwareSerial.h>

int i = 0;
int x = 1 ;
byte GetData[] = {0x55,0xAA,0x01,0x00,0x00,0x00,0x00,0x01,0x00};

void setup() {
 Serial.begin(9600);
}
   
void loop()
{

 if(x>0){
   for (int i=0; i<sizeof(GetData); i++){
     Serial.write(GetData[i]);
   }
        x=x-1;
     }
 if (Serial.available()) {
   Serial.println("data");
   while(Serial.available()>0) {
     byte inByte = Serial.read();
     //Serial.print(inByte);
     delay(10);
   }}
}
 


The arduino serial monitor is blank.

Please help. Is there some bugs in my arduino program, or I have wrong configuration.

Thank you.
eujin888
Fledgling
 
Posts: 1
Joined: Fri Feb 05, 2016 8:07 pm

Re: Arduino to RS232 interface issue

Postby bengchet » Mon Feb 15, 2016 9:57 am

Hi,

From your coding, you have commented the line

Serial.print(inByte);

Of course it won't show the output on Serial monitor.

Plus, to show the data in Hex form, use

Serial.print(inByte, HEX);

If still haven't got any satisfying result, it might be hardware setup problem.
bengchet
Moderator
 
Posts: 237
Joined: Tue Aug 25, 2015 8:29 am


Return to Arduino Based

Who is online

Users browsing this forum: No registered users and 19 guests

cron