“高帅富”空调的红外解码和遥控方法-Arduino爱好者 - Powered by Discuz!

Arduino爱好者

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 30980|回复: 18

“高帅富”空调的红外解码和遥控方法

[复制链接]
发表于 2014-5-20 21:24 | 显示全部楼层 |阅读模式
大神奈何col在教程区有一篇使用IRremote库红外遥控家里的电器,
里面提到了用IR库的RAW解码空调遥控器,让我受益匪浅。
但是空调的编码长度太长,原本库里面rawbuf缓冲区100的长度远远不够,如果按照文章改成255,可以解决一部分空调的解码了。但是有些“高帅富”空调编码长度更长,255也不够用,比如我家里的一台三菱变频机,具体表现是解码后读出的RAW指令长度正好是255,这就说明缓存溢出了。
这种情况下,单纯修改irremote.h里面的rawbuf已经没用了,因为库中缓存上限就是255,如果改成300之类的,收到的RAW指令长度反而会很小,指令是无效的。
还好,国外的大神也就是irremote库的编辑者AnalysIR 意识到了这个问题,所以在他的网站上发表了针对长空调指令的获取代码
当然不愿意看的童鞋可以使用我修改过的代码,我的代码把数组里面的负号去掉了,另外注意红外接收管的信号脚是接在2号口的:


[mw_shl_code=c,true]/*
Author: AnalysIR
Revision: 1.0

This code is provided to overcome an issue with Arduino IR libraries
It allows you to capture raw timings for signals longer than 255 marks & spaces.
Typical use case is for long Air conditioner signals.

You can use the output to plug back into IRremote, to resend the signal.

This Software was written by AnalysIR.

Usage: Free to use, subject to conditions posted on blog below.
Please credit AnalysIR and provide a link to our website/blog, where possible.

Copyright AnalysIR 2014

Please refer to the blog posting for conditions associated with use.
http://www.analysir.com/blog/201 ... ol-signals-arduino/

Connections:
IR Receiver      Arduino
V+          ->  +5v
GND          ->  GND
Signal Out   ->  Digital Pin 2
(If using a 3V Arduino, you may connect V+ to +3V)
*/

#define LEDPIN 13
//you may increase this value on Arduinos with greater than 2k SRAM
#define maxLen 800

volatile  unsigned int irBuffer[maxLen]; //stores timings - volatile because changed by ISR
volatile unsigned int x = 0; //Pointer thru irBuffer - volatile because changed by ISR

void setup() {
  Serial.begin(9600); //change BAUD rate as required
  attachInterrupt(0, rxIR_Interrupt_Handler, CHANGE);//set up ISR for receiving IR signal
}

void loop() {
  // put your main code here, to run repeatedly:

  //Serial.println(F("Press the button on the remote now - once only"));
  delay(5000); // pause 5 secs
  if (x) { //if a signal is captured
    digitalWrite(LEDPIN, HIGH);//visual indicator that signal received
    Serial.println();
    Serial.print(F("Raw: (")); //dump raw header format - for library
    Serial.print((x - 1));
    Serial.print(F(") "));
    detachInterrupt(0);//stop interrupts & capture until finshed here
    for (int i = 1; i < x; i++) { //now dump the times
      //if (!(i & 0x1)) Serial.print(F("-"));
      Serial.print(irBuffer - irBuffer[i - 1]);
      Serial.print(F(","));
    }
    x = 0;
    Serial.println();
    Serial.println();
    digitalWrite(LEDPIN, LOW);//end of visual indicator, for this time
    attachInterrupt(0, rxIR_Interrupt_Handler, CHANGE);//re-enable ISR for receiving IR signal
  }

}

void rxIR_Interrupt_Handler() {
  if (x > maxLen) return; //ignore if irBuffer is already full
  irBuffer[x++] = micros(); //just continually record the time-stamp of signal transitions

}[/mw_shl_code]



我运行这个代码以后,用空调的遥控器按了下开机,显示的raw代码长度竟然有583位之多!
接下来把这个长数组黏贴到红外发送程序中,就可以实现遥控各种空调的计划了。


最后说一句,这个新代码的最大指令长度为800位,如果还不够,只能再去抱AnalysIR的大腿了。
发表于 2016-10-18 14:41 | 显示全部楼层
楼主是sb吗?一脸蒙蔽,不会就别发
发表于 2014-8-27 10:08 来自手机 | 显示全部楼层
我使用了你的方法获取了原始码,但是发送的时候只要发送的数组元素个数超过260个就只会发送260个。583个元素也只发送260个
发表于 2015-5-9 16:02 | 显示全部楼层
我的格力空调是274,我看不明白楼主的代码是什么意思,是要改动哪里的啊?你说原文件不能改超过255,那么要怎么样做才行的阿?
发表于 2015-11-19 23:14 | 显示全部楼层
我读取了279位,之后用发射,但是仍然不能控制空调。是不是发射不能发射超过255位啊?
发表于 2015-12-4 22:43 | 显示全部楼层
楼主 你看 感觉用这个程序去解码空调很不稳定啊 每次解码的结果都不一样
发表于 2015-12-5 00:06 | 显示全部楼层
补充一下,就是我用这个程序解码美的空调的开关键,然后每次得到的解码长度,内容都不一样,长度变化不大,但是内容差异较大,希望楼主能够解答一下
发表于 2016-6-27 11:08 | 显示全部楼层
本帖最后由 yzy1102 于 2016-7-10 00:04 编辑

我看了HS0038红外接收管的手册,里面有关于接收能力的参数:"Up to 800 short bursts per second can be received continuously"见链接,所以设置为800是有道理的。HS0038http://www.szlcsc.com/product/downloadFile-5E196DCD2BF20D9F-new_pdf_doc-pdf.html上述理解有误,maxlen中的800并不是800bit的意思,这段代码仅仅是记录接收到的每个高低电平时长值而已,实际记录的bit位仅有(800-3)/2而已。不过对于编码超级庞杂的遥控来说,与其费劲解码,不如直接复制来的简单直接。只是苦了那小小的2KBram。想要实用,得在记录上想好办法。
发表于 2016-6-27 14:11 | 显示全部楼层
首先你得要有空调
发表于 2016-9-7 19:45 | 显示全部楼层
关注楼主,我现在正在做一个红外控制空调的项目,不知道楼主现在实现了吗?
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|好玩手机游戏盒子|196体育|Arduino爱好者

GMT+8, 2023-10-4 02:35 , Processed in 0.085810 second(s), 17 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表