Pages: [1]   Go Down
Author Topic: Getting Header in with my Data. XBEE Series 2  (Read 700 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 29
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi All,

I'm getting some header data mixed in with my transmitted data. Not sure why the XBEE isn't stripping it out?

It's basically like:

Code:
Transmit:
a
Receive:
??@?=hiac~

Transmit:
b
Receive:
??@?=hib ~

Trancsmit:
c
Receive:
??@?=hicq~

As you can see, the 8th byte still has the proper data, and the consistency of the proceeding bytes makes me believe that this is not random data, but I'm really not sure why it's there.

Any ideas?
« Last Edit: September 21, 2012, 10:08:13 am by Neodudeman » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 29
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

To elaborate, my code for both Arduinos is

Code:
void setup()
{
  Serial.begin(9600);
}

void loop()
{
  if(Serial.available()>0)
  {
    char inByte = Serial.read();
    Serial.write(inByte[i]);
  }
}
Logged

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

Quote
To elaborate, my code for both Arduinos is
No, it isn't. That code won't even compile.

Code:
    Serial.write(inByte[i]);
inByte is not an array. Why are you trying to print the ith element of a non array? Where is i defined?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 29
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry about that; inByte was originally an array, and I was using readBytes(), stepping through to i. For the sake of the post, I changed it to Serial.read().

In any case, I've simplified the code, and I've still been seeing the errors:

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

Receive:
void setup()
{
   Serial.begin(9600);
}
void loop()
{
   if(Serial.available()>0)
   {
      Serial.println(Serial.read());
   }
}

Data:
Code:
Transmit:
HLHLHLHLHL

Receive:
126
0
13
144
0
19
162
0
64
61
177
104
84
132
1
76
255
126
0
13
144
0
19
162
0
64
61
177
104
84
132
1
72
3
126
0
13
144
0
19
162
0
64
61
177
104
84
132
1
76
255
126
0
13
144
0
19
162
0
64
61
177
104
84
132
1
72
3
126
0
13
144
0
19
162
0
64
61
177
104
84
132
1
76
255

I'm positive that the 126 designates the message opening, after which it closes once the proper data byte has been sent. In this case, the data bytes are 72,3 and 76,255. I've tried counting through, removing the header manually, but to little success. I suppose I could try again, but is there another, better way?
« Last Edit: September 26, 2012, 01:26:27 pm by Neodudeman » Logged

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

Code:
      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.

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

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

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 29
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
     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:
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.
« Last Edit: September 26, 2012, 01:32:48 pm by Neodudeman » Logged

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

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:
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.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 29
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset





On the receiver, I think you would want to use:
Code:
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:
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?
Logged

Pages: [1]   Go Up
Jump to: