XBee Newbie needs help getting started

Alas, no joy quite yet, but perhaps close. I have tested all aspects of the system-- the remote IR receiver, the IR emitter, the wireless communication. The receiver decodes correctly, and the emitter can control a TV when I manually send the code, the Ardunos can communicate wirelessly. But I cannot get the receiver to talk directly with the emitter to control the TV.

So, here's the setup: Arduino #1 receives the IR signal code from the handheld remote, decodes it and writes the key to the RF serial link. Arduino #2 retrieves the key from the link and drives the IR emitter to control the TV. The key discussed here ie 61A0F00F which turns the TV off and on.

The COM15 is the arduino receiving the IR signal, Arduino #1. Attached is a screen shot of the CoolTerm monitoring COM15, as it sends the code key to the serial port. When I depress the Power button on the remote, this is the code it detects, 61A0F00F. It writes it to the serial port little endien style 0FF0A061.

Here is this portion of the code, as derived with your help:

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

WHen I input this code manually to Arduino #2) which drives the emitter, via the CoolTerm program via COM 14, it works fine, the TV turns off and on. COM14 in the attachment shows this. I am also sending the code LSB first, just like it is written by the receiver.

Here is the portion that retrieves the code from the serial port:

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

Yet something is wrong with what Arduino #2 reads from the serial port as output by the arduino #1, because the system does not work using the RF wireless communication.

One thing that doesn't look exactly right is the spaces that appear between the bytes in the COM 15 output. Is there a way to get rid of these, and could they be causing a problem?

 if (x=3) irsend.sendNEC(myNumber.UL, 32);

I just KNOW that before this project is complete, you WILL remember when to use = and when to use ==. This is NOT the place for =.

I don't see the pictures, so I can't comment on them.

You could copy and paste the text...

Oh snap! Yes indeed, x ==3. Why did it work before?

Attached is the screen shot.

CoolTerm screen shot.docx (229 KB)

The spaces are just CoolTerm helping you see the individual values. They are not part of what is send by the XBees.

Why did it work before?

Because the = is an operator, and operators return values. The = operator returns a the value assigned. That lets you do stuff like:

int a, b, c;
a = b = c = 14;

In your case, x was assigned the value 3, so the if test was the same as if(3) {}. Since 3 is not 0, the block is executed.

If that picture on the right represents the receiver, the process of sending and receiving data is not working correctly. The received data does not match the sent data. If it represents the sender, there is still a problem, in that the one side appears to be showing binary data and the other side is seeing the data as ASCII data.

Time to post both sets of code again.

Yes, I see what you mean. The serial data is sent by the receiver (COM15) and received by the emitter (COM14). Is the sender COM15 is sending hex data, but the receiver is reading binary data?
Here are the pertinent serial.write() serial.read() portions:

Serial writing:

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

Readback:

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

Is the sender COM15 is sending hex data, but the receiver is reading binary data?

Hex data IS binary data.

Serial.write(&myNumber.B,4);
//Serial.print(myNumber.UL, HEX);

if (Serial.available()) myNumber.B[x++] = Serial.read();
} Serial.print(myNumber.UL, HEX);

Using the same port to send data to a serial port monitor AND to the XBee is going to cause frustration.

How are the XBees connected to the Arduinos? If you are using shields that have an option to select which pins the XBee is connected to, or you are using wires to connect the XBee TX/RX pins to the Arduino, using something other than the hardware serial pins to talk to the XBee and using the hardware serial pins to talk to the PC would be much easier.