极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 12062|回复: 3

arduino leonardo红外发送问题

[复制链接]
发表于 2014-2-9 18:33:20 | 显示全部楼层 |阅读模式
        开始用 leonardo板子测试红外发送时都能正常使用(能够通过红外控制DVD播放机),我采用的是Arduino-IRremote-master库,但是这周星期五后就突然不能使用了,但是板子还是可以正常接收红外码。
       红外发射头是好,并且通过针脚3能够点亮led灯(即初步认为针脚3没有问题)。经过多次测试认为主要问题出现在代码“irsend.sendNEC(0xFFEA15,32);”上。查过很多资料,依然没能解决问题。求思路,不胜感激啊(会不会是板子坏了哦,新手)
以下是测试代码
[pre lang="arduino" line="1" file="红外发送"]#include <IRremote.h>

IRsend irsend;

void setup() {
  // put your setup code here, to run once:
  pinMode(3,OUTPUT);
  digitalWrite(3,HIGH);
  delay(3000);
  digitalWrite(3,LOW);

}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.println("SendIR: ");
  irsend.sendNEC(0xFFEA15,32);
  delay(1000);
}[/code]
回复

使用道具 举报

 楼主| 发表于 2014-2-10 12:38:51 | 显示全部楼层
补充一下,经过查找现在发现通过pin13可以正常发送红外码了,并且在
http://www.righto.com/2009/08/multi-protocol-infrared-remote-library.html上找到了有类似的问题,大牛Ken Shirriff 回复说“australopitecus: My code won't work with an Arduino mega as it has a different processor and the pins are all different. (Sorry I didn't mention that in my original article.) You could see if there's anything on PWM pin 9; I believe that's where the OC2B output connects on the mega. Probably you'll need to study the atmega 1280 datasheet and see how the PWM flags are different for the mega's processor, and change the code appropriately. Unfortunately I don't have a mega, so I can't try this myself.”
大致意思是说针脚对应的timer不一致引起的,我查了 leonardo的timer定义
const uint8_t PROGMEM digital_pin_to_timer_PGM[] = {
        NOT_ON_TIMER,       
        NOT_ON_TIMER,
        NOT_ON_TIMER,
        TIMER0B,                /* 3 */
        NOT_ON_TIMER,
        TIMER3A,                /* 5 */
        TIMER4D,                /* 6 */
        NOT_ON_TIMER,       
       
        NOT_ON_TIMER,       
        TIMER1A,                /* 9 */
        TIMER1B,                /* 10 */
        TIMER0A,                /* 11 */
       
        NOT_ON_TIMER,       
        TIMER4A,                /* 13 */
       
        NOT_ON_TIMER,       
        NOT_ON_TIMER,
        NOT_ON_TIMER,
        NOT_ON_TIMER,
        NOT_ON_TIMER,
        NOT_ON_TIMER,

        NOT_ON_TIMER,
        NOT_ON_TIMER,
        NOT_ON_TIMER,
        NOT_ON_TIMER,
        NOT_ON_TIMER,
        NOT_ON_TIMER,
        NOT_ON_TIMER,
        NOT_ON_TIMER,
        NOT_ON_TIMER,
        NOT_ON_TIMER,
};
并没有IRremote中所使用的timer2。会不会是由于这个原因导致的不稳定呢?(因为我开始用pin3是可以输出红外信息的,但今天变到pin13去了)。我的说法可能有很多问题,希望有人能指点下,不胜感激啊。
回复 支持 反对

使用道具 举报

发表于 2014-11-26 09:24:09 | 显示全部楼层
我也是 。接在3pin 无法发送红外数据。并且用手机也看不到红外发射管有工作
回复 支持 反对

使用道具 举报

发表于 2015-1-25 21:41:01 | 显示全部楼层
本帖最后由 弘毅 于 2015-1-25 21:58 编辑

leonardo不能用这个原版的红外库的,计时器有问题,我记得要用一个专用版。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-8 09:02 , Processed in 0.038288 second(s), 20 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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