attiny 2313 and the IRremote.h library

hello i’ve tried to upload this code to an attiny2313 @8mhz internal clock.

#include <IRremote.h>

const int pin=3;
const int led=9;
int toggle=0;
IRrecv irrecv(pin);
decode_results results;

void setup() {
irrecv.enableIRIn();
pinMode(led,OUTPUT);

}

void loop() {
if(irrecv.decode(&results)){
if(results.value==0x1000C||0xC||0x17AB7F3E){
if(toggle==0){
digitalWrite(led,HIGH);
toggle=1;
}
else{
digitalWrite(led,LOW);
toggle=0;
}
}
irrecv.resume();
}

}

pretty simple really, just trying something.

it will give me a lot of errors in the verbose, they’re so many that i think is rude to post them all, but i can do if needed. but the errors look mostly like this.

G:\arduino\libraries\IRremote\boarddefs.h:217:29: error: ‘WGM22’ was not declared in this scope

TCCR2B = _BV(WGM22) | _BV(CS20); \

^

G:\arduino\libraries\IRremote\irSend.cpp:119:2: note: in expansion of macro ‘TIMER_CONFIG_KHZ’

TIMER_CONFIG_KHZ(khz);

^

G:\arduino\libraries\IRremote\boarddefs.h:217:42: error: ‘CS20’ was not declared in this scope

TCCR2B = _BV(WGM22) | _BV(CS20); \

^

G:\arduino\libraries\IRremote\irSend.cpp:119:2: note: in expansion of macro ‘TIMER_CONFIG_KHZ’

TIMER_CONFIG_KHZ(khz);

^

In file included from G:\arduino\libraries\IRremote\IRremoteInt.h:111:0,

from G:\arduino\libraries\IRremote\IRremote.h:24,

from G:\arduino\libraries\IRremote\irSend.cpp:1:

G:\arduino\libraries\IRremote\boarddefs.h:218:2: error: ‘OCR2A’ was not declared in this scope

OCR2A = pwmval; \

^

G:\arduino\libraries\IRremote\irSend.cpp:119:2: note: in expansion of macro ‘TIMER_CONFIG_KHZ’

TIMER_CONFIG_KHZ(khz);

^

G:\arduino\libraries\IRremote\boarddefs.h:219:2: error: ‘OCR2B’ was not declared in this scope

OCR2B = pwmval / 3; \

^

G:\arduino\libraries\IRremote\irSend.cpp:119:2: note: in expansion of macro ‘TIMER_CONFIG_KHZ’

TIMER_CONFIG_KHZ(khz);

^

i have the feeling that the attiny is not compatible with the library.

That would be correct.

To boarddefs.h, change:

#elif defined(__AVR_ATtiny84__)
    #define IR_USE_TIMER1     // tx = pin 6

to

#elif defined(__AVR_ATtiny84__)||defined(__AVR_ATtiny2313__)||defined(__AVR_ATtiny4313__)
    #define IR_USE_TIMER1

and it should work, assuming it fits in 2k of flash, which it might not.