Pages: [1]   Go Down
Author Topic: Xbee: 2 x Adriunos, serial comms not working  (Read 942 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi All,

I've been trying to get this working for a while now. I've been reading the Building Wireless networks book and have got the two Xbees working via X-CTU. So I know they are configured properly and are talking via that protocol .

When I hook them up to my Arduinos though I can't seem to get it working as expected. I can see via the Xbee leds that they are communicating / associated but when listening to the serial port I don't receive anything. I put a simple test to turn on a LED when receiving some data and no luck . I've tried a heap of different code with no luck.

I have put a few youtube vids of the setup.







I'm using:

1x Seeduino Stalker (Xbee Co-ordinator AT)
1x EtherTen Arduino with relay shield and Sparkfun Xbee Sheild (Xbee Router AT)

I have tried with just without the relay shield and no love.

I know the Seeduino is sending via serial because I have tested via X-UTU as shown in the youtube vid. When I hook upto the 2nd Arduino I'm no getting it.

I feel / hope I'm missing something really simple.

Using this in the loop to catch the incoming data


Code:

void setup()
{
  pinMode(5, OUTPUT);
  Serial.begin(9600);
}

if (Serial.available() > 0) {
   digitalWrite(5, HIGH);
   delay(2000);
   digitalWrite(5, LOW);
}

Baudrate on the Seeduino is also 9600.

I also tried using:

#include <SoftwareSerial.h>

uint8_t pinRx = 2, pinTx = 3;
SoftwareSerial mySerial(pinRx, pinTx);

if (mySerial.available())
  {
    char gotChar = mySerial.read();
    Serial.print(gotChar);
    digitalWrite(5, HIGH);
    delay(2000);
    digitalWrite(5, LOW);   
  }

no love :\
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 551
Posts: 46204
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So, you are using the hardware serial port to talk to the XBee and the PC. Fail.

Quote
Code:

void setup()
{
  pinMode(5, OUTPUT);
  Serial.begin(9600);
}

if (Serial.available() > 0) {
   digitalWrite(5, HIGH);
   delay(2000);
   digitalWrite(5, LOW);
}
Where is the loop() function? Where do you actually read the serial data?

Quote
no love :\
No explanation about what you are doing (what are you sending?) or what the Arduino is actually doing == no help.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My objective is to have the seeduino out in the garden in report moisture and temp readings. The etherten with relay shield and xbee shield will receive this data and trigger the relay and turn on/off a water valve depending on the readings.

The I have the Seeduino transmitting "D" via serial BR 9600 every 5 seconds atm to test it. I can see the 2nd Xbee to associating with the Xbee on the Seeduino when it sends the "D" every 5 seconds.

Your right there is no loop in that code snippet. It wasn't the full set of code. It would not compile with out that.

When you say that I'm using the hardware serial port == fail. What do you recommend to use?

I tried some really basic code:

Sender:  (Seeeduino Stalker)
Code:
void setup()
{
  Serial.begin(9600);
}

void loop() {
    Serial.print('D');  // send a capital D over the serial port every 5 seconds
    delay(5000);

}

Receiver: (Etherten)
Code:
void setup() {

   Serial.begin(9600);
   pinMode(5, OUTPUT);

}

void loop() {
 
  // look for a capital D over the serial port and turn on LED if found

if (Serial.available() > 0) {
  if (Serial.read() == 'D'){
    digitalWrite(5, HIGH); //turn on LED to show it has received the data
    delay(2000); //wait for 2 seconds
   }
 }
 
      digitalWrite(5, LOW);
 }

I tried removing the if statement for checking the value and just turn on LED if anything was received and still not getting anything.

I tried using the SoftwareSerial library with this code:

Receiver:

Code:
#include <SoftwareSerial.h>

uint8_t pinRx = 0, pinTx = 1;
SoftwareSerial mySerial(pinRx, pinTx);

long BaudRate = 9600;

int led = 5;

void setup()
{
  pinMode(led, OUTPUT);
 
  Serial.begin(BaudRate);
  mySerial.begin(BaudRate); 
  mySerial.listen();
}

void loop()
{
  // transmit
  if (Serial.available())
  {
    digitalWrite(led, HIGH);
    char gotChar = Serial.read();
    Serial.print(gotChar);
    mySerial.print(gotChar);
    digitalWrite(led, HIGH);
    delay(2000);
    digitalWrite(led, LOW);
  }
 
  // receive
  if (mySerial.available())
  {
    char gotChar = mySerial.read();
    Serial.print(gotChar);
    digitalWrite(led, HIGH);
    delay(2000);
    digitalWrite(led, LOW);   
  }
}

I still didn't receive anything.

I feel I'm missing something basic here because all the stuff I have read it should work. I can see via the Xbee status that they are associating and if I hook the Etherten xbee via USB to X-UTU it is receiving the "D"

Also if I hook up via USB and type in "D" the LED turns on so I know the code is right (logic wise).

Logged

the land of sun+snow
Offline Offline
Faraday Member
**
Karma: 149
Posts: 2790
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

How does the Stalker select between the XBee going to the Arduino Tx/Rx pins and the normal
USB/FTDI interface going to the Tx/Rx pins. You can't have both connected at the same time.

Also I wouldn't use such long delays in the code, as the responsiveness of the system is impacted.
You might get farther with sending data every 1-sec, and blinking leds for 0.1-sec.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I look up the specs and looks like it does not have one. I use the Uartbee to program it then remove it.



http://www.seeedstudio.com/wiki/Seeeduino_Stalker_v2.2#Bee_Module_Related

'Serial interface – To save space and lower costs, USB<->Serial connectivity is not provided by default. You may use the FT232 based UartSBee or other USB to serial adapter boards to do the programming or communicate with the PC.'

Should I still be using the Softwareserial library on both ends?

Logged

the land of sun+snow
Offline Offline
Faraday Member
**
Karma: 149
Posts: 2790
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Need more info,

1. with your setup, are you using any kind of USB device [FTDI cable or FTDI Friend, etc], or making
    comms via XBee only?

2. unless something is funny with the Stalker design, you should not be using SoftSerial at pins 0,1
    because those pins are wired to the hardware UART of the Arduino, accessed via
    Serial.begin(9600); and other Serial.xxx functions. Therefore, having both

   Serial.begin(BaudRate);
   mySerial.begin(BaudRate);

   kinds of statements in the same sketch will cause a conflict between Serial and SoftSerial.

3. Similarly, where you are using SoftwareSerial on pins 2,3, what is connected to those pins on
    the header? Normally, they're just open.

4. I assume in your Receiver sketch where you have Serial and SoftSerial, you are trying to use one
    of those  ports as a debug port? Do you have something [FDTI cable or Friend] connected to J2 on
    the Receiver board?

   
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

1. with your setup, are you using any kind of USB device [FTDI cable or FTDI Friend, etc], or making
    comms via XBee only?

    Only via XBee.. just use USB to program it then remove them. Running off battery on the Seeeduino and mains on the Etherten Arduino

2. unless something is funny with the Stalker design, you should not be using SoftSerial at pins 0,1
    because those pins are wired to the hardware UART of the Arduino, accessed via
    Serial.begin(9600); and other Serial.xxx functions. Therefore, having both


   Serial.begin(BaudRate);
   mySerial.begin(BaudRate);
 

   kinds of statements in the same sketch will cause a conflict between Serial and SoftSerial.

  I changed to 2,3 on both units to avoid conflicts.

   Also made Serial 9600 and myserial 4800 on both ends (Seeeduino and Etherten)


3. Similarly, where you are using SoftwareSerial on pins 2,3, what is connected to those pins on
    the header? Normally, they're just open.

    Nothing connect on either ends on these pins. I tired different pins also

4. I assume in your Receiver sketch where you have Serial and SoftSerial, you are trying to use one
    of those  ports as a debug port? Do you have something [FDTI cable or Friend] connected to J2 on
    the Receiver board?

    I remove the cable on the J2.. just have it running on battery.

   
   
Logged

the land of sun+snow
Offline Offline
Faraday Member
**
Karma: 149
Posts: 2790
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
3. Similarly, where you are using SoftwareSerial on pins 2,3, what is connected to those pins on
    the header? Normally, they're just open.

    Nothing connect on either ends on these pins. I tired different pins also

I checked about the Etherten board, I have not seen it before.

http://www.freetronics.com/products/etherten#.UKpwPOTBGfU

I assume this is where your problem is, as it has a USB chip onboard and that is hardwired to
the RX,TX pins and Serial.xxx functions, so you have to use SoftSerial on that board for the
XBee. The problem is now you have to connect the XBee module to the pins used by SoftSerial,
rather than to Rx,TX [pins 0,1] default.

Does your XBee shield allow you to do that? From what I've seen, all in all, most XBee shields
are not very well designed to deal with these problems.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for all your help so far.

The shield I'm using is a Sparkfun Xbee shield

https://www.sparkfun.com/products/9841?

'The serial pins (DIN and DOUT) of the XBee are connected through an SPDT switch, which allows you to select a connection to either the UART pins (D0, D1) or any digital pins on the Arduino (D2 and D3 default).'
Logged

the land of sun+snow
Offline Offline
Faraday Member
**
Karma: 149
Posts: 2790
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Then, flip the switch and try using SoftSerial on pins 2,3 - or 3,2 - it's easy to
get the wrong ones, crossed.

Also, you need to check the shield you have has 3.3V to 5V level shifters on the
Rx,Tx lines from the Arduino to the XBee, as it's a 3.3V device. Some of the older
Sparkfun shields were deficient on this aspect.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I went back to basics and used the standard R3 UNO and breadboard with a xbee breakout board... its working with that code.... FINALLY smiley-grin been so frustrating..

I started layering it back up.. and when I connect the sparkfun shield it all falls over.. It worked once.. then stopped and couldnt get it to work again... Thinking it maybe faulty?



Thanks again for your help
Logged

the land of sun+snow
Offline Offline
Faraday Member
**
Karma: 149
Posts: 2790
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Good thinking, your pictures show so many wires, it looks like you may have gotten ahead of
yourself in hooking everything up before the various pieces were all tested individually.

I looked at the schematic for the Sparkfun XBee shield you linked. Like most Arduino world schematics,
I find it to be totally bizarre.

IE, the headers on the board are not labelled at all, and JP1-1..6 on the schematic no doubt refer to
pins 2..7 on the unlabelled header. Also, there are no 5V - 3.3V level-shifters. I swear they must have
4-yearolds designing these things. In any case, that's no doubt clearly a big problem you're having.
You'll likely damage the XBee module connecting 5V to the Din pin.

Some other companies, like Adafruit, sell properly-designed XBee shields.

The other problem is, people always have trouble trying to do debugging and XBee comms simultaneously
on -UNO style boards, which have only 1 hardware UART. You have to use SoftSerial, and it's never worked
well for me. All in all, it works better to jumper the XBee module to pins 0,1 [through level-shifters].



« Last Edit: November 20, 2012, 12:12:00 pm by oric_dan(333) » Logged

Pages: [1]   Go Up
Jump to: