Go Down

Topic: Arduino Uno and Xbee - why won't they communicate? (Read 503 times) previous topic - next topic

PGPops

May 25, 2013, 01:09 pm Last Edit: May 29, 2013, 07:30 pm by PGPops Reason: 1
Hello world,

I am trying to set up a simple project but I cannot get the "Serial bus" to work.

Mission: to get the "Physical Pixel" to work over XBee.

Basics:
on the first Arduino I am sending a byte every second, alternating between 'H' and 'L'
on the second Arduino I should be receiving a byte when it is available. Depending what the byte is it should toggle the Pin 13 LED on or off.

Serial stuff:
I am using SoftwareSerial.h

Xbee stuff:
I have set up the Xbee and tested them. Both are Xbee Pro S2. One is set up as the Coordinator, the other as the End Device. I have checked all the usual suspects: PIN, DH, DL, Baud rate, etc.

Note: the XBees do successfully communicate over the x-CTU terminal.

Problem: The code is not finding XBSerial.available()
I can see the one transmitting (The DO pin flashes once a second)
I can see the other receiving (The DI pin is on)

I think it is my code.

Please can you review and give me some hope?

Code Unit 1: Send alternating bytes 'H' and 'L' once a second:

Code: [Select]
#include <SoftwareSerial.h>

#define rxPin 6
#define txPin 7

//Xbee serial connection.
 SoftwareSerial XBSerial(rxPin, txPin);

void setup()
{
 Serial.begin(9600);
  //Start xBee Serial Bus
 pinMode(rxPin, INPUT);
 pinMode(txPin, OUTPUT);
 XBSerial.begin(9600);
}

void loop()
{
 XBSerial.write('H');
 delay(1000);
 XBSerial.write('L');
 delay(1000);
}


Code unit 2: Reads the bytes and should toggle Pin 13 LED:

Code: [Select]
#include <SoftwareSerial.h>

#define rxPin 6
#define txPin 7

//Xbee serial connection.
 SoftwareSerial XBSerial(rxPin, txPin);

const int ledPin = 13; // the pin that the LED is attached to
int incomingByte;      // a variable to read incoming serial data into

void setup() {
 // initialize serial communication:
 Serial.begin(9600);
 // initialize the LED pin as an output:
 pinMode(ledPin, OUTPUT);
 
  //Start xBee Serial Bus
 pinMode(rxPin, INPUT);
 pinMode(txPin, OUTPUT);
 XBSerial.begin(9600);
 
 //so I know which board to watch:
 int check=0;
 while (check<2){
   digitalWrite(ledPin, HIGH);
   delay(2000);
   digitalWrite(ledPin, LOW);
   delay(200);
   check++;
 }
}

void loop() {
 // see if there's incoming serial data:
     while (!XBSerial.available())
   // read the oldest byte in the serial buffer:
   incomingByte = Serial.read();
   
   Serial.println(incomingByte);
   // if it's a capital H (ASCII 72), turn on the LED:
   if (incomingByte == 'H') {
     digitalWrite(ledPin, HIGH);
   }
   
 // if it's an L (ASCII 76) turn off the LED:
  if (incomingByte == 'L') {
     digitalWrite(ledPin, LOW);
   }
}




I would greatly appreciate any guidance. I am new to the Arduino world so don't assume I know anything  :smiley-mr-green:

PaulS

The pin spacing of the Arduino and the pin spacing of the XBee are not compatible. You need to have something between the XBees and the Arduinos. It would be helpful to know what that is.

If it is a shield, it would be a most unusual shield that used pins 6 and 7 to communicate between the Arduino and the XBee.

If it is not a shield, then a  schematic is definitely in order.

PGPops

It is indeed a shield. It is the Iteadstudio XBee shield V1.1.

The SoftwareSerial pins are set up to the shield pins which are the jumped to Din and Dout.

PaulS

Quote
It is indeed a shield. It is the Iteadstudio XBee shield V1.1.

The SoftwareSerial pins are set up to the shield pins which are the jumped to Din and Dout.

Links and pics would be good.

HackWar

This appears to be the documentation I think:
http://itead-europe.com/pm/platform/shield/xbee%20shield/DS_IM120417004_XBeeShield.pdf

Since you use SoftwareSerial did you notice this section in the documentation?
Quote
... When XBee communicate to Arduino software serial ports, set the jumper connect DIN to
D2~13, DOUT to D2~D13 by the setting from the code ...

PGPops

Yes, that is correct. The code is set to Rx pin 6, and Tx pin 7. The shield jumpers are set Din (Rx) to D6 and Dout (Tx) to D7.

On unit 1 the Dout flashes once a second as it should. However, on the other unit the "XBSerial.available()" is never true.

Go Up