Go Down

Topic: Xbee Pro XSC (Read 2068 times) previous topic - next topic

techra

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: [Select]

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: [Select]


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);
}
}
}

HazardsMind

#1
Nov 16, 2012, 09:37 pm Last Edit: Nov 16, 2012, 09:45 pm by HazardsMind Reason: 1
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
My GitHub:
https://github.com/AndrewMascolo?tab=repositories

techra

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

HazardsMind

#3
Nov 16, 2012, 09:55 pm Last Edit: Nov 16, 2012, 09:57 pm by HazardsMind Reason: 1
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.
My GitHub:
https://github.com/AndrewMascolo?tab=repositories

techra

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

HazardsMind

#5
Nov 16, 2012, 10:08 pm Last Edit: Nov 16, 2012, 10:19 pm by HazardsMind Reason: 1
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.
My GitHub:
https://github.com/AndrewMascolo?tab=repositories

techra

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

HazardsMind

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.
My GitHub:
https://github.com/AndrewMascolo?tab=repositories

techra

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

HazardsMind

no RX0 and TX0 is just Serial, everything else is Serial1...2...3.
My GitHub:
https://github.com/AndrewMascolo?tab=repositories

techra

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

HazardsMind

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?
My GitHub:
https://github.com/AndrewMascolo?tab=repositories

techra

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

HazardsMind

#13
Nov 17, 2012, 03:17 am Last Edit: Nov 17, 2012, 03:43 am by HazardsMind Reason: 1
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:
http://www.youtube.com/watch?v=vKVNmA8C6m8

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: [Select]

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);
       }
}


My GitHub:
https://github.com/AndrewMascolo?tab=repositories

techra

#14
Nov 17, 2012, 04:23 am Last Edit: Nov 17, 2012, 04:25 am by techra Reason: 1
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.

Go Up