Библиотека IRremote, irsend

Elektro
Offline
Зарегистрирован: 10.02.2012

 Доброе время суток всем! 

Использую Библотеку IRremote

В ней есть пример IRsendDemo подача ик сигнала на 3 пин, проблемма в том что мне нужно выводить сигнал не на 3 пин, а на 12 или на друго. Вопрос, как изменить порт вывода? 

подскажите пожалуйста.

 

memfise
Offline
Зарегистрирован: 30.06.2012

в самом 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 заменить на ваш пин.

 

Elektro
Offline
Зарегистрирован: 10.02.2012

 я пробовал, 3 заменять на нужный мне порт, но это не дало результата, 

TCCR2A |= _BV(COM2B1); // Enable pin 3 PWM output

TCCR2A &= ~(_BV(COM2B1)); // Disable pin 3 PWM output

вот эти строки меня смущают. Есть еще какие идеи? 
 

 

AlexFisher
AlexFisher аватар
Offline
Зарегистрирован: 20.12.2011

Дело в том, что код "заточен" под 3 пин. Можно перевесить на другой с PWM, но нужно будет менять, например, эти строки, которые Вас смущают. Нужно смотреть, какой таймер и какой канал этого таймера работает с нужной Вам ногой. 

На 12 вывод принципиально не получится (если у Вас не МЕГА) - там нет PWM

Например, для 11 вывода нужно будет написать:

TCCR2A |= _BV(COM2A1); // Enable pin 11 PWM output

TCCR2A &= ~(_BV(COM2A1)); // Disable pin 11 PWM output

Потому что 11 вывод сидит на том же таймере, но на канале А

Читайте pin mapping, еще здесь 

alexval2007
Offline
Зарегистрирован: 10.11.2012

А для atmega8 библотеку IRremote никто непробовал переписывать?

medossa
Offline
Зарегистрирован: 10.07.2012

alexval2007 пишет:

А для atmega8 библотеку IRremote никто непробовал переписывать?

а чё с ней не так? должна работать.

alexval2007
Offline
Зарегистрирован: 10.11.2012

некомпилируется чегото под мегу 8 под все остальное пожалуста а мега 8 шиш

medossa
Offline
Зарегистрирован: 10.07.2012

IDE чё пишет, когда ошибка?

alexval2007
Offline
Зарегистрирован: 10.11.2012

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

 

medossa
Offline
Зарегистрирован: 10.07.2012

не совсем компетентен в этом деле. почему-то переменные не декларированы....

попробуй скачать arduino ide 022 например, т.е. старую версию. видать твоя либа под старую иде написана.

alexval2007
Offline
Зарегистрирован: 10.11.2012

есть у меня таковая таже исторя либу я подправил под 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меги
 

alexval2007
Offline
Зарегистрирован: 10.11.2012

Мда а ларчик просто открывался использовал таймер1 ну и поправил строчки #define TIMER_ENABLE_INTR    (TIMSK = _BV(OCIE1A))
#define TIMER_DISABLE_INTR   (TIMSK = 0)  у атмеги8 TIMSK1 обзывается просто TIMSK Теперь  правда проблемка невмещяется код в атмегу 8 наверно прийдется под себя резануть либу наверняка там много лишнего

inhelp
inhelp аватар
Offline
Зарегистрирован: 23.09.2012
Из файлика IRremoteInt.h для атмеги 
 
/ Atmega8
#elif defined(__AVR_ATmega8P__) || defined(__AVR_ATmega8__)
  #define IR_USE_TIMER1   // tx = pin 9
 
У меня библиотека компилится под  Atmega 8a-pu
 
xplp
Offline
Зарегистрирован: 21.12.2012

hi all, что бы не создавать ещё одну тему напишу тут. 

Пробую сократить код библиотеки, вернее от неё избавится чтоб всё в одном скетче было, ненужные функции выкинуть. А нужно чтобы при нажатии на кнопку просто отправлялась команда на устройство. с помошью примера к библиотеке(IRrecord) я считал коды -  тип NEC длина 32 значение 551063. Пытаюсь уместить всё в один файл без библиотеки выдернул вроде всё но есть ошибки, сделал так:

#define NEC_HDR_MARK  9000
#define NEC_HDR_SPACE 4500
#define NEC_BIT_MARK  560
#define NEC_ONE_SPACE 1600
#define NEC_ZERO_SPACE  560
#define NEC_RPT_SPACE 2250
#define TIMER_PWM_PIN        3
#include <WProgram.h>
//#include <Arduino.h>

#define SYSCLOCK F_CPU 

// IR detector output is active low
#define MARK  0
#define SPACE 1
#define NEC_BITS 32

#define TIMER_CONFIG_KHZ(val) ({ \
  const uint16_t pwmval = SYSCLOCK / 2000 / (val); \
  TCCR5A = _BV(WGM51); \
  TCCR5B = _BV(WGM53) | _BV(CS50); \
  ICR5 = pwmval; \
  OCR5A = pwmval / 3; \
})

#define TIMER_ENABLE_PWM     (TCCR2A |= _BV(COM2B1))
#define TIMER_DISABLE_PWM    (TCCR2A &= ~(_BV(COM2B1)))

#define TOPBIT 0x80000000

#define TIMER_DISABLE_INTR   (TIMSK5 = 0)
/*
int COM2A = 00; //disconnect OC2A
int COM2B = 00; //disconnect OC2B; to send signal set to 10: OC2B non-inverted
int WGM2 = 101; //phase-correct PWM with OCRA as top
int CS2 = 000; //no prescaling*/

void mark(int time) {
  // Sends an IR mark for the specified number of microseconds.
  // The mark output is modulated at the PWM frequency.
  TIMER_ENABLE_PWM; // Enable pin 3 PWM output
  digitalWrite(TIMER_PWM_PIN, HIGH); 
  delayMicroseconds(time);
}

/* Leave pin off for time (given in microseconds) */
void space(int time) {
  // Sends an IR space for the specified number of microseconds.
  // A space is no output, so the PWM output is disabled.
  TIMER_DISABLE_PWM; // Disable pin 3 PWM output
  digitalWrite(TIMER_PWM_PIN, LOW); 
  delayMicroseconds(time);
}

void enableIROut(int khz) {
  // Enables IR output.  The khz value controls the modulation frequency in kilohertz.
  // The IR output will be on pin 3 (OC2B).
  // This routine is designed for 36-40KHz; if you use it for other values, it's up to you
  // to make sure it gives reasonable results.  (Watch out for overflow / underflow / rounding.)
  // TIMER2 is used in phase-correct PWM mode, with OCR2A controlling the frequency and OCR2B
  // controlling the duty cycle.
  // There is no prescaling, so the output frequency is 16MHz / (2 * OCR2A)
  // To turn the output on and off, we leave the PWM running, but connect and disconnect the output pin.
  // A few hours staring at the ATmega documentation and this will all make sense.
  // See my Secrets of Arduino PWM at http://arcfn.com/2009/07/secrets-of-arduino-pwm.html for details.

  
  // Disable the Timer2 Interrupt (which is used for receiving IR)
  TIMER_DISABLE_INTR; //Timer2 Overflow Interrupt
  
  pinMode(TIMER_PWM_PIN, OUTPUT);
  digitalWrite(TIMER_PWM_PIN, LOW); // When not sending PWM, we want it low
  
  // COM2A = 00: disconnect OC2A
  // COM2B = 00: disconnect OC2B; to send signal set to 10: OC2B non-inverted
  // WGM2 = 101: phase-correct PWM with OCRA as top
  // CS2 = 000: no prescaling
  // The top value for the timer.  The modulation frequency will be SYSCLOCK / 2 / OCR2A.
  TIMER_CONFIG_KHZ(khz);
}

void sendNEC(unsigned long data, int nbits)
{
  enableIROut(38);
  mark(NEC_HDR_MARK);
  space(NEC_HDR_SPACE);
  for (int i = 0; i < nbits; i++) {
    if (data & TOPBIT) {
      mark(NEC_BIT_MARK);
      space(NEC_ONE_SPACE);
    } 
    else {
      mark(NEC_BIT_MARK);
      space(NEC_ZERO_SPACE);
    }
    data <<= 1;
  }
  mark(NEC_BIT_MARK);
  space(0);
}
unsigned long codeValue; 
int codeLen;
void setup()
{
  //int codeType = 1; // The type of code
  unsigned long codeValue = 551063; // The code value if not raw
  int codeLen = 32; // The length of the code
  //int toggle = 0; // The RC5/6 toggle state
}

void loop() {
  sendNEC(codeValue, codeLen);
  delay(1000);
}

При компиляции появляются следующие ошибки:

IR_send_0023.cpp: In function 'void enableIROut(int)':
IR_send_0023:68: error: 'TIMSK5' was not declared in this scope
IR_send_0023:78: error: 'TCCR5A' was not declared in this scope
IR_send_0023:78: error: 'WGM51' was not declared in this scope
IR_send_0023:78: error: 'TCCR5B' was not declared in this scope
IR_send_0023:78: error: 'WGM53' was not declared in this scope
IR_send_0023:78: error: 'CS50' was not declared in this scope
IR_send_0023:78: error: 'ICR5' was not declared in this scope
IR_send_0023:78: error: 'OCR5A' was not declared in this scope

Я так понимаю это какие то константы которые для каждого типа контроллера разные. Подскажите как быть с этим? Цель такая - хочу уместить код в ATtiny85, можно ли это сделать?

xplp
Offline
Зарегистрирован: 21.12.2012

del

xplp
Offline
Зарегистрирован: 21.12.2012

del

xplp
Offline
Зарегистрирован: 21.12.2012

del

Клапауций
Offline
Зарегистрирован: 10.02.2013
xplp
Offline
Зарегистрирован: 21.12.2012

извиняюсь за кучу продублированных постов, сервер писал ошибка SMTP нельзя почту мол отправить =(

memfise
Offline
Зарегистрирован: 30.06.2012

.