Pages: [1] 2   Go Down
Author Topic: Xbee Pro XSC  (Read 1642 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 34
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

We have been working on the xbee pro xsc for a couple of days,we got it to light the other arduino's led but were having problem display it on the com port,it continuously showed us -49 for any integer data.

the master code:
Code:
void setup()
{
Serial.begin(9600);
pinMode(2, HIGH);
Serial.print("start ");

}
void loop()
{
 
    Serial.print("0");
    delay(1200);
   
    Serial.print("1");
    delay(1200);
    Serial.print("2");
    delay(1200);
    Serial.print("3");
    delay(1200);
    Serial.print("e");
    delay(1200);
    Serial.print("f");
    delay(1200);
   
 
}

the slave code:
Code:

int led = 13;


void setup()
{
  Serial.begin(9600);
  pinMode(13,OUTPUT);
  Serial.print("start on slave");
}
void loop()
{
 
if (Serial.available() > 0)
{
  if (Serial.read() == '0')
  {int data=Serial.read();
  data=data-'0';
  Serial.print(data,DEC);
    digitalWrite(13,HIGH);
  }
else
{
  digitalWrite(13,LOW);
}
}
}
Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 99
Posts: 3632
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Your pinMode(2,HIGH) in your master code should not be HIGH, it should be either OUTPUT or INPUT. Im surprised you didn't get an error message. Also your trying to SEND a CHAR not an INT, so your slave code should not be looking for an INT, it should be:
char data = Serial.read();
And for your master code should be:
Serial.Write('0');
Serial.Write('1');
Serial.Write('2');
Serial.Write('3');
etc

Serial.print("0") should not be used here
« Last Edit: November 16, 2012, 03:45:21 pm by HazardsMind » Logged

Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

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

sorry but we are not even using the pushbutton...so  therefore the display is only being produced by the arduino.
Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 99
Posts: 3632
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok, regardless if your using a button or not, if you want to send data from the master to the slave you need to Serial.Write it otherwise the slave will get the wrong data.

also that -49 is just (-'0'), there is no incoming data so data = data-'0'; is going to produce -49 everytime.
« Last Edit: November 16, 2012, 03:57:34 pm by HazardsMind » Logged

Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

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

ok so this is the new output on 0 and 1 after tweaking:
start on slaveÏÏ
Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 99
Posts: 3632
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Also one other thing, if you want to receive data from the master to the slave and then print that data from the slave, you need to have a ARD mega, because a regular UNO will not be able to do both.

Unless, your master has a LCD display in which case it can do both, but to get the data from a RF or BT module and then display it on a computer monitor, it can't do that.

MEGA:
Serial.begin(9600); //print the incoming data to the screenget the incoming data
Serial1.begin(9600); // get the incoming data

Serial.print(/*your data here*/); // NOTICE the Serial"1" this puts your data on a different TX/RX to be output to the screen.
« Last Edit: November 16, 2012, 04:19:40 pm by HazardsMind » Logged

Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

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

ok so we made the master as the mega now and the uno as the slave,and changed it to Serial1.write();
Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 99
Posts: 3632
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

no the slave has to be the MEGA, because it is doing two different things with its TX and RX ports.

oh I edited my previous comment, I change the Serial and Serial1 lines. Serial is connected the usb so that should go to the PC monitor.
Logged

Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

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

and doesnt the mega have 4 serial ports,im using the 0th one,so do i need to configure it as 1
Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 99
Posts: 3632
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

no RX0 and TX0 is just Serial, everything else is Serial1...2...3.
Logged

Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

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

yup so ive put it at tx0 and rx0 so i didnt configure it
Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 99
Posts: 3632
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

As of right now, does it work? Also I think the Xbee needs to be off inorder to upload the code properly.

What are the error messages, if any?
Logged

Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

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

yup that is happening,the thing is that its glowing the led whenever defined like at 0 or 1,it does go on and the rest of the times its off,but the problem is with receiving the data,its showing me values that are constant
Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 99
Posts: 3632
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm an idiot for not asking this before, do you know how to use an xbee or is this your first time?
If this is your first time, then please go on youtube and find some tutorials. I have a sample code here that may help you.
http://code.google.com/p/xbee-arduino/
Also watch this guy:


The Xbee has it's own way of communicating to the arduino. It will not accept Serial.read or write commands, instead it has its own xbee.read and xbee.write.

HOWEVER...

If you just want to test the code you wrote, use jumper cables to simulate a connection.

Master ARD:      Slave ARD
TX  =======>    RX
RX  =======>    TX


And for your slave code, just do this:

Code:
int led = 13;


void setup()
{
  Serial.begin(9600);    // usb connection to PC, view in ARD serial monitor
  Serial1.begin(9600);  //connect to mega
  pinMode(led,OUTPUT);
  Serial.println("start on slave");
}
void loop()
{
 
if (Serial1.available() > 0) {
         digitalWrite(led,HIGH);
         char data=Serial1.read();
         Serial.print(data);
         data = ' '; // clears data for new char, (just in case)
}
else {
         digitalWrite(led,LOW);
       }
}

« Last Edit: November 16, 2012, 09:43:43 pm by HazardsMind » Logged

Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

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

its actually not the first time,ive configured it,and ive seen that video too but it doesnt help alot as ive a xbee pro xsc,but the connection is established and im using a 3v3 regulator to connect to the arduino for both my xbees,
dout=rx0(data that came ,now stored in the buffer)
din =tx0(data coming in from the arduino to transmit)
and the thing is all the codes that Ive tried till now can only do a specific function like light an led,or like jeremy blum's servo motor,but i still dont know to receive data.
The major problem with this xbee in specific is that it cant go more than 9600 baud rate,plus it works on point to point communication,so i really cant use the api mode.
« Last Edit: November 16, 2012, 10:25:15 pm by techra » Logged

Pages: [1] 2   Go Up
Jump to: