Go Down

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

Neodudeman

Sep 21, 2012, 04:47 pm Last Edit: Sep 21, 2012, 05:08 pm by Neodudeman Reason: 1
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: [Select]

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?

Neodudeman

To elaborate, my code for both Arduinos is

Code: [Select]

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

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

PaulS

Quote
To elaborate, my code for both Arduinos is

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

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

Neodudeman

#3
Sep 26, 2012, 04:15 pm Last Edit: Sep 26, 2012, 08:26 pm by Neodudeman Reason: 1
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: [Select]

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

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?

PaulS

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.

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.

Go Up