以下是我从Arduino读取原始IR数据的代码:

#define sprint Serial.print
#define sprintln Serial.println
#include <IRremote.h>

#define IR_RCVR_PIN 11
IRrecv ir_receiver(IR_RCVR_PIN);
decode_results results;

void setup() {
    Serial.begin(9600);
    ir_receiver.enableIRIn(); // Start the receiver
}

void loop() {
   if (ir_receiver.decode(&results)) {
    dump(&results);
    ir_receiver.resume(); // Receive the next value
   }
}

int c = 1;

void dump(decode_results *results) {
   int count = results->rawlen;
   sprintln(c);
   c++;
   sprintln("For IR Scope: ");
   for (int i = 1; i < count; i++) {
       sprint("0x");
       sprint((unsigned int)results->rawbuf[i], HEX);
    sprint(" ");
   }

   sprintln("");
   sprintln("For Arduino sketch: ");
   sprint("unsigned int raw[");
   sprint(count, DEC);
   sprint("] = {");
   for (int i = 1; i < count; i++) {
       sprint("0x");
       sprint((unsigned int)results->rawbuf[i], HEX);
       sprint(",");
    }
    sprint("};");
    sprintln("");
    sprint("irsend.sendRaw(raw,");
    sprint(count, DEC);
    sprint(",38);");
    sprintln("");
    sprintln("");
}

使用它,我可以从 Remote 上获得此信息:
1
For IR Scope:
0x47 0x1F 0xB 0x17 0xA 0x17 0xB 0x6 0xA 0x6 0xB 0x6 0xA 0x17 0xB 0x6 0xA 0x6 0xB 0x17
0xA 0x17 0xA 0x7 0xA 0x17 0xA 0x7 0xA 0x6 0xB 0x17 0xA 0x17 0xA 0x6 0xB 0x17 0xA 0x17
0xB 0x6 0xA 0x6 0xB 0x17 0xA 0x6 0xB 0x6 0xA 0x17 0xB 0x6 0xA 0x6 0xB 0x6 0xA 0x7 0xA
0x6 0xB 0x6 0xA 0x6 0xB 0x6 0xA 0x7 0xA 0x6 0xB 0x6 0xA 0x7 0xA 0x6 0xB 0x6 0xA 0x6 0xB
0x6 0xA 0x7 0xA 0x6 0xB 0x6 0xA 0x6 0xB 0x17 0xA 0x6 0xB 0x6 0xA

For Arduino sketch:

unsigned int raw[100] =
{0x47,0x1F,0xB,0x17,0xA,0x17,0xB,0x6,0xA,0x6,0xB,0x6,0xA,0x17,
 0xB,0x6,0xA,0x6,0xB,0x17,0xA,0x17,0xA,0x7,0xA,0x17,0xA,0x7,0xA,0x6,
 0xB,0x17,0xA,0x17,0xA,0x6,0xB,0x17,0xA,0x17,0xB,0x6,0xA,0x6,0xB,0x17,0xA,
 0x6,0xB,0x6,0xA,0x17,0xB,0x6,0xA,0x6,0xB,0x6,0xA,0x7,0xA,0x6,0xB,0x6,0xA,
 0x6,0xB,0x6,0xA,0x7,0xA,0x6,0xB,0x6,0xA,0x7,0xA,0x6,0xB,0x6,0xA,0x6,0xB,
 0x6,0xA,0x7,0xA,0x6,0xB,0x6,0xA,0x6,0xB,0x17,0xA,0x6,0xB,0x6,0xA,};

因此,在发送此数据时,我可以使用以下指令:
irsend.sendRaw(raw,100,38);

问题是我无法从需要控制的设备获得任何响应。我已经检查了红外发射器,我的读数与上面相同。

我错过了什么吗?

最佳答案

您应该多次读取信号,然后取平均值以消除很小的偏差。 请确保您的发射器和接收器使用相同的光波长,并以38KHz的频率工作(您正在以38KHz的频率进行调制。如果您的发射器为您进行调制,则您不应使用IRremote)。

另外,您期望“响应”是什么?通常,IR通信是单向的。

关于c++ - 如何正确地从Arduino接收和发送原始IR数据,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22751255/

10-11 23:12