瘦网虫 发表于 2013-6-18 14:28:04

解决问题系列(3)——红外发射,控制美的空调开

本帖最后由 瘦网虫 于 2013-6-26 21:49 编辑

好久没搞红外遥控了,今天拿起来。感觉还好,对照前人们的教程贴,很快就把电路搭起来。

今天准备遥控美的空调(我手边的是美的)。

用IRremote库里面的IRdump例程,先克隆出来空调的开关,再发送回去,搞了半天,控制不了。

//unsigned int rawCodes_ac_open = {3602,4400,4450,550,1600,550,550,550,1650,500,1650,550,550,550,550,500,1650,550,550,550,550,500,1650,550,550,550,550,500,1650,550,1650,500,550,550,1650,550,550,500,1650,550,1650,500,1650,550,1650,500,550,550,1650,550,1600,550,1650,550,550,550,500,550,550,550,550,550,1600,550,550,550,550,550,1600,550,1650,550,1600,550,550,550,550,550,550,550,500,550,550,550,550,550,550,550,500,550,1650,550,1600,550,1650,550,1600,550,1650,550};
unsigned int rawCodes_ac_open = {4397,4368,561,1578,560,537,557,1581,584,1582,584,486,558,537,584,1554,560,538,558,510,558,1607,557,513,585,511,556,1585,581,1583,583,486,557,1609,556,513,558,538,557,512,558,1607,558,1583,557,1608,558,1608,557,1580,559,1606,559,1581,556,1609,557,512,559,537,558,512,557,539,557,512,558,1607,558,1582,558,537,584,1555,558,1607,556,514,559,537,556,513,558,537,556,514,558,1606,559,511,583,513,558,1582,557,1608,558,1580,585,5154,4419,4347,584,1555,558,539,557,1581,584,1581,571,501,577,516,571,1568,557,541,581,487,557,1608,557,513,558,538,557,1582,583,1582,584,487,557,1608,557,511,611,486,558,510,558,1607,557,1609,556,1583,583,1582,583,1555,558,1607,558,1607,559,1582,557,537,585,486,558,510,558,540,558,509,557,1608,558,1608,557,512,559,1606,559,1581,558,537,581,490,558,510,587,511,557,511,559,1606,559,510,569,527,558,1582,560,1604,561,1605,561};
unsigned int rawCodes_ac_close ={25524,4400,4400,550,1650,550,550,550,1600,550,1650,550,500,550,550,550,1650,550,500,550,550,550,1650,550,500,550,550,550,1650,550,1600,550,550,550,1600,550,1650,550,550,550,1600,550,1650,550,1600,550,1650,550,1600,550,1650,550,550,500,1650,550,550,550,550,500,550,550,550,550,550,550,550,500,550,550,1650,550,550,500,550,550,550,550,550,550,550,500,550,550,1650,550,550,500,1650,550,1650,500,1650,550,1650,500,1650,550,1650,550};


被屏蔽的第一行代码,就是用IRdump读出来的,这个不能控制空调。
第二行可以,看出来区别了吗?1个是100,一个是200。
每个数字为单片机捕获的美的空调遥控器的高低电平时间,单位为US,一高一低一高一低......详见sendRaw函数。
可以预见的是,第三行代码也不能用。

第二行的内容我也是无意中搜出来的,见下面的链接:
http://blog.21ic.com/user1/3179/archives/2010/68502.html

找到正确的序列,才可以控制。
下面是发送代码

Serial.print("SendIR: ");
irsend.sendRaw(rawCodes_ac_open,200, 38);   // 记得换成你遥控器的红外线编码
delay(3000);   

无它,唯运气好而已,记录一下,防止遗忘。

解决问题系列(4)——红外编码分析利器使用


解决问题系列(2)——红外发射"未知类型"代码

histamine 发表于 2013-6-18 15:49:51

IRremote接收数据的rawbuf最大长度是可以改的

见IRremote.h文件中的宏定义
#define RAWBUF 100 // Length of raw duration buffer

学长 发表于 2013-6-18 19:22:44

本帖最后由 学长 于 2013-6-18 19:23 编辑

非常高级 有参考价值.. 谢谢

瘦网虫 发表于 2013-6-18 20:38:39

histamine 发表于 2013-6-18 15:49 static/image/common/back.gif
IRremote接收数据的rawbuf最大长度是可以改的

见IRremote.h文件中的宏定义


我正准备找这个100在哪里定义的呢。呵呵。谢谢高人指点。

瘦网虫 发表于 2013-6-18 20:39:45

学长 发表于 2013-6-18 19:22 static/image/common/back.gif
非常高级 有参考价值.. 谢谢

按照猜想,如果改成200,应该可以继续读出该遥控器的其他按键红外值。

学长 发表于 2013-6-18 21:23:35

瘦网虫 发表于 2013-6-18 20:39 static/image/common/back.gif
按照猜想,如果改成200,应该可以继续读出该遥控器的其他按键红外值。

期待你的测试结果哦... 加油

FoieDEEEE_仲敬 发表于 2013-6-18 22:40:19

如果直接发十六进制数据怎么样?

瘦网虫 发表于 2013-6-20 22:16:04

本帖最后由 瘦网虫 于 2013-6-21 09:56 编辑

又找来IRremote库原文
http://www.righto.com/2009/08/multi-protocol-infrared-remote-library.html

中间提到了处理raw函数。

Handling raw codes
处理原始代码

The library provides support for sending and receiving raw durations. This is intended mainly for debugging, but can also be used for protocols the library doesn't implement, or to provide universal remote functionality.
The raw data for received IR measures the duration of successive spaces and marks in 50us ticks. The first measurement is the gap, the space before the transmission starts. The last measurement is the final mark.


The raw data for sending IR holds the duration of successive marks and spaces in microseconds. The first value is the first mark, and the last value is the last mark.



There are two differences between the raw buffers for sending and for receiving. The send buffer values are in microseconds, while the receive buffer values are in 50 microsecond ticks. The send buffer starts with the duration of the first mark, while the receive buffer starts with the duration of the gap space before the first mark. The formats are different because I considered it useful for the library to measure gaps between transmissions, but not useful for the library to provide these gaps when transmitting. For receiving, 50us granularity is sufficient for decoding and avoids overflow of the gaps, while for transmitting, 50us granularity is more than 10% error so 1us granularity seemed better.

看专家的翻译:
http://www.geek-workshop.com/thread-3574-1-1.html

瘦网虫 发表于 2013-6-20 23:05:19

学长 发表于 2013-6-18 21:23 static/image/common/back.gif
期待你的测试结果哦... 加油

测试暂时不成功。先找来原始的网站翻翻,看看原理。

啷哩个铛 发表于 2013-6-21 02:24:24

家里用的长虹空调,貌似解码不了,求楼主指导

瘦网虫 发表于 2013-6-21 08:47:45

把自己dump出来的open编码跟可以使用的正确的编码做了下对比
{4400,4450,550,1600,550,550,550,1650,500,1650,550,550,550,550,500,1650,550,550,550,550,500,1650,550,550,550,550,500,1650,550,1650,500,550,550,1650,550,550,500,
{4397,4368,561,1578,560,537,557,1581,584,1582,584,486,558,537,584,1554,560,538,558,510,558,1607,557,513,585,511,556,1585,581,1583,583,486,557,1609,556,513,558,
到37位之前都很类似(自己dump出来的第一个数字去掉后)..准备做更多研究。

瘦网虫 发表于 2013-6-21 08:49:57

啷哩个铛 发表于 2013-6-21 02:24 static/image/common/back.gif
家里用的长虹空调,貌似解码不了,求楼主指导

指导不了,自己还没有搞明白呢。

histamine 发表于 2013-6-21 09:32:29

搞个35块钱的山寨分析仪测一下,分析起来会容易很多:)

建议RAWBUF尽量改大点,留点余量

学长 发表于 2013-6-21 12:07:35

histamine 发表于 2013-6-21 09:32 static/image/common/back.gif
搞个35块钱的山寨分析仪测一下,分析起来会容易很多

建议RAWBUF尽量改大点,留点余量

请教下 我最近想买分析仪 配合 USBee Pro 那种的,请问你用的是哪一种的?谢谢

瘦网虫 发表于 2013-6-24 14:12:04

学长 发表于 2013-6-21 12:07 static/image/common/back.gif
请教下 我最近想买分析仪 配合 USBee Pro 那种的,请问你用的是哪一种的?谢谢

我用的¥168的那种,可以分析到24Mhz的。(貌似¥35的那种也一样用)

分析出红外编码后,通过sendRaw发送出去,成功控制空调了。
页: [1] 2
查看完整版本: 解决问题系列(3)——红外发射,控制美的空调开