Arduino communication problem in wireless IR remote system

<This is a repost of an ongoing difficulty, restating the problem without all the history. I feel I may have exhausted those helping me (Paul and Jack) on the other thread! Many problems have been resolved along the way, but it appears that I am down to one last problem (a statement that may come back to haunt me!!)>

Here's the situation as it stands. I have two Arduinos that I want to put in a wireless system to relay an IR code from a hand held remote in one room of the house, to a settop box located in another room. One Arduino has an IR decoder which decodes the key from a hand held remote, and sends it to the other Arduino parked in front of the box with an IR emitter. The system, in parts, works fine. When I get the code from the detector (to my PC via USB) and send it manually (from my PC via USB) to the emitting Arduino, it controls the box properly. But when I try to send the code wirelessly directly between the Arduinos, it doesn't work quite right. The commands do not appear to be relayed correctly and the emitting Arduino can't control the box.

The Arduinos are to communicate via Xbees (S2's) installed on SainSmart shields on the Arduinos, identical hardware on each end. One XBee is configured as the coordinator, and they can communicate wirelessly as confirmed by the "PhysicalPixel" example routine turning pin 13 LED on/off as instructed on the Arduino wireless XBee page, with one XBee transmitting an "H" and "L" to turn the LED on the other Arduino on and off.

So back to my IR problem, here is what the decoding Arduino code looks like. "myNumber" holds decoded the 4 byte key:

myNumber.UL = results->value;
Serial.write(&myNumber.B,4);

When the decoder detects the IR pattern, it posts the following to the Serial port whether I use the emitter or depress the on/off key on the remote. The key in question is 61A0F00F (power on/off):

Hex Field ASCII
0000 0F F0 A0 61 ...a

The decoder puts out this same response when I direct the actual remote towards the detector, or when I am driving my emitter with the code 61A0F00F. See attached screenshot. So it can't tell the difference between the actual remote and the Arduino-driven emitter. The problem is that this output is not understood correctly by the Arduino on the emitting end of the system.

Here is what the emitting code looks like:

  void loop() {
  int x = 0;
  while (x < 4) {
    if (Serial.available()) myNumber.B[x++] = Serial.read();
}    
Serial.print(myNumber.UL, HEX);

if (x==3) irsend.sendNEC(myNumber.UL, 32);  //drive IR emitter with NEC code
delay(10000);

And the serial output looks like this:

HEX field ASCII Field
0000 36 31 41 30 46 30 30 46 61A0F00F

When I put this hex code in manually, i.e. via CoolTerm, inverted (so 0FF0A061) the settop box responds (by turning on). When I link the Arduinos wirelessly, it does not. A screenshot of the CoolTerms is attached.

Can anyone see what is wrong with the communication above? The numbers in the hex fields don't look quite right, the hex field from the decoder does look like hex, but the hex field from the emitter looks like ASCII? So is the emitter expecting an ASCII number but getting hex instead? I apologize if I am not using the terms correclly, I am a newbie at all this.

This is highly frustrating, as it appears that the system almost, almost works, BUT NOT QUITE!!

Any help/insight would be appreciated.

screenshot Arduino wireless.docx (292 KB)

When the decoder detects the IR pattern, it posts the following to the Serial port whether I use the emitter or depress the on/off key on the remote. The key in question is 61A0F00F (power on/off):

Hex Field ASCII
0000 0F F0 A0 61 ...a

Since you are sending binary data, this is what I would expect to see.

And the serial output looks like this:

HEX field ASCII Field
0000 36 31 41 30 46 30 30 46 61A0F00F

What this is telling me is that the receiver got the correct binary data and converted it to the correct value, since you are printing the value as a string. That string shows up in the ASCII field. The data in the hex field is meaningless. If you used Serial.write() on the receiver, and printed the received byte array, it should match what was printed on the sender.

So, it appears as though the receiver is properly receiving what the sender sent.

I'm curious about something. Suppose you change this:

if (x==3) irsend.sendNEC(myNumber.UL, 32);  //drive IR emitter with NEC code

to this:

if (x==3) irsend.sendNEC(0x61A0F00F, 32);  //drive IR emitter with NEC code

just as a test. If receiving any 4 bytes of data results in the IR sending the right sequence of light flashes to the TV, we've learned one thing. If not, then we've learned something different.

if (x==3) irsend.sendNEC(0x61A0F00F, 32); //drive IR emitter with NEC code

works just fine, turns TV on and off.

if (x==3) irsend.sendNEC(0x61A0F00F, 32); //drive IR emitter with NEC code

works just fine, turns TV on and off.

The only other thing I can think to try is to print myNumber.B on both sides, so the output looks like:
myNumber.b[ 0 ] = ??
myNumber.b[ 1 ] = ??
myNumber.b[ 2 ] = ??
myNumber.b[ 3 ] = ??

Perhaps the order that data is sent and received is not what we think it is. That is grasping at straws, though.

Yes, I've tried inverting the order, so now the transmitter sends both 61A0F00F and 0FF0A061. yet still no joy. I am now double checking the wireless system, as I've had some trouble with the Sainsmart board already.