<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)