白雪 发表于 2014-6-18 23:00:29

【求问】发送NEC红外为什么不能识别?

想法是:想通过接收空调遥控器信号,进行解析,再发送同样的信号达到控制的目的。
已经做到了接受遥控器信号,使用IRdump程序,可以获得一个C3E10000的NEC编码,之后进行发送验证,两块Arduino开发板,一个发送,一个接收,但是我在使用发射模块 irsend.sendNEC(0xC3E10000,32) 发射信号,接收器使用IRdump程序接收,COM口观察却是 unkown类型……
这个问题困扰好久了……还望大家指教!
贴上使用的代码和结果图片。
接收部分:
/*
* IRremote: IRrecvDump - dump details of IR codes with IRrecv
* An IR detector/demodulator must be connected to the input RECV_PIN.
* Version 0.1 July, 2009
* Copyright 2009 Ken Shirriff
* http://arcfn.com
* JVC and Panasonic protocol added by Kristian Lauszus (Thanks to zenwheel and other people at the original blog post)
*/

#include <IRremote.h>

int RECV_PIN = 11;

IRrecv irrecv(RECV_PIN);

decode_results results;

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

// Dumps out the decode_results structure.
// Call this after IRrecv::decode()
// void * to work around compiler issue
//void dump(void *v) {
//decode_results *results = (decode_results *)v
void dump(decode_results *results) {
int count = results->rawlen;
if (results->decode_type == UNKNOWN) {
    Serial.print("Unknown encoding: ");
}
else if (results->decode_type == NEC) {
    Serial.print("Decoded NEC: ");
}
else if (results->decode_type == SONY) {
    Serial.print("Decoded SONY: ");
}
else if (results->decode_type == RC5) {
    Serial.print("Decoded RC5: ");
}
else if (results->decode_type == RC6) {
    Serial.print("Decoded RC6: ");
}
else if (results->decode_type == PANASONIC) {       
    Serial.print("Decoded PANASONIC - Address: ");
    Serial.print(results->panasonicAddress,HEX);
    Serial.print(" Value: ");
}
else if (results->decode_type == JVC) {
   Serial.print("Decoded JVC: ");
}
Serial.print(results->value, HEX);
Serial.print(" (");
Serial.print(results->bits, DEC);
Serial.println(" bits)");
Serial.print("Raw (");
Serial.print(count, DEC);
Serial.print("): ");

for (int i = 0; i < count; i++) {
    if ((i % 2) == 1) {
      Serial.print(results->rawbuf*USECPERTICK, DEC);
    }
    else {
      Serial.print(-(int)results->rawbuf*USECPERTICK, DEC);
    }
    Serial.print(" ");
}
Serial.println("");
}


void loop() {
if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    dump(&results);
    irrecv.resume(); // Receive the next value
}
}

发送部分:
//圣源电子制作网:www.syyyd.com
//淘宝:http://syyyd.taobao.com
//红外遥控测试程序发射端
// 红外发射模块接=3
#include <IRremote.h>                  // 引用 IRRemote 函式库

IRsend irsend;                        // 定义 IRsend 物件来发射红外线讯号

void setup()
{
pinMode(3, OUTPUT);      
digitalWrite(3, HIGH);   // 点亮红外发射测试(可以用手机摄像查看是不是有工作)
delay(3000);             // 等待3秒
digitalWrite(3, LOW);    // 结束测试
}

void loop()
{
Serial.print("SendIR: ");
int i;
for(i=0;i<2;i++)
irsend.sendNEC(0xC3E10000, 32);   // 发射遥控器的红外线编码
delay(1000);             // 等待1秒自动循环发射
}


下面是COM口的内容,蓝色的是遥控器的信号,可以看到是NEC协议的C3E10000,其他的都是我发射模块发射的sendNEC(0xC3E10000,32)……这是为什么呢?

shihaipeng04 发表于 2014-6-19 11:57:35

遥控器发出的代码都是很复杂的,收不到的那个Arduino可能是因为发射的代码不正确。。

我用Arduino录制遥控器发出的信号,似乎每次都不太一样。感觉遥控器的红外信号比我想象的要复杂的多。

白雪 发表于 2014-6-19 12:15:29

shihaipeng04 发表于 2014-6-19 11:57 static/image/common/back.gif
遥控器发出的代码都是很复杂的,收不到的那个Arduino可能是因为发射的代码不正确。。

我用Arduino录制遥 ...

是呀,比想象中复杂得多……这个瓶颈卡了好久了……完全没进展:'(

shihaipeng04 发表于 2014-6-19 13:17:04

白雪 发表于 2014-6-19 12:15 static/image/common/back.gif
是呀,比想象中复杂得多……这个瓶颈卡了好久了……完全没进展

如果只是想替代遥控器来控制电器,不需要2个Arduino。。只要提前录制下遥控器的信号,保存到数组里,用控制程序发送就好了。 自发自接收的,必须得知道这些传输的规则,否则好像啥也没有。

白雪 发表于 2014-6-19 17:08:12

shihaipeng04 发表于 2014-6-19 13:17 static/image/common/back.gif
如果只是想替代遥控器来控制电器,不需要2个Arduino。。只要提前录制下遥控器的信号,保存到数组里,用控 ...

请问如何将收到的红外编码,就是在串口里看到的例如C3E10000保存下来?保存为a=0xC3E10000这样的

shihaipeng04 发表于 2014-6-19 17:34:41

白雪 发表于 2014-6-19 17:08 static/image/common/back.gif
请问如何将收到的红外编码,就是在串口里看到的例如C3E10000保存下来?保存为a=0xC3E10000这样的

好像需要是字符串格式吧。。。a="C3E10000"

我自己录的格力的老式遥控器的开机代码,在我家的老空调上实验成功了。


#include <IRremote.h>

IRsend irsend;
unsigned int buf[]=    {

9200,4250,800,400,800,400,850,2300,800,2300,800,400,850,400,800,400,800,400,850,400,800,400,800,400,800,450,750,450,750,500,700,500,700,550,600,600,600,2550,600,600,600,650,550,2550,550,650,600,650,550,650,550,650,600,650,550,700,550,650,600,650,550,650,550,700,550,650,550,650,550,2600,550,650,550,650,600,2550,550,650,550,650,600,650,550,650,550,650,650,650,550,650,550,650,600,2550,550,650,550,700,550,650,550,2600,600,650,550,650,550

};

void setup()
{
}

void loop() {
irsend.sendRaw(buf,117,38);
delay(3000);
}

林定祥 发表于 2014-6-19 19:02:32

坛子里有人介绍,空调遥控很复杂,他不尽发射现在你想发射的指令,而且还会顺带发射状态,因此你会觉得琢磨不定。
最好,你认为目前的指令和状态是对的,就把收到的数组纪录后重发就可以了。

白雪 发表于 2014-6-19 23:12:07

shihaipeng04 发表于 2014-6-19 17:34 static/image/common/back.gif
好像需要是字符串格式吧。。。a="C3E10000"

我自己录的格力的老式遥控器的开机代码,在我家的老空调上 ...

嗯,原始数组我也记录下来过,然后用一个板子和发射模块把数组发送出去,但是另一块接收模块上面也是无法解析成NEC协议的相关编码……一直卡在这里。。。

鲨鱼蜡椒 发表于 2015-10-6 14:27:06

shihaipeng04 发表于 2014-6-19 17:34 static/image/common/back.gif
好像需要是字符串格式吧。。。a="C3E10000"

我自己录的格力的老式遥控器的开机代码,在我家的老空调上 ...

你试的空调遥控器是什么型号的,怎么我的格力不能用,
页: [1]
查看完整版本: 【求问】发送NEC红外为什么不能识别?