gpt4 book ai didi

c++ - 如何从 Arduino 正确接收和发送原始红外数据

转载 作者:行者123 更新时间:2023-11-30 04:06:52 26 4
gpt4 key购买 nike

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

#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("");
}

使用它我可以从远程 Controller 获取:

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 正确接收和发送原始红外数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22751255/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com