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:
#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
#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