Библиотека IRremote, irsend
- Войдите на сайт для отправки комментариев
Чт, 25/10/2012 - 20:24
Доброе время суток всем!
Использую Библотеку IRremote
В ней есть пример IRsendDemo подача ик сигнала на 3 пин, проблемма в том что мне нужно выводить сигнал не на 3 пин, а на 12 или на друго. Вопрос, как изменить порт вывода?
подскажите пожалуйста.
в самом IRremote.cpp (файл идущий вместе с библиотекой) есть строка типа // The IR output will be on pin 3 (OC2B). А ниже
pinMode(3, OUTPUT);
digitalWrite(3, LOW); // When not sending PWM, we want it low
Это и есть настройка пина(внутри библиотеки, поэтому она и работает только с 3)
Таким образом может стоит 3 заменить на ваш пин.
я пробовал, 3 заменять на нужный мне порт, но это не дало результата,
TCCR2A |= _BV(COM2B1); // Enable pin 3 PWM output
TCCR2A &= ~(_BV(COM2B1)); // Disable pin 3 PWM output
вот эти строки меня смущают. Есть еще какие идеи?
Дело в том, что код "заточен" под 3 пин. Можно перевесить на другой с PWM, но нужно будет менять, например, эти строки, которые Вас смущают. Нужно смотреть, какой таймер и какой канал этого таймера работает с нужной Вам ногой.
На 12 вывод принципиально не получится (если у Вас не МЕГА) - там нет PWM
Например, для 11 вывода нужно будет написать:
TCCR2A |= _BV(COM2A1); // Enable pin 11 PWM output
TCCR2A &= ~(_BV(COM2A1)); // Disable pin 11 PWM output
Потому что 11 вывод сидит на том же таймере, но на канале А
Читайте pin mapping, еще здесь
А для atmega8 библотеку IRremote никто непробовал переписывать?
А для atmega8 библотеку IRremote никто непробовал переписывать?
а чё с ней не так? должна работать.
некомпилируется чегото под мегу 8 под все остальное пожалуста а мега 8 шиш
IDE чё пишет, когда ошибка?
D:\Program Files\arduino-1.0\hardware\tools\avr\bin\avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega8 -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=101 -ID:\Program Files\arduino-1.0\hardware\arduino\cores\arduino -ID:\Program Files\arduino-1.0\hardware\arduino\variants\standard -ID:\Program Files\arduino-1.0\libraries\IRremote -ID:\Program Files\arduino-1.0\libraries\EEPROM C:\DOCUME~1\86C2~1\LOCALS~1\Temp\build8536526822206511613.tmp\Switch_IR_PDU_ino.cpp -o C:\DOCUME~1\86C2~1\LOCALS~1\Temp\build8536526822206511613.tmp\Switch_IR_PDU_ino.cpp.o
In file included from Switch_IR_PDU_ino.cpp:2:
d:/program files/arduino-1.0/hardware/tools/avr/lib/gcc/../../avr/include/avr/delay.h:36:2: warning: #warning "This file has been moved to <util/delay.h>."
D:\Program Files\arduino-1.0\hardware\tools\avr\bin\avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega8 -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=101 -ID:\Program Files\arduino-1.0\hardware\arduino\cores\arduino -ID:\Program Files\arduino-1.0\hardware\arduino\variants\standard -ID:\Program Files\arduino-1.0\libraries\IRremote -ID:\Program Files\arduino-1.0\libraries\EEPROM -ID:\Program Files\arduino-1.0\libraries\IRremote\utility D:\Program Files\arduino-1.0\libraries\IRremote\IRremote.cpp -o C:\DOCUME~1\86C2~1\LOCALS~1\Temp\build8536526822206511613.tmp\IRremote\IRremote.cpp.o
D:\Program Files\arduino-1.0\libraries\IRremote\IRremote.cpp: In member function 'void IRsend::enableIROut(int)':
D:\Program Files\arduino-1.0\libraries\IRremote\IRremote.cpp:200: error: 'TIMSK1' was not declared in this scope
D:\Program Files\arduino-1.0\libraries\IRremote\IRremote.cpp: In member function 'void IRrecv::enableIRIn()':
D:\Program Files\arduino-1.0\libraries\IRremote\IRremote.cpp:229: error: 'TIMSK1' was not declared in this scope
Это если юзатьтаймер 1
а если таймер 2 то
D:\Program Files\arduino-1.0\hardware\tools\avr\bin\avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega8 -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=101 -ID:\Program Files\arduino-1.0\hardware\arduino\cores\arduino -ID:\Program Files\arduino-1.0\hardware\arduino\variants\standard -ID:\Program Files\arduino-1.0\libraries\IRremote -ID:\Program Files\arduino-1.0\libraries\EEPROM C:\DOCUME~1\86C2~1\LOCALS~1\Temp\build8536526822206511613.tmp\Switch_IR_PDU_ino.cpp -o C:\DOCUME~1\86C2~1\LOCALS~1\Temp\build8536526822206511613.tmp\Switch_IR_PDU_ino.cpp.o
In file included from Switch_IR_PDU_ino.cpp:2:
d:/program files/arduino-1.0/hardware/tools/avr/lib/gcc/../../avr/include/avr/delay.h:36:2: warning: #warning "This file has been moved to <util/delay.h>."
D:\Program Files\arduino-1.0\hardware\tools\avr\bin\avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega8 -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=101 -ID:\Program Files\arduino-1.0\hardware\arduino\cores\arduino -ID:\Program Files\arduino-1.0\hardware\arduino\variants\standard -ID:\Program Files\arduino-1.0\libraries\IRremote -ID:\Program Files\arduino-1.0\libraries\EEPROM -ID:\Program Files\arduino-1.0\libraries\IRremote\utility D:\Program Files\arduino-1.0\libraries\IRremote\IRremote.cpp -o C:\DOCUME~1\86C2~1\LOCALS~1\Temp\build8536526822206511613.tmp\IRremote\IRremote.cpp.o
D:\Program Files\arduino-1.0\libraries\IRremote\IRremote.cpp: In member function 'void IRsend::mark(int)':
D:\Program Files\arduino-1.0\libraries\IRremote\IRremote.cpp:174: error: 'TCCR2A' was not declared in this scope
D:\Program Files\arduino-1.0\libraries\IRremote\IRremote.cpp:174: error: 'COM2B1' was not declared in this scope
D:\Program Files\arduino-1.0\libraries\IRremote\IRremote.cpp: In member function 'void IRsend::space(int)':
D:\Program Files\arduino-1.0\libraries\IRremote\IRremote.cpp:182: error: 'TCCR2A' was not declared in this scope
D:\Program Files\arduino-1.0\libraries\IRremote\IRremote.cpp:182: error: 'COM2B1' was not declared in this scope
D:\Program Files\arduino-1.0\libraries\IRremote\IRremote.cpp: In member function 'void IRsend::enableIROut(int)':
D:\Program Files\arduino-1.0\libraries\IRremote\IRremote.cpp:200: error: 'TIMSK2' was not declared in this scope
D:\Program Files\arduino-1.0\libraries\IRremote\IRremote.cpp:210: error: 'TCCR2A' was not declared in this scope
D:\Program Files\arduino-1.0\libraries\IRremote\IRremote.cpp:210: error: 'TCCR2B' was not declared in this scope
D:\Program Files\arduino-1.0\libraries\IRremote\IRremote.cpp:210: error: 'WGM22' was not declared in this scope
D:\Program Files\arduino-1.0\libraries\IRremote\IRremote.cpp:210: error: 'OCR2A' was not declared in this scope
D:\Program Files\arduino-1.0\libraries\IRremote\IRremote.cpp:210: error: 'OCR2B' was not declared in this scope
D:\Program Files\arduino-1.0\libraries\IRremote\IRremote.cpp: In member function 'void IRrecv::enableIRIn()':
D:\Program Files\arduino-1.0\libraries\IRremote\IRremote.cpp:226: error: 'TCCR2A' was not declared in this scope
D:\Program Files\arduino-1.0\libraries\IRremote\IRremote.cpp:226: error: 'TCCR2B' was not declared in this scope
D:\Program Files\arduino-1.0\libraries\IRremote\IRremote.cpp:226: error: 'OCR2A' was not declared in this scope
D:\Program Files\arduino-1.0\libraries\IRremote\IRremote.cpp:229: error: 'TIMSK2' was not declared in this scope
D:\Program Files\arduino-1.0\libraries\IRremote\IRremote.cpp:229: error: 'OCIE2A' was not declared in this scope
D:\Program Files\arduino-1.0\libraries\IRremote\IRremote.cpp: At global scope:
D:\Program Files\arduino-1.0\libraries\IRremote\IRremote.cpp:258: warning: 'TIMER2_COMPA_vect' appears to be a misspelled signal handler
не совсем компетентен в этом деле. почему-то переменные не декларированы....
попробуй скачать arduino ide 022 например, т.е. старую версию. видать твоя либа под старую иде написана.
есть у меня таковая таже исторя либу я подправил под 1,0
таким образом вместо #include "WProgram.h"
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
Ну а ругается на TCCR2A' was not declared in this scope потому что у 8й меги 2йтаймер подругому обзывается к примеру
TCNT2
OCR2 По идее надо переписывать все упоминания в либе но непонятно почему неработает с 1м таймером там то всё как у 168меги
Мда а ларчик просто открывался использовал таймер1 ну и поправил строчки #define TIMER_ENABLE_INTR (TIMSK = _BV(OCIE1A))
#define TIMER_DISABLE_INTR (TIMSK = 0) у атмеги8 TIMSK1 обзывается просто TIMSK Теперь правда проблемка невмещяется код в атмегу 8 наверно прийдется под себя резануть либу наверняка там много лишнего
hi all, что бы не создавать ещё одну тему напишу тут.
Пробую сократить код библиотеки, вернее от неё избавится чтоб всё в одном скетче было, ненужные функции выкинуть. А нужно чтобы при нажатии на кнопку просто отправлялась команда на устройство. с помошью примера к библиотеке(IRrecord) я считал коды - тип NEC длина 32 значение 551063. Пытаюсь уместить всё в один файл без библиотеки выдернул вроде всё но есть ошибки, сделал так:
001
#define NEC_HDR_MARK 9000
002
#define NEC_HDR_SPACE 4500
003
#define NEC_BIT_MARK 560
004
#define NEC_ONE_SPACE 1600
005
#define NEC_ZERO_SPACE 560
006
#define NEC_RPT_SPACE 2250
007
#define TIMER_PWM_PIN 3
008
#include <WProgram.h>
009
//#include <Arduino.h>
010
011
#define SYSCLOCK F_CPU
012
013
// IR detector output is active low
014
#define MARK 0
015
#define SPACE 1
016
#define NEC_BITS 32
017
018
#define TIMER_CONFIG_KHZ(val) ({ \
019
const
uint16_t pwmval = SYSCLOCK / 2000 / (val); \
020
TCCR5A = _BV(WGM51); \
021
TCCR5B = _BV(WGM53) | _BV(CS50); \
022
ICR5 = pwmval; \
023
OCR5A = pwmval / 3; \
024
})
025
026
#define TIMER_ENABLE_PWM (TCCR2A |= _BV(COM2B1))
027
#define TIMER_DISABLE_PWM (TCCR2A &= ~(_BV(COM2B1)))
028
029
#define TOPBIT 0x80000000
030
031
#define TIMER_DISABLE_INTR (TIMSK5 = 0)
032
/*
033
int COM2A = 00; //disconnect OC2A
034
int COM2B = 00; //disconnect OC2B; to send signal set to 10: OC2B non-inverted
035
int WGM2 = 101; //phase-correct PWM with OCRA as top
036
int CS2 = 000; //no prescaling*/
037
038
void
mark(
int
time) {
039
// Sends an IR mark for the specified number of microseconds.
040
// The mark output is modulated at the PWM frequency.
041
TIMER_ENABLE_PWM;
// Enable pin 3 PWM output
042
digitalWrite(TIMER_PWM_PIN, HIGH);
043
delayMicroseconds(time);
044
}
045
046
/* Leave pin off for time (given in microseconds) */
047
void
space(
int
time) {
048
// Sends an IR space for the specified number of microseconds.
049
// A space is no output, so the PWM output is disabled.
050
TIMER_DISABLE_PWM;
// Disable pin 3 PWM output
051
digitalWrite(TIMER_PWM_PIN, LOW);
052
delayMicroseconds(time);
053
}
054
055
void
enableIROut(
int
khz) {
056
// Enables IR output. The khz value controls the modulation frequency in kilohertz.
057
// The IR output will be on pin 3 (OC2B).
058
// This routine is designed for 36-40KHz; if you use it for other values, it's up to you
059
// to make sure it gives reasonable results. (Watch out for overflow / underflow / rounding.)
060
// TIMER2 is used in phase-correct PWM mode, with OCR2A controlling the frequency and OCR2B
061
// controlling the duty cycle.
062
// There is no prescaling, so the output frequency is 16MHz / (2 * OCR2A)
063
// To turn the output on and off, we leave the PWM running, but connect and disconnect the output pin.
064
// A few hours staring at the ATmega documentation and this will all make sense.
065
// See my Secrets of Arduino PWM at <a href="http://arcfn.com/2009/07/secrets-of-arduino-pwm.html" title="http://arcfn.com/2009/07/secrets-of-arduino-pwm.html" rel="nofollow">http://arcfn.com/2009/07/secrets-of-arduino-pwm.html</a> for details.
066
067
068
// Disable the Timer2 Interrupt (which is used for receiving IR)
069
TIMER_DISABLE_INTR;
//Timer2 Overflow Interrupt
070
071
pinMode(TIMER_PWM_PIN, OUTPUT);
072
digitalWrite(TIMER_PWM_PIN, LOW);
// When not sending PWM, we want it low
073
074
// COM2A = 00: disconnect OC2A
075
// COM2B = 00: disconnect OC2B; to send signal set to 10: OC2B non-inverted
076
// WGM2 = 101: phase-correct PWM with OCRA as top
077
// CS2 = 000: no prescaling
078
// The top value for the timer. The modulation frequency will be SYSCLOCK / 2 / OCR2A.
079
TIMER_CONFIG_KHZ(khz);
080
}
081
082
void
sendNEC(unsigned
long
data,
int
nbits)
083
{
084
enableIROut(38);
085
mark(NEC_HDR_MARK);
086
space(NEC_HDR_SPACE);
087
for
(
int
i = 0; i < nbits; i++) {
088
if
(data & TOPBIT) {
089
mark(NEC_BIT_MARK);
090
space(NEC_ONE_SPACE);
091
}
092
else
{
093
mark(NEC_BIT_MARK);
094
space(NEC_ZERO_SPACE);
095
}
096
data <<= 1;
097
}
098
mark(NEC_BIT_MARK);
099
space(0);
100
}
101
unsigned
long
codeValue;
102
int
codeLen;
103
void
setup
()
104
{
105
//int codeType = 1; // The type of code
106
unsigned
long
codeValue = 551063;
// The code value if not raw
107
int
codeLen = 32;
// The length of the code
108
//int toggle = 0; // The RC5/6 toggle state
109
}
110
111
void
loop
() {
112
sendNEC(codeValue, codeLen);
113
delay(1000);
114
}
При компиляции появляются следующие ошибки:
1
IR_send_0023.cpp: In function
'void enableIROut(int)'
:
2
IR_send_0023:68: error:
'TIMSK5'
was not declared
in
this
scope
3
IR_send_0023:78: error:
'TCCR5A'
was not declared
in
this
scope
4
IR_send_0023:78: error:
'WGM51'
was not declared
in
this
scope
5
IR_send_0023:78: error:
'TCCR5B'
was not declared
in
this
scope
6
IR_send_0023:78: error:
'WGM53'
was not declared
in
this
scope
7
IR_send_0023:78: error:
'CS50'
was not declared
in
this
scope
8
IR_send_0023:78: error:
'ICR5'
was not declared
in
this
scope
9
IR_send_0023:78: error:
'OCR5A'
was not declared
in
this
scope
Я так понимаю это какие то константы которые для каждого типа контроллера разные. Подскажите как быть с этим? Цель такая - хочу уместить код в ATtiny85, можно ли это сделать?
del
del
del
посмотрите здесь http://ubiyubix.wordpress.com/2012/05/05/porting-the-arduino-irremote-library-to-the-attiny4313/
извиняюсь за кучу продублированных постов, сервер писал ошибка SMTP нельзя почту мол отправить =(
.