Offline
Newbie
Karma: 0
Posts: 34
|
 |
« on: November 16, 2012, 03:15:36 pm » |
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: 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: 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
Edison Member
Karma: 28
Posts: 1551
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
|
 |
« Reply #1 on: November 16, 2012, 03:37:31 pm » |
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
|
UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W, Gameduino
Arduino Tutorials, coming soon.
"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 34
|
 |
« Reply #2 on: November 16, 2012, 03:42:12 pm » |
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
Edison Member
Karma: 28
Posts: 1551
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
|
 |
« Reply #3 on: November 16, 2012, 03:55:05 pm » |
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
|
UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W, Gameduino
Arduino Tutorials, coming soon.
"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 34
|
 |
« Reply #4 on: November 16, 2012, 04:04:21 pm » |
ok so this is the new output on 0 and 1 after tweaking: start on slaveÏÏ
|
|
|
|
|
Logged
|
|
|
|
|
Queens, New York
Offline
Edison Member
Karma: 28
Posts: 1551
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
|
 |
« Reply #5 on: November 16, 2012, 04:08:23 pm » |
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
|
UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W, Gameduino
Arduino Tutorials, coming soon.
"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 34
|
 |
« Reply #6 on: November 16, 2012, 04:19:10 pm » |
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
Edison Member
Karma: 28
Posts: 1551
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
|
 |
« Reply #7 on: November 16, 2012, 04:22:17 pm » |
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
|
UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W, Gameduino
Arduino Tutorials, coming soon.
"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 34
|
 |
« Reply #8 on: November 16, 2012, 04:25:46 pm » |
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
Edison Member
Karma: 28
Posts: 1551
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
|
 |
« Reply #9 on: November 16, 2012, 04:28:46 pm » |
no RX0 and TX0 is just Serial, everything else is Serial1...2...3.
|
|
|
|
|
Logged
|
UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W, Gameduino
Arduino Tutorials, coming soon.
"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 34
|
 |
« Reply #10 on: November 16, 2012, 04:29:42 pm » |
yup so ive put it at tx0 and rx0 so i didnt configure it
|
|
|
|
|
Logged
|
|
|
|
|
Queens, New York
Offline
Edison Member
Karma: 28
Posts: 1551
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
|
 |
« Reply #11 on: November 16, 2012, 06:20:28 pm » |
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
|
UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W, Gameduino
Arduino Tutorials, coming soon.
"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 34
|
 |
« Reply #12 on: November 16, 2012, 09:11:59 pm » |
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
Edison Member
Karma: 28
Posts: 1551
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
|
 |
« Reply #13 on: November 16, 2012, 09:17:05 pm » |
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: 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
|
UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W, Gameduino
Arduino Tutorials, coming soon.
"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 34
|
 |
« Reply #14 on: November 16, 2012, 10:23:13 pm » |
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
|
|
|
|
|
|