Go Down

Topic: XBee Shield on MEGA 2560 issue (Read 174 times) previous topic - next topic

NickLavigne

Hello,

Yes I know. This has been covered many times.  But I am in a bind.  First of, yes I have read and found many forum post about similar issues, I have tried many different options and none seem to work for me.  I am starting to think that my Mega is busted, which is fine, I may buy another one.  But before I would like to see first if its me that is doing anything wrong or not.

I am using a VB.NEt application to send commands to my Arduino. I did initial XBee test with my UNO, which basic commands work and respond.  The code I will post below is my testing code.  So if I recall correctly, this worked on my MEGA yesterday.  I modified my code with my real code and it stopped working... so I reverted to my testing code... and still not working.  So I am confused.  Maybe I did something wrong somewhere.

This is the UNO code that works fine without any issues:
Code: [Select]
#define ledPin1 8
#define ledPin2 9

//Arduino UNO
// XBee's DOUT (TX) is connected to pin 2 (Arduino's Software RX)
// XBee's DIN (RX) is connected to pin 3 (Arduino's Software TX)
#include <SoftwareSerial.h>
SoftwareSerial XBee(2, 3); // RX, TX

void setup() {
  pinMode(ledPin1,OUTPUT); digitalWrite(ledPin1, HIGH);
  pinMode(ledPin2,OUTPUT); digitalWrite(ledPin2, HIGH);
  XBee.begin(9600);
  Serial.begin(9600);
}

void loop() {
  if (XBee.available()){
    char c = XBee.read();
    if(c == '1'){
        digitalWrite(ledPin1,LOW); delay(1000);
        digitalWrite(ledPin1,HIGH); delay(1);
    }else{
        digitalWrite(ledPin1,HIGH); delay(1);
    }
    if(c == '2'){
        digitalWrite(ledPin2,LOW); delay(1000);
        digitalWrite(ledPin2,HIGH); delay(1);
    }else{
        digitalWrite(ledPin2,HIGH); delay(1);
    }
  }  
}


When I transfer this to the MEGA, and before someone say "Why arent you using the hardware serial on the MEGA... I am :)  Well trying to.

Here is the MEGA code

Code: [Select]
#define ledPin1 8
#define ledPin2 9

//For Atmega2560
// XBee's DOUT (TX) to pin 14
// XBee's DIN (RX) pin 15
#define XBee Serial3

void setup() {
  pinMode(ledPin1,OUTPUT); digitalWrite(ledPin1, HIGH);
  pinMode(ledPin2,OUTPUT); digitalWrite(ledPin2, HIGH);
  XBee.begin(9600);
  Serial.begin(9600);
}

void loop() {
  if (XBee.available()){
    char c = XBee.read();
    if(c == '1'){
        digitalWrite(ledPin1,LOW); delay(1000);
        digitalWrite(ledPin1,HIGH); delay(1);
    }else{
        digitalWrite(ledPin1,HIGH); delay(1);
    }
    if(c == '2'){
        digitalWrite(ledPin2,LOW); delay(1000);
        digitalWrite(ledPin2,HIGH); delay(1);
    }else{
        digitalWrite(ledPin2,HIGH); delay(1);
    }
  }  
}


I am using Serial3, so I need to use pins 14 and 15.  It was never covered in details but I found a post where it was said to connect the DOUT from XBee Shield to the RX (pin15) and DIN to the TX (pin14).
So I connected the 2 wires (see attached pictures. One is the UNO showing it at work... the other is the 2 wires connections).

The MEGA doesnt do anything. I can see the RSSI light come up stating I received data on the XBee but even serial print doesnt show anything.  What am I doing wrong?  Any help or comments are welcomed at this time :)

thanks

ieee488

The Mega2560 has 4 hardware serial ports.
Did you try the others?


NickLavigne

The Mega2560 has 4 hardware serial ports.
Did you try the others?


i tried with serial2 and serial1

NickLavigne

#3
Mar 24, 2019, 12:40 am Last Edit: Mar 24, 2019, 12:48 am by NickLavigne
Ok well i think this issues gave me lots of headaches for nothing.
I just figured out my error.

By searching online on wiring for the xbee module, I found out that the DOUT of the XBee shield needs to go in RX of MEGA and the DIN of shield needs to go in TX of MEGA. I guess I got confused with the IN going in "Receiving" and OUT in "Transmit"... guess that was common sense except that in fact it was The OUT of shield is going IN the MEGA and the OUT of MEGA going IN the shield :)

So I was right.. I did have it working before.  Most likely I reversed the wires when installing the MEGA and didnt even noticed.
Well I guess you learn from mistakes!

Go Up