Pages: [1]   Go Down
Author Topic: Confused: Xbees work only when right next to each other [solved]  (Read 481 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 0
Posts: 102
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi everyone

I'm playing with a pair of Xbee's that I have to see if I can send a few lines of text from a saved file via xbees (each connected on different computers). Whenever I test sending my small text file (10 lines) by putting the xbees right next to each other (2 inches away from each other), the data is received perfectly by the receiving xbee . However... if I move the xbees further apart (just 1 ft!) the data starts to look jumbled-up in the receiving end.

I am at a loss... could this be due to a xbee configuration problem, or a programming issue? smiley-sad

Specs for both XBees: XBee Pro S1 60 mW PCB. The only configuration changes I made where to matching PAN IDs, and baud rate set to 9600. Both are powered simultaneously using 2 different computers.

Any thoughts out there on what could be going on? Thanks!


Contents of my "data.txt" file:
This is test line number #1 to see if this works
L2 This is test line number #2 to see if this works
L3 This is test line number #3 to see if this works
L4 This is test line number #4 to see if this works
L5 This is test line number #5 to see if this works
L6 This is test line number #6 to see if this works
L7 This is test line number #7 to see if this works
L8 This is test line number #8 to see if this works
L9 This is test line number #9 to see if this works
L10 This is test line number #10 to see if this works


Test 1 - XBees just 2 inches appart:
... ... ...
L10 This is test line number #10 to see if this works‘ This is test line number #1 to see if this works
L2 This is test line number #2 to see if this works
L3 This is test line number #3 to see if this works
L4 This is test line number #4 to see if this works
L5 This is test line number #5 to see if this works
L6 This is test line number #6 to see if this works
L7 This is test line number #7 to see if this works
L8 This is test line number #8 to see if this works
L9 This is test line number #9 to see if this works
L10 This is test line number #10 to see if this works‘ This is test line number #1 to see if this works
L2 This is test line number #2 to see if this works
L3 This is test line number #3 to see if this works
L4 This is test line number #4 to see if this works
L5 This is test line number #5 to see if this works
L6 This is test line number #6 to see if this works
L7 This is test line number #7 to see if this works
L8 This is test line number #8 to see if this works
L9 This is test line number #9 to see if this works
L10 This is test line number #10 to see if this works‘ This is test line number #1 to see if this works
... ... ...


Test 2 - xbees 1 foot apart:
... ... ...
L10 This is test line number #10 to see if this works T ises his iseslimber ts t n workisorsor
L9esTs ine  #1 tth
L2 mb#2hiw
if t wte # i
L6
linene#1 see ts t limbif two #ifiss mb # i t l #f um t iksise   l tthisrkis tt 2 r e  tL7te lbe t ithis woksL8s st s tsrks
 ibe#f s 0 s ine r  ±Tss st2 see iine  s thitestlibe#4is w wk
is esis w
 Thit mb  wte ntothisworks
Lhis tst num if
Lisli eree is t iis #sef inu5 s test mb #5 if ts nuseisor
Ls o orser #kso
Lisebe thinus isesl nb#2o s thL3his serhis  te ifisksesr #5to ee ifthisor
6 s 6 toee ifisTh is st lne nuer #7 tthworks
hiis tet line number #8 tos if  w9 is ts l num s ws
0  l n to f th
... ... ...


« Last Edit: November 04, 2013, 11:55:09 pm by coding1227 » Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 102
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

here is my code smiley

Code:
/// Set Up Libraries & Variables
#include <SoftwareSerial.h>  // for softserial
#include <Wire.h>
#include <SdFat.h>
SdFat sd;
SdFile myFile;
#define PinC 4       // control the XBEE PWR
#define RX_XBEE 8  // define arduino pin to TX info to XBEE
#define TX_XBEE 9   // define arduino pin to RX info from XBEE
const int chipSelect = 10;
#define TERMBAUD  9600    // This is the serial rate for your terminal program.
#define XBEEBAUD 9600    // This sets the serial rate for the XBEE
SoftwareSerial SS_xbee(RX_XBEE, TX_XBEE);    //Declare SoftwareSerial connection for Xbee


void setup()
{
  Serial.begin(TERMBAUD);
  Wire.begin();

  // set XBee settings
  pinMode(RX_XBEE, INPUT);
  pinMode(TX_XBEE, OUTPUT);
  SS_xbee.begin(XBEEBAUD);           //Sets baud rate for the XBEE

  //Set power pin mode
  pinMode(PinC, OUTPUT);

  // Initialize SdFat or print a detailed error message and halt
  if (!sd.begin(chipSelect, SPI_FULL_SPEED)) sd.initErrorHalt();
  Serial.println("Card initialized OK");
}


void loop()

  digitalWrite(PinC, HIGH);   // Turn the Xbee ON

  // Get ready to send the file via XBee
  if (!myFile.open("data.txt", O_READ)) {
    sd.errorHalt("opening data.txt for read failed");
  }
  delay(10);
  SS_xbee.println("");

  int data;
  while ((data = myFile.read()) >= 0) {
    SS_xbee.write(data);
    delay(4);
  }
  myFile.close();  // Let's close the file now that we are done...

  SS_xbee.println("");
  digitalWrite(PinC, LOW);   // Turn the Xbee OFF

  Serial.println("HELLOOOOO");
  delay(2000);    // this is pause the program
}
Logged

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

The XBee Pros will easily work out to 100m [300 feet] in normal practice. I assume you are using a UNO/etc, since use of softserial indicates presence of only 1 UART.

FWIW, I've never had any luck at all using any variant of softserial, so gave up completely [as indicated on several recent threads], and went to processors having more than 1 h.w. UART. Some people "claim" softserial works ok, but so far, no one has come forwards with actual proof of this [still waiting and hoping :-)].

In general, softserial tends to lose character bits whenever other interrupts are being processed [eg, true Serial, Timer, Servo, and everything else], as indicated by this sort of jumble:
Quote
L10 This is test line number #10 to see if this works T ises his iseslimber ts t n workisorsor
L9esTs ine  #1 tth
L2 mb#2hiw
if t wte # i
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 102
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

really? I can't believe that people have not been able to send a few lines of text from a file via xbee using an arduino...

I thought I had seen at some point people doing this before, but I can't remember exactly where...

Anyone has any examples or suggestions on how to achieve this?
Logged

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

I think you will find it works just fine if you use a processor with >1 h.w. UART,  eg mega2560 or 1280, etc. 
Logged

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

Is there something in your area that is causing interference? I've used SoftwareSerial with non-Pro models (Series 1 and Series 2) and been able to send and receive with no errors when the XBees are 150 feet apart. All of mine have the wire antenna. What type of antenna do you have?
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 102
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hmmm... I have a feeling that it isn't an issue with the processing, since the data actually does go through from one arduino uno to the other arduino uno (when the xbees are the closest to each other). I wonder if it is something else...

Hi Paul_IS: there is nothing in my area that causes interference smiley-sad
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 102
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

sorry... I forgot to mention that my xbees have the embedded disk antena (PCB)
Logged

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

Good, maybe Paul will give you a sketch he knows to work. Then, maybe we'll all have something to use.
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 102
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Oric!

After a few hours of banging my head against the wall on this issue, I was able to make it work! smiley I am not quite sure what the problem was, to be quite honest. All I did was re-build the circuit from scratch, and re-write the sketch from scratch again. Now, it works like a charm...

Crazy how these things can work sometimes smiley

Thank you so much for your suggestions nonetheless. At least, we learned that Softserial can actually work (in some cases) to send the data via xbee. Obviously, it can be a bit finicky... but well, what in the world of electronics isn't? ;-)

Logged

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

Thanks Oric!

After a few hours of banging my head against the wall on this issue, I was able to make it work! smiley I am not quite sure what the problem was, to be quite honest. All I did was re-build the circuit from scratch, and re-write the sketch from scratch again. Now, it works like a charm...

Crazy how these things can work sometimes smiley

Thank you so much for your suggestions nonetheless. At least, we learned that Softserial can actually work (in some cases) to send the data via xbee. Obviously, it can be a bit finicky... but well, what in the world of electronics isn't? ;-)
Great, how about posting your sketch, and stating which library variant you're using, so I can try it too.
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 102
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

of course! Below is my edited code. Also, I use the SoftwareSerial that comes with the Arduino software... I am guessing it is the standard?

Code:
/// Set Up Libraries & Variables
#include <SoftwareSerial.h>  // for softserial
#include <Wire.h>   
#include <SD.h>   // for writing data to SD
#define TERMBAUD  9600    // This is the serial rate for your terminal program.
#define XBEEBAUD 9600    // This sets the serial rate for the XBEE
#define RX_XBEE 8  // define arduino pin to TX info to XBEE
#define TX_XBEE 9   // define arduino pin to RX info from XBEE
SoftwareSerial SS_xbee(RX_XBEE, TX_XBEE);    //Declare SoftwareSerial connection for Xbee
int xbee = 6;  // transistor to control the XBEE PWR
File myFile;

void setup()    // the setup routine runs once when you press reset:
{
  Serial.begin(TERMBAUD);            // Sets baud rate of the terminal program
  Wire.begin();                      // Calls the wire library
  SS_xbee.begin(XBEEBAUD);           //Sets baud rate for the XBEE
  pinMode(xbee, OUTPUT);             //Sets the transistor to send 3.3v to XBEE
  pinMode(RX_XBEE, INPUT);           //Sets the Arduino 8 pin (rx) connected to Dout of XBEE
  pinMode(TX_XBEE, OUTPUT);          //Sets the Arduino 9 pin (tx) connected to Din of XBEE

  digitalWrite(xbee, HIGH);

  // Initialize Sd or print a detailed error message and halt
  if (!SD.begin(10))
  {
    Serial.println("initialization failed!");
    return;
  }
  else {
    Serial.println("Card initialized OK");
    delay(100);
  }
}



void loop()    // the loop routine runs over and over again forever:
{
  Serial.println("SERIAL PRINT This is test line number 10 to see if this works");

  // Read and send the data wirelessly
  myFile = SD.open("test.txt", O_READ);
  char data;
  while ((data = myFile.read()) >= 0) {
    SS_xbee.write(data);
    delay(4);
  }

  SS_xbee.println("END of data TX");  //Say we are finishing data TX
  delay(1000);
  digitalWrite(xbee, LOW);   // Turn the Xbee OFF

  delay(100000);    // this is pause the program

}    // Close loop


Logged

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

Thanks for posting your sketch. I think this will work ok, as long as you don't have any simultaneous operations going on, along the lines of what I mentioned previously...
Quote
In general, softserial tends to lose character bits whenever other interrupts are being processed [eg, true Serial, Timer, Servo, and everything else],

For testing, you might try putting some Serial.print(), Serial.available(), and Serial.read() statements inside your loop, and see what happens if you send and receive keyboard characters while a long file is being read from SD.
Code:
 while ((data = myFile.read()) >= 0) {

    .... <add interrupt processing code here> ....

    SS_xbee.write(data);
    delay(4);
  }
« Last Edit: November 05, 2013, 01:44:48 pm by oric_dan » Logged

Pages: [1]   Go Up
Jump to: