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

xautv 发表于 2018-6-5 10:10

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

接线图如下:


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

代码:
#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(); // 接收下一个编码
}
}

编译验证时出错:
警告: 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) 编译时出错。


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



奈何col 发表于 2018-6-5 12:50

警告: RobotIRremote 库要求运行在 (avr) 架构(),可能与你现在运行在 (esp8266) 架构上的开发板()不兼容
已经提示你了,这个库不兼容8266

guoqingaa 发表于 2018-6-6 08:54

这个图用什么软件画的?

997497869 发表于 2018-6-12 01:32

解决了吗

跑龙套的保 发表于 2018-6-12 09:26

这个红外库是给avr系列的单片机用的,https://github.com/markszabo/IRremoteESP8266 可以下载这个给8266的红外库

yesir119 发表于 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就行,信号引脚不影响

gaosenzhi 发表于 2021-11-10 09:50

红外模块直接接3.3V电压也可以的。

gaosenzhi 发表于 2021-11-10 09:50

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

红外模块直接接3.3V电压也可以的。

yesir119 发表于 2021-11-10 16:15

跑龙套的保 发表于 2021-11-10 09:24
可以的。供电接5v就行,信号引脚不影响

你好,感谢回复指导!我的那个8266是CH340版本的!听说VU引脚是5V的,我供电记接VU还是Vin?我买的那个接收器模块和题主不一样,他好像是光一个灯,我那个还有电路板!信号引脚也可以用3.3V的接收么?
页: [1] 2
查看完整版本: ESP8266在Arduino IDE下,红外遥控接收代码编译出错。