ESP8266在Arduino IDE下,红外遥控接收代码编译出错。-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 7959|回复: 15

ESP8266在Arduino IDE下,红外遥控接收代码编译出错。

[复制链接]
发表于 2018-6-5 10:10 | 显示全部楼层 |阅读模式
接线图如下:
红外.png

开发环境:
Arduino IDE 1.8.5 + Arduino IDE for ESP8266

代码:
[mw_shl_code=bash,true]#include<RobotIRremote.h>

int RECV_PIN = D4; // 红外一体化接收头连接到Arduino 11号引脚
IRrecv irrecv(RECV_PIN); //创建一个接收对象

decode_results results; // 用于存储编码结果的对象

void setup()
{
  Serial.begin(9600); // 初始化串口通信
  irrecv.enableIRIn(); // 初始化红外解码
}

void loop()
{
  delay(500);

  if (irrecv.decode(&results))
  {
    Serial.println(results.value, HEX);
    irrecv.resume(); // 接收下一个编码
  }
}[/mw_shl_code]

编译验证时出错:
[mw_shl_code=bash,true]警告: RobotIRremote 库要求运行在 (avr) 架构(),可能与你现在运行在 (esp8266) 架构上的开发板()不兼容。
In file included from E:\Edison\NodeMcu\arduino-1.8.5\libraries\RobotIRremote\src\IRremote.cpp:20:0:

E:\Edison\NodeMcu\arduino-1.8.5\libraries\RobotIRremote\src\IRremote.cpp: In member function 'void IRrecv::enableIRIn()':

E:\Edison\NodeMcu\arduino-1.8.5\libraries\RobotIRremote\src\RobotIRremoteInt.h:238:3: error: 'TCCR2A' was not declared in this scope

   TCCR2A = _BV(WGM21); \

   ^

E:\Edison\NodeMcu\arduino-1.8.5\libraries\RobotIRremote\src\IRremote.cpp:87:3: note: in expansion of macro 'TIMER_CONFIG_NORMAL'

   TIMER_CONFIG_NORMAL();

   ^

In file included from E:\Edison\NodeMcu\arduino-1.8.5\libraries\RobotIRremote\src/avr/io.h:99:0,

                 from E:\Edison\NodeMcu\arduino-1.8.5\libraries\RobotIRremote\src/avr/interrupt.h:38,

                 from E:\Edison\NodeMcu\arduino-1.8.5\libraries\RobotIRremote\src\IRremote.cpp:23:

E:\Edison\NodeMcu\arduino-1.8.5\libraries\RobotIRremote\src\RobotIRremoteInt.h:238:16: error: 'WGM21' was not declared in this scope

   TCCR2A = _BV(WGM21); \

                ^

E:\Edison\NodeMcu\arduino-1.8.5\libraries\RobotIRremote\src/avr/sfr_defs.h:208:25: note: in definition of macro '_BV'

#define _BV(bit) (1 << (bit))

                         ^

E:\Edison\NodeMcu\arduino-1.8.5\libraries\RobotIRremote\src\IRremote.cpp:87:3: note: in expansion of macro 'TIMER_CONFIG_NORMAL'

   TIMER_CONFIG_NORMAL();

   ^

In file included from E:\Edison\NodeMcu\arduino-1.8.5\libraries\RobotIRremote\src\IRremote.cpp:20:0:

E:\Edison\NodeMcu\arduino-1.8.5\libraries\RobotIRremote\src\RobotIRremoteInt.h:239:3: error: 'TCCR2B' was not declared in this scope

   TCCR2B = _BV(CS21); \

   ^

E:\Edison\NodeMcu\arduino-1.8.5\libraries\RobotIRremote\src\IRremote.cpp:87:3: note: in expansion of macro 'TIMER_CONFIG_NORMAL'

   TIMER_CONFIG_NORMAL();

   ^

In file included from E:\Edison\NodeMcu\arduino-1.8.5\libraries\RobotIRremote\src/avr/io.h:99:0,

                 from E:\Edison\NodeMcu\arduino-1.8.5\libraries\RobotIRremote\src/avr/interrupt.h:38,

                 from E:\Edison\NodeMcu\arduino-1.8.5\libraries\RobotIRremote\src\IRremote.cpp:23:

E:\Edison\NodeMcu\arduino-1.8.5\libraries\RobotIRremote\src\RobotIRremoteInt.h:239:16: error: 'CS21' was not declared in this scope

   TCCR2B = _BV(CS21); \

                ^

E:\Edison\NodeMcu\arduino-1.8.5\libraries\RobotIRremote\src/avr/sfr_defs.h:208:25: note: in definition of macro '_BV'

#define _BV(bit) (1 << (bit))

                         ^

E:\Edison\NodeMcu\arduino-1.8.5\libraries\RobotIRremote\src\IRremote.cpp:87:3: note: in expansion of macro 'TIMER_CONFIG_NORMAL'

   TIMER_CONFIG_NORMAL();

   ^

In file included from E:\Edison\NodeMcu\arduino-1.8.5\libraries\RobotIRremote\src\IRremote.cpp:20:0:

E:\Edison\NodeMcu\arduino-1.8.5\libraries\RobotIRremote\src\RobotIRremoteInt.h:240:3: error: 'OCR2A' was not declared in this scope

   OCR2A = TIMER_COUNT_TOP / 8; \

   ^

E:\Edison\NodeMcu\arduino-1.8.5\libraries\RobotIRremote\src\IRremote.cpp:87:3: note: in expansion of macro 'TIMER_CONFIG_NORMAL'

   TIMER_CONFIG_NORMAL();

   ^

E:\Edison\NodeMcu\arduino-1.8.5\libraries\RobotIRremote\src\RobotIRremoteInt.h:241:3: error: 'TCNT2' was not declared in this scope

   TCNT2 = 0; \

   ^

E:\Edison\NodeMcu\arduino-1.8.5\libraries\RobotIRremote\src\IRremote.cpp:87:3: note: in expansion of macro 'TIMER_CONFIG_NORMAL'

   TIMER_CONFIG_NORMAL();

   ^

E:\Edison\NodeMcu\arduino-1.8.5\libraries\RobotIRremote\src\RobotIRremoteInt.h:218:31: error: 'TIMSK2' was not declared in this scope

#define TIMER_ENABLE_INTR    (TIMSK2 = _BV(OCIE2A))

                               ^

E:\Edison\NodeMcu\arduino-1.8.5\libraries\RobotIRremote\src\IRremote.cpp:90:3: note: in expansion of macro 'TIMER_ENABLE_INTR'

   TIMER_ENABLE_INTR;

   ^

In file included from E:\Edison\NodeMcu\arduino-1.8.5\libraries\RobotIRremote\src/avr/io.h:99:0,

                 from E:\Edison\NodeMcu\arduino-1.8.5\libraries\RobotIRremote\src/avr/interrupt.h:38,

                 from E:\Edison\NodeMcu\arduino-1.8.5\libraries\RobotIRremote\src\IRremote.cpp:23:

E:\Edison\NodeMcu\arduino-1.8.5\libraries\RobotIRremote\src\RobotIRremoteInt.h:218:44: error: 'OCIE2A' was not declared in this scope

#define TIMER_ENABLE_INTR    (TIMSK2 = _BV(OCIE2A))

                                            ^

E:\Edison\NodeMcu\arduino-1.8.5\libraries\RobotIRremote\src/avr/sfr_defs.h:208:25: note: in definition of macro '_BV'

#define _BV(bit) (1 << (bit))

                         ^

E:\Edison\NodeMcu\arduino-1.8.5\libraries\RobotIRremote\src\IRremote.cpp:90:3: note: in expansion of macro 'TIMER_ENABLE_INTR'

   TIMER_ENABLE_INTR;

   ^

In file included from E:\Edison\NodeMcu\arduino-1.8.5\libraries\RobotIRremote\src\IRremote.cpp:20:0:

E:\Edison\NodeMcu\arduino-1.8.5\libraries\RobotIRremote\src\IRremote.cpp: In function 'void TIMER2_COMPA_vect()':

E:\Edison\NodeMcu\arduino-1.8.5\libraries\RobotIRremote\src\RobotIRremoteInt.h:442:25: error: 'PORTB' was not declared in this scope

#define BLINKLED_ON()  (PORTB |= B00100000)

                         ^

E:\Edison\NodeMcu\arduino-1.8.5\libraries\RobotIRremote\src\IRremote.cpp:178:7: note: in expansion of macro 'BLINKLED_ON'

       BLINKLED_ON();  // turn pin 13 LED on

       ^

E:\Edison\NodeMcu\arduino-1.8.5\libraries\RobotIRremote\src\RobotIRremoteInt.h:443:25: error: 'PORTB' was not declared in this scope

#define BLINKLED_OFF() (PORTB &= B11011111)

                         ^

E:\Edison\NodeMcu\arduino-1.8.5\libraries\RobotIRremote\src\IRremote.cpp:181:7: note: in expansion of macro 'BLINKLED_OFF'

       BLINKLED_OFF();  // turn pin 13 LED off

       ^

exit status 1
为开发板 NodeMCU 1.0 (ESP-12E Module) 编译时出错。[/mw_shl_code]


但同样的代码和接线方法,在Arduino UNO的板子上就没有问题,求大神指点。



发表于 2018-6-5 12:50 | 显示全部楼层
警告: RobotIRremote 库要求运行在 (avr) 架构(),可能与你现在运行在 (esp8266) 架构上的开发板()不兼容
已经提示你了,这个库不兼容8266
发表于 2018-6-6 08:54 | 显示全部楼层
这个图用什么软件画的?
发表于 2018-6-12 09:26 | 显示全部楼层
这个红外库是给avr系列的单片机用的,https://github.com/markszabo/IRremoteESP8266 可以下载这个给8266的红外库
发表于 2021-11-10 01:57 | 显示全部楼层
跑龙套的保 发表于 2018-6-12 09:26
这个红外库是给avr系列的单片机用的,https://github.com/markszabo/IRremoteESP8266 可以下载这个给8266的 ...

请问一下,我买的ESP8266 nodeMCU,输出是3.3V的,红外模块需要5V,是不是不能合一起用哇?
发表于 2021-11-10 09:24 | 显示全部楼层
yesir119 发表于 2021-11-10 01:57
请问一下,我买的ESP8266 nodeMCU,输出是3.3V的,红外模块需要5V,是不是不能合一起用哇? ...

可以的。供电接5v就行,信号引脚不影响
发表于 2021-11-10 09:50 | 显示全部楼层
红外模块直接接3.3V电压也可以的。
发表于 2021-11-10 09:50 | 显示全部楼层
yesir119 发表于 2021-11-10 01:57
请问一下,我买的ESP8266 nodeMCU,输出是3.3V的,红外模块需要5V,是不是不能合一起用哇? ...

红外模块直接接3.3V电压也可以的。
发表于 2021-11-10 16:15 来自手机 | 显示全部楼层
跑龙套的保 发表于 2021-11-10 09:24
可以的。供电接5v就行,信号引脚不影响

你好,感谢回复指导!我的那个8266是CH340版本的!听说VU引脚是5V的,我供电记接VU还是Vin?我买的那个接收器模块和题主不一样,他好像是光一个灯,我那个还有电路板!信号引脚也可以用3.3V的接收么?
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2024-11-28 08:35 , Processed in 0.141899 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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