Go Down

Topic: Problem in transmitting the with arduino mega 2560 (Read 283 times) previous topic - next topic

Yashkhandelwal

Mar 14, 2018, 10:17 am Last Edit: Mar 14, 2018, 10:26 am by Yashkhandelwal Reason: mistakenly posted previously
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

But the problem arose when I changed from Arduino leonardo to Arduino mega2560
What pins on the Mega is the XBee connected to?

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Yashkhandelwal

XBEE                                MEGA

0-RX             TO                19-RX1
1-TX             TO                 18-TX1
GND             TO                 GND     
5V                TO                 5V

Robin2

I don't have an XBee but I'm pretty sure the XBee Rx should connect to the Mega Tx and vice versa.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Yashkhandelwal

Serial.write() is not working with strings.
can you tell why?

PaulS

Quote
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.
The art of getting good answers lies in asking good questions.

Yashkhandelwal

Your idea of changing the Rx and Tx doesn't work. It even stopped sending the integer values.

Yashkhandelwal

What do you use for communication for one Arduino to another Arduino?

GrooveFlotilla

Some people are like Slinkies.

Not really good for anything, but they bring a smile to your face when pushed down the stairs.

Yashkhandelwal


GrooveFlotilla

Some people are like Slinkies.

Not really good for anything, but they bring a smile to your face when pushed down the stairs.

Go Up