peckbyte 发表于 2015-1-31 00:11:55

使用红外线库文件IRremote完美控制315m超再生模块

本帖最后由 peckbyte 于 2015-1-31 12:19 编辑

买了2对315m超再生模块,一直都找不到好的库来编码解码,后来在网上看到一位大侠提示用红外线arduino的类库可以操作315m,于是花了些时间研究了一下,发现可以完美的使用在315m超再生模块。

IRremote库主要的改动主要有一下几处:
1.删除了其他的编码解码模式,只保留了常见的NEC模式,这也是大多数家电红外线遥控器最常见的模式;
2.在IRremoteInt.h文件中改动:#define TOLERANCE 50// percent tolerance in measurements <<---增加了容错率
3.关键改动,多次试验发现解码不成功,发现红外线发射时,arduino接收的数据BUFFER会有额外的一个数据,所以解码程序是从buffer处开始分析数据,而315模块没有额外的这个数据,所以我们要改动解码程序,buffer开始解码。
实验用例子:发送程序(注意,库文件我改了个名字:IRremote315)
#include <IRremote315.h>
#include <IRremoteInt315.h>



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

void setup()
{
pinMode(3, OUTPUT);   

}

void loop()
{
Serial.print("SendIR: ");
irsend.sendNEC(0x765585, 32);   // 记得换成你遥控器的红外线编码
delay(3000);             // 等待3秒
}


接收程序:
#include <IRremote315.h>
#include <IRremoteInt315.h>



int RECV_PIN = 11;
int LED1 = 2;
long on1= 0x00FF906F;
int sta=1;
IRrecv irrecv(RECV_PIN);
decode_results results;
// 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.println("Could not decode message");
    }
else
   {
    if (results->decode_type == NEC)
      {
       Serial.print("Decoded NEC: ");
      }
   
   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 setup()
{
pinMode(RECV_PIN, INPUT);   
pinMode(LED1,OUTPUT);
pinMode(13, OUTPUT);
Serial.begin(9600);

irrecv.enableIRIn(); // Start the receiver
}
int on = 0;
unsigned long last = millis();

void loop()
{
if (irrecv.decode(&results))
   {
    // If it's been at least 1/4 second since the last
    // IR received, toggle the relay
    if (millis() - last > 250)
      {
       on = !on;
//       digitalWrite(8, on ? HIGH : LOW);
       digitalWrite(13, on ? HIGH : LOW);
       dump(&results);
      }
    if (results.value == on1 )
       {
         if(sta==1)
         {digitalWrite(LED1, HIGH);
         sta=0;
         }
         else
         {digitalWrite(LED1, LOW);
         sta=1;
         }
      
       }

    last = millis();      
    irrecv.resume(); // Receive the next value
}
}



sleept 发表于 2015-1-31 05:31:40

本帖最后由 sleept 于 2015-1-31 05:33 编辑

你的编码芯片 是不是PT2262 ? 你试过其他型号的发射芯片是否也能解码?

peckbyte 发表于 2015-1-31 12:20:39

sleept 发表于 2015-1-31 05:31 static/image/common/back.gif
你的编码芯片 是不是PT2262 ? 你试过其他型号的发射芯片是否也能解码?

这种便宜的315m模块没有解码芯片,就是用arduino编程解码的。

bigwolf 发表于 2015-1-31 12:43:54

不容易,有现成的库

学慧放弃 发表于 2015-1-31 13:37:24

我有好多这个东西,不知道干嘛用的,

创智科技 发表于 2015-1-31 17:15:18

学慧放弃 发表于 2015-1-31 13:37 static/image/common/back.gif
我有好多这个东西,不知道干嘛用的,

这个就是遥控器上面的摩托车呀卷帘门呀 那类的

Be1ieve 发表于 2015-1-31 21:18:17

另外有一套叫Virtual Wire的也不錯
現在整併進RadioHead,ASK模組

zxjlwt 发表于 2015-4-9 13:38:35

学习了。
http://arduino.surenpi.com

飞water 发表于 2015-5-7 15:55:54

mark,占坑学习

bolang0927 发表于 2015-7-5 22:40:29

支持折腾 ,顶起楼主!!!

pumpitup 发表于 2015-7-7 15:40:01

学习一下一下

zxjlwt 发表于 2015-10-14 12:46:51

可以对这个函数库做一下代码分析吗?

simatic_net 发表于 2016-3-14 21:03:52

我也买了两套,打算用来造遥控灯。
页: [1]
查看完整版本: 使用红外线库文件IRremote完美控制315m超再生模块