0

I'm using the IR Remote library with an attiny45 chip. The codes works fine with an Arduino but getting error message when uploading to attiny45 chip.

#include <IRremote.h>

int RECV_PIN = 2;
int led = 1;
int relay = 0;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  irrecv.enableIRIn(); // Start the receiver
  pinMode (led, OUTPUT);
  pinMode (relay, OUTPUT);
}

void loop() {
  if (irrecv.decode(&results)) {

    switch (results.value) {
      case 0xff02fd :
        digitalWrite(led, HIGH);
        digitalWrite(relay, LOW);
        break;

        case 0x1FC42BD :
        digitalWrite(led, HIGH);
        digitalWrite(relay, LOW);
        break;

      default :
        digitalWrite(led, LOW);
        digitalWrite(relay, HIGH);
        break;
    }

    irrecv.resume(); // Receive the next value
  }
}

When uploading, i'm getting the following error messages : Arduino: 1.8.1 (Windows 7), Board: "ATtiny25/45/85, ATtiny45, Internal 8 MHz"

C:\Users\Acer\Documents\Arduino\libraries\IRremote\IRremote.cpp: In member function 'void IRsend::mark(int)':

C:\Users\Acer\Documents\Arduino\libraries\IRremote\IRremote.cpp:176:3: error: 'TCCR2A' was not declared in this scope

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

   ^

In file included from c:\program files (x86)\arduino\hardware\tools\avr\avr\include\avr\io.h:99:0,

                 from c:\program files (x86)\arduino\hardware\tools\avr\avr\include\avr\pgmspace.h:90,

                 from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:28,

                 from C:\Users\Acer\Documents\Arduino\libraries\IRremote\IRremoteInt.h:15,

                 from C:\Users\Acer\Documents\Arduino\libraries\IRremote\IRremote.cpp:13:

C:\Users\Acer\Documents\Arduino\libraries\IRremote\IRremote.cpp:176:17: error: 'COM2B1' was not declared in this scope

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

                 ^

C:\Users\Acer\Documents\Arduino\libraries\IRremote\IRremote.cpp: In member function 'void IRsend::space(int)':

C:\Users\Acer\Documents\Arduino\libraries\IRremote\IRremote.cpp:188:3: error: 'TCCR2A' was not declared in this scope

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

   ^

In file included from c:\program files (x86)\arduino\hardware\tools\avr\avr\include\avr\io.h:99:0,

                 from c:\program files (x86)\arduino\hardware\tools\avr\avr\include\avr\pgmspace.h:90,

                 from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:28,

                 from C:\Users\Acer\Documents\Arduino\libraries\IRremote\IRremoteInt.h:15,

                 from C:\Users\Acer\Documents\Arduino\libraries\IRremote\IRremote.cpp:13:

C:\Users\Acer\Documents\Arduino\libraries\IRremote\IRremote.cpp:188:19: error: 'COM2B1' was not declared in this scope

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

                   ^

C:\Users\Acer\Documents\Arduino\libraries\IRremote\IRremote.cpp: In member function 'void IRsend::enableIROut(int)':

C:\Users\Acer\Documents\Arduino\libraries\IRremote\IRremote.cpp:210:3: error: 'TIMSK2' was not declared in this scope

   TIMSK2 &= ~_BV(TOIE2); //Timer2 Overflow Interrupt

   ^

In file included from c:\program files (x86)\arduino\hardware\tools\avr\avr\include\avr\io.h:99:0,

                 from c:\program files (x86)\arduino\hardware\tools\avr\avr\include\avr\pgmspace.h:90,

                 from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:28,

                 from C:\Users\Acer\Documents\Arduino\libraries\IRremote\IRremoteInt.h:15,

                 from C:\Users\Acer\Documents\Arduino\libraries\IRremote\IRremote.cpp:13:

C:\Users\Acer\Documents\Arduino\libraries\IRremote\IRremote.cpp:210:18: error: 'TOIE2' was not declared in this scope

   TIMSK2 &= ~_BV(TOIE2); //Timer2 Overflow Interrupt

                  ^

C:\Users\Acer\Documents\Arduino\libraries\IRremote\IRremote.cpp:228:3: error: 'TCCR2A' was not declared in this scope

   TCCR2A = _BV(WGM20);

   ^

In file included from c:\program files (x86)\arduino\hardware\tools\avr\avr\include\avr\io.h:99:0,

                 from c:\program files (x86)\arduino\hardware\tools\avr\avr\include\avr\pgmspace.h:90,

                 from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:28,

                 from C:\Users\Acer\Documents\Arduino\libraries\IRremote\IRremoteInt.h:15,

                 from C:\Users\Acer\Documents\Arduino\libraries\IRremote\IRremote.cpp:13:

C:\Users\Acer\Documents\Arduino\libraries\IRremote\IRremote.cpp:228:16: error: 'WGM20' was not declared in this scope

   TCCR2A = _BV(WGM20);

                ^

C:\Users\Acer\Documents\Arduino\libraries\IRremote\IRremote.cpp:229:3: error: 'TCCR2B' was not declared in this scope

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

   ^

In file included from c:\program files (x86)\arduino\hardware\tools\avr\avr\include\avr\io.h:99:0,

                 from c:\program files (x86)\arduino\hardware\tools\avr\avr\include\avr\pgmspace.h:90,

                 from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:28,

                 from C:\Users\Acer\Documents\Arduino\libraries\IRremote\IRremoteInt.h:15,

                 from C:\Users\Acer\Documents\Arduino\libraries\IRremote\IRremote.cpp:13:

C:\Users\Acer\Documents\Arduino\libraries\IRremote\IRremote.cpp:229:16: error: 'WGM22' was not declared in this scope

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

                ^

C:\Users\Acer\Documents\Arduino\libraries\IRremote\IRremote.cpp:229:29: error: 'CS20' was not declared in this scope

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

                             ^

C:\Users\Acer\Documents\Arduino\libraries\IRremote\IRremote.cpp:232:3: error: 'OCR2A' was not declared in this scope

   OCR2A = SYSCLOCK / 2 / khz / 1000;

   ^

C:\Users\Acer\Documents\Arduino\libraries\IRremote\IRremote.cpp:233:3: error: 'OCR2B' was not declared in this scope

   OCR2B = OCR2A / 3; // 33% duty cycle

   ^

C:\Users\Acer\Documents\Arduino\libraries\IRremote\IRremote.cpp: In member function 'void IRrecv::enableIRIn()':

C:\Users\Acer\Documents\Arduino\libraries\IRremote\IRremote.cpp:262:3: error: 'TCCR2A' was not declared in this scope

   TCCR2A = 0;  // normal mode

   ^

In file included from c:\program files (x86)\arduino\hardware\tools\avr\avr\include\avr\io.h:99:0,

                 from c:\program files (x86)\arduino\hardware\tools\avr\avr\include\avr\pgmspace.h:90,

                 from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:28,

                 from C:\Users\Acer\Documents\Arduino\libraries\IRremote\IRremoteInt.h:15,

                 from C:\Users\Acer\Documents\Arduino\libraries\IRremote\IRremote.cpp:13:

C:\Users\Acer\Documents\Arduino\libraries\IRremote\IRremote.cpp:267:7: error: 'TCCR2B' was not declared in this scope

   cbi(TCCR2B,CS22);

       ^

C:\Users\Acer\Documents\Arduino\libraries\IRremote\IRremote.cpp:267:3: note: in expansion of macro 'cbi'

   cbi(TCCR2B,CS22);

   ^

Multiple libraries were found for "IRremote.h"
C:\Users\Acer\Documents\Arduino\libraries\IRremote\IRremote.cpp:267:14: error: 'CS22' was not declared in this scope

 Used: C:\Users\Acer\Documents\Arduino\libraries\IRremote
   cbi(TCCR2B,CS22);

 Not used: C:\Users\Acer\Documents\Arduino\libraries\IRremote1
              ^

 Not used: C:\Users\Acer\Documents\Arduino\libraries\Arduino-IRremote-master
C:\Users\Acer\Documents\Arduino\libraries\IRremote\IRremote.cpp:267:3: note: in expansion of macro 'cbi'

   cbi(TCCR2B,CS22);

   ^

C:\Users\Acer\Documents\Arduino\libraries\IRremote\IRremote.cpp:268:14: error: 'CS21' was not declared in this scope

   sbi(TCCR2B,CS21);

              ^

C:\Users\Acer\Documents\Arduino\libraries\IRremote\IRremote.cpp:268:3: note: in expansion of macro 'sbi'

   sbi(TCCR2B,CS21);

   ^

C:\Users\Acer\Documents\Arduino\libraries\IRremote\IRremote.cpp:269:14: error: 'CS20' was not declared in this scope

   cbi(TCCR2B,CS20);

              ^

C:\Users\Acer\Documents\Arduino\libraries\IRremote\IRremote.cpp:269:3: note: in expansion of macro 'cbi'

   cbi(TCCR2B,CS20);

   ^

C:\Users\Acer\Documents\Arduino\libraries\IRremote\IRremote.cpp:272:7: error: 'TIMSK2' was not declared in this scope

   sbi(TIMSK2,TOIE2);

       ^

C:\Users\Acer\Documents\Arduino\libraries\IRremote\IRremote.cpp:272:3: note: in expansion of macro 'sbi'

   sbi(TIMSK2,TOIE2);

   ^

C:\Users\Acer\Documents\Arduino\libraries\IRremote\IRremote.cpp:272:14: error: 'TOIE2' was not declared in this scope

   sbi(TIMSK2,TOIE2);

              ^

C:\Users\Acer\Documents\Arduino\libraries\IRremote\IRremote.cpp:272:3: note: in expansion of macro 'sbi'

   sbi(TIMSK2,TOIE2);

   ^

In file included from C:\Users\Acer\Documents\Arduino\libraries\IRremote\IRremote.cpp:13:0:

C:\Users\Acer\Documents\Arduino\libraries\IRremote\IRremoteInt.h:46:24: error: 'TCNT2' was not declared in this scope

   #define RESET_TIMER2 TCNT2 = INIT_TIMER_COUNT2

                        ^

C:\Users\Acer\Documents\Arduino\libraries\IRremote\IRremote.cpp:278:3: note: in expansion of macro 'RESET_TIMER2'

   RESET_TIMER2;

   ^

C:\Users\Acer\Documents\Arduino\libraries\IRremote\IRremote.cpp: In function 'void __vector_5()':

C:\Users\Acer\Documents\Arduino\libraries\IRremote\IRremoteInt.h:46:24: error: 'TCNT2' was not declared in this scope

   #define RESET_TIMER2 TCNT2 = INIT_TIMER_COUNT2

                        ^

C:\Users\Acer\Documents\Arduino\libraries\IRremote\IRremote.cpp:308:3: note: in expansion of macro 'RESET_TIMER2'

   RESET_TIMER2;

   ^

exit status 1
Error compiling for board ATtiny25/45/85.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

This is the version of Arduino that i'm using : Arduino: 1.8.1 (Windows 7), Board: "ATtiny25/45/85, ATtiny45, Internal 8 MHz"

Shaam
  • 92
  • 13
  • You probably can't use pin 3 (the _BV(bit) macro) because IRremote library uses Timer 2 in a mode that only works with output on Arduino Pin 3. Take a look on this Instructable: http://www.instructables.com/id/Attiny-IR-library/?ALLSTEPS – Philip Feb 04 '17 at 10:14
  • Pin 3 means which pin on the attiny please? – Shaam Feb 04 '17 at 10:37
  • Yes it's Pin 3 on Arduino UNO and it's hardcoded. – Philip Feb 04 '17 at 11:00
  • I'm not using pin 3 on the Arduino Uno, the code I uploaded is the Attiny45. On the Arduino Uno, i'm using the pin 9 – Shaam Feb 04 '17 at 11:07

1 Answers1

0

I am pretty sure this has problem has to be the fact when downloading to an attiny45 or any Arduino-like-chip you need to reset the chip as code is being downloaded. The reset pin is pin 1. To reset it you should ground the pin. Here is the pinout diagram for reference.

Will Buxton
  • 53
  • 1
  • 8