I am working was working with arduino leonardo and xbee s2c for transmitting the values and message.
I was successful in doing that.
Sender:
String a;
String b;
void setup()
{
Serial.begin(9600);
Serial1.begin(9600);
}
void loop()
{
a="HEllO";
b="YASH";
Serial1.print("At b: ");
Serial1.print(b);
Serial1.print("At a: ");
Serial1.print(a);
delay(400);
Serial.flush();
Serial1.flush();
}
Receiver:
String b;
String a;
void setup()
{
Serial.begin(9600);
Serial1.begin(9600);
}
void loop()
{
if (Serial.available())
{
a=Serial.readString();
Serial1.print("At a");
Serial1.println(a);
}
if (Serial1.available())
{
b= Serial1.readString();
Serial.print("At b");
Serial.println(b);
}
all worked perfectly fine.
But the problem arose when I changed from Arduino leonardo to Arduino mega2560
it doesnt send nor receives.
Can someone help me.
Robin2
March 14, 2018, 10:50am
#2
Yashkhandelwal:
But the problem arose when I changed from Arduino leonardo to Arduino mega2560
What pins on the Mega is the XBee connected to?
...R
XBEE MEGA
0-RX TO 19-RX1
1-TX TO 18-TX1
GND TO GND
5V TO 5V
Robin2
March 20, 2018, 9:58am
#4
I don't have an XBee but I'm pretty sure the XBee Rx should connect to the Mega Tx and vice versa.
...R
Serial.write() is not working with strings.
can you tell why?
system
March 20, 2018, 11:18am
#6
can you tell why?
There is no reason why it should. What write() is NOT doing is sending a String the way you expect. What that means is that your expectations are wrong. What do you think should be sent when you send a String OBJECT (NOT the string wrapped by a String object) in binary?
write() is for sending binary data. print() is for sending the data in ASCII. write() is (properly) NOT overloaded to deal with String objects. print() is.
Your idea of changing the Rx and Tx doesn't work. It even stopped sending the integer values.
What do you use for communication for one Arduino to another Arduino?
BUT I WANT WIRELESS COMMUNICATION.