I have connected arduino mega with a rs232-ttl module.
When I am sending some hex code from arduino to pc, it is being received fine on Serial Port Monitor software.
But when I am doing the reverse operation ie, sending some hex code from the same software to arduino, it is not being received.
My code is:
#include<SoftwareSerial.h>
SoftwareSerial mySerial(6, 7); // Rx, Tx
byte data[] = {0x7e, 0xa0, 0x07, 0x03, 0x41, 0x93, 0x5a, 0x64, 0x7e, 0x7e, 0xa0, 0x44, 0x03, 0x41, 0x10, 0xb3, 0xe1, 0xe6, 0xe6, 0x00, 0x60,
0x36, 0xa1, 0x09, 0x06, 0x07, 0x60, 0x85, 0x74, 0x05, 0x08, 0x01, 0x01, 0x8a, 0x02, 0x07, 0x80, 0x8b, 0x07, 0x60, 0x85, 0x74,
0x05, 0x08, 0x02, 0x01, 0xac, 0x0a, 0x80, 0x08, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0xbe, 0x10, 0x04, 0x0e, 0x01,
0x00, 0x00, 0x00, 0x06, 0x5f, 0x1f, 0x04, 0x00, 0x00, 0x1e, 0x1d, 0xff, 0xff, 0xd4, 0x34, 0x7e};
void setup()
{
Serial.begin(9600);
mySerial.begin(9600);
}
void loop()
{
Serial.println("-----------------------");
mySerial.write(data, sizeof(data));
delay(100);
if (mySerial.available())
{
Serial.println("Reading from PC");
Serial.println(mySerial.read(), HEX);
}
else
{
Serial.println("Can't read from PC");
}
delay(1000);
}