0x00 用途
集成 射频发射装置 到 天猫精灵的 红外网关
0x01 使用到的软件/硬件
ESP8266
Arduino 编辑器
https://github.com/crankyoldgit/IRremoteESP8266
https://github.com/sui77/rc-switch
0x02 安装驱动, 配置编辑器
参考这篇文章
http://www.taichi-maker.com/homepage/download/
0x03 ESP8266 引脚图
image.png
0x04 代码实现
#include <RCSwitch.h>
#include <IRremoteESP8266.h>
#include <IRrecv.h>
#include <IRutils.h>
const uint16_t kRecvPin = 14;
const uint16_t kSendRCPin = 2;
IRrecv irrecv(kRecvPin);
decode_results results;
RCSwitch mySwitch = RCSwitch();
void setup() {
Serial.begin(115200);
while (!Serial)
delay(50);
irrecv.enableIRIn();
Serial.println();
Serial.print("IRrecvDemo is now running and waiting for IR message on Pin ");
Serial.println(kRecvPin);
mySwitch.enableTransmit(kSendRCPin);
mySwitch.setProtocol(1);
}
void change_light_status() {
mySwitch.send(20172033, 26);
}
void loop() {
if (irrecv.decode(&results)) {
serialPrintUint64(results.value);
Serial.println("");
if (results.value == 3856494594){
Serial.println("Match");
change_light_status();
}
irrecv.resume();
delay(100);
}
}
0x05 代码解释
获取到 值为 3856494594
的红外信号时候, 就发射 20172033
的射频信号
可以自行修改
0x06 遇到的坑
IRremote 不是 arduino 和 esp8266 通用的, 需要 使用 IRremoteESP8266 这个库
我手中的红外接收器 不能接受 所有遥控器的信号, 需要买点别的种类试验一下
Arduino 上面 irremote, rcswitch 两个库有冲突, 网上有说是 timer 冲突, 尝试过修改 timer 名称 仍然不起作用, 所以最后选用了 esp8266, 理论上是可以解决的, 但是不是很擅长 C语言, 也不想调试好久 ...
这是 github 上的 issues
https://github.com/sui77/rc-switch/issues/111
https://github.com/z3t0/Arduino-IRremote/issues/360
下次不可避免了 再来试试吧如果想对 esp8266 输出电压 实现 增压, 例如 3.3v -> 5V , 可以去买一个
TXS0108E
, 我还没用, 只是查到的.