Getting Header in with my Data. XBEE Series 2

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:

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?

To elaborate, my code for both Arduinos is

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

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

To elaborate, my code for both Arduinos is

No, it isn't. That code won't even compile.

    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?

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:

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:

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?

      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.

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

PaulS:

      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.

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.

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

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

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

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:

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.

PaulS:
On the receiver, I think you would want to use:

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.

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.

PaulS:
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?