Go Down

Topic: Getting Header in with my Data. XBEE Series 2 (Read 787 times) previous topic - next topic

Neodudeman

#5
Sep 26, 2012, 08:26 pm Last Edit: Sep 26, 2012, 08:32 pm by Neodudeman Reason: 1

That transmit code is crap, too. It will NOT compile. The Serial.read() method does not take an argument.


My gosh, I'm just embarrassing myself. Sorry, I didn't use the copy/paste command, but was reading it off of my other computer, and was manually re-typing it here. In my touch typing, I guess signals crossed, and I got read/write confused. That should be Serial.write(), yes.


Code: [Select]
     Serial.println(Serial.read());
The println() method converts the integer returned by the Serial.read() method to a string to send, and appends a carriage return and line feed.


Yes, I was printing out what was coming in from the Serial, which is the output that I attached.

I.E.
Code: [Select]
126
0
13
144
0
19
162
0
64
61
177
104
84
132
1
76
255


But, I believe that, instead of all this extra data, it should only be 76 that gets returned.


You should be using the Serial.write() method on the receiver.


I'm sorry, I don't understand this?


If you won't post your real code that you have compiled, linked, uploaded, and executed, I'm going to quit responding.


I've edited the code I posted to accurately reflect what I've been putting into my Arduinos. I apologize for the inconvenience.

PaulS

Quote
But, I believe that, instead of all this extra data, it should only be 76 that gets returned.

Why do you believe that? 76 is the ASCII code for the letter L. When you read in the value 'L' as an int, you get 76. When you then Serial.println() that int, the bytes '7' (55), '6', (54), carriage return (13), and line feed (10) get sent. I'm not sure why you want to do that.

On the receiver, I think you would want to use:
Code: [Select]
if(Serial.available() > 0)
{
   char ltr = Serial.read();
   Serial.write(ltr);
}


What I really think that you need to do, though, is get the XBee off the hardware serial port, and use the hardware serial port (Serial) just for debugging.

Neodudeman






On the receiver, I think you would want to use:
Code: [Select]
if(Serial.available() > 0)
{
   char ltr = Serial.read();
   Serial.write(ltr);
}



The Serial.println() was on the receiver.
On the Transmitter, I'm using Write, so only H and L should get sent.

Code: [Select]
Transmit:
void setup()
{
   Serial.begin(9600);
}
void loop()
{
   Serial.write('H');
   delay(200);
   Serial.write('L');
   delay(200);
}


I've set up only one way communication; that is, the XBEE2s are setup so that one is always receiving, never sends out, and the other one Always sends to that other one, alone.


When you then Serial.println() that int, the bytes '7' (55), '6', (54), carriage return (13), and line feed (10) get sent. I'm not sure why you want to do that.


The Serial.println() was on the receiver. I suppose I should have been more clear. I have it so that the receiving XBEE2 is reading the RX, and writing to the USB's TX. That's how I'm getting the data out. This has worked in the past, but maybe that's causing the strange behavior?

Go Up