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:
#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.
eujin888:
Thank you very AWOL, Robin2 and mart256 for the prompt response.
AWOL, I tried different delays but it still did not work.
Robin2, I read the Serial Input basics, and followed the example. It did not help.
mart256, I used softserial to communicate and build in serial to print out to serial monitor. What did I missed?
Pls give me a helping hand. Thank you.
Do you understand the code you posted? Or just copypasted it? Check the void setup, there is only one serial channel being initialized. There should be two channñels.
I use a ttl to rs232 converter between arduino and rs232 device(an e-smart MPPT). No particular reason for pins 0 and 1 for soft serial. I thought any pin can be used as long as I define them. Using pins 10 and 11 also did not work either.
I attach a photo of the set-up.
Arduino Mega pin 10 to TTL/RS232 converter TXD; pin11 to TTL/RS232 converter RXD.
TTL/RS232 connector output to e-smart MPPT RS232 port.