IR Code on Attiny gives error

I am using this code

/*
 * IRrecord: record and play back IR signals as a minimal 
 * An IR detector/demodulator must be connected to the input RECV_PIN.
 * An IR LED must be connected to the output PWM pin 3.
 * A button must be connected to the input BUTTON_PIN; this is the
 * send button.
 * A visible LED can be connected to STATUS_PIN to provide status.
 *
 * The logic is:
 * If the button is pressed, send the IR code.
 * If an IR code is received, record it.
 *
 * Version 0.11 September, 2009
 * Copyright 2009 Ken Shirriff
 * http://arcfn.com
 */

#include <IRremote.h>

int RECV_PIN = 11;
int BUTTON_PIN = 12;
int STATUS_PIN = 13;

IRrecv irrecv(RECV_PIN);
IRsend irsend;

decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  pinMode(BUTTON_PIN, INPUT);
  pinMode(STATUS_PIN, OUTPUT);
}

// Storage for the recorded code
int codeType = -1; // The type of code
unsigned long codeValue; // The code value if not raw
unsigned int rawCodes[RAWBUF]; // The durations if raw
int codeLen; // The length of the code
int toggle = 0; // The RC5/6 toggle state

// Stores the code for later playback
// Most of this code is just logging
void storeCode(decode_results *results) {
  codeType = results->decode_type;
  int count = results->rawlen;
  if (codeType == UNKNOWN) {
    Serial.println("Received unknown code, saving as raw");
    codeLen = results->rawlen - 1;
    // To store raw codes:
    // Drop first value (gap)
    // Convert from ticks to microseconds
    // Tweak marks shorter, and spaces longer to cancel out IR receiver distortion
    for (int i = 1; i <= codeLen; i++) {
      if (i % 2) {
        // Mark
        rawCodes[i - 1] = results->rawbuf[i]*USECPERTICK - MARK_EXCESS;
        Serial.print(" m");
      } 
      else {
        // Space
        rawCodes[i - 1] = results->rawbuf[i]*USECPERTICK + MARK_EXCESS;
        Serial.print(" s");
      }
      Serial.print(rawCodes[i - 1], DEC);
    }
    Serial.println("");
  }
  else {
    if (codeType == NEC) {
      Serial.print("Received NEC: ");
      if (results->value == REPEAT) {
        // Don't record a NEC repeat value as that's useless.
        Serial.println("repeat; ignoring.");
        return;
      }
    } 
    else if (codeType == SONY) {
      Serial.print("Received SONY: ");
    } 
    else if (codeType == RC5) {
      Serial.print("Received RC5: ");
    } 
    else if (codeType == RC6) {
      Serial.print("Received RC6: ");
    } 
    else {
      Serial.print("Unexpected codeType ");
      Serial.print(codeType, DEC);
      Serial.println("");
    }
    Serial.println(results->value, HEX);
    codeValue = results->value;
    codeLen = results->bits;
  }
}

void sendCode(int repeat) {
  if (codeType == NEC) {
    if (repeat) {
      irsend.sendNEC(REPEAT, codeLen);
      Serial.println("Sent NEC repeat");
    } 
    else {
      irsend.sendNEC(codeValue, codeLen);
      Serial.print("Sent NEC ");
      Serial.println(codeValue, HEX);
    }
  } 
  else if (codeType == SONY) {
    irsend.sendSony(codeValue, codeLen);
    Serial.print("Sent Sony ");
    Serial.println(codeValue, HEX);
  } 
  else if (codeType == RC5 || codeType == RC6) {
    if (!repeat) {
      // Flip the toggle bit for a new button press
      toggle = 1 - toggle;
    }
    // Put the toggle bit into the code to send
    codeValue = codeValue & ~(1 << (codeLen - 1));
    codeValue = codeValue | (toggle << (codeLen - 1));
    if (codeType == RC5) {
      Serial.print("Sent RC5 ");
      Serial.println(codeValue, HEX);
      irsend.sendRC5(codeValue, codeLen);
    } 
    else {
      irsend.sendRC6(codeValue, codeLen);
      Serial.print("Sent RC6 ");
      Serial.println(codeValue, HEX);
    }
  } 
  else if (codeType == UNKNOWN /* i.e. raw */) {
    // Assume 38 KHz
    irsend.sendRaw(rawCodes, codeLen, 38);
    Serial.println("Sent raw");
  }
}

int lastButtonState;

void loop() {
  // If button pressed, send the code.
  int buttonState = digitalRead(BUTTON_PIN);
  if (lastButtonState == HIGH && buttonState == LOW) {
    Serial.println("Released");
    irrecv.enableIRIn(); // Re-enable receiver
  }

  if (buttonState) {
    Serial.println("Pressed, sending");
    digitalWrite(STATUS_PIN, HIGH);
    sendCode(lastButtonState == buttonState);
    digitalWrite(STATUS_PIN, LOW);
    delay(50); // Wait a bit between retransmissions
  } 
  else if (irrecv.decode(&results)) {
    digitalWrite(STATUS_PIN, HIGH);
    storeCode(&results);
    irrecv.resume(); // resume receiver
    digitalWrite(STATUS_PIN, LOW);
  }
  lastButtonState = buttonState;
}

from this tutorial
http://www.arcfn.com/2009/09/arduino-universal-remote-record-and.html to program an attiny85 to record and replay ir signals.

The program works fine on the atmega 328. I know I can program the attiny85 with arduino as ISP because I have successfully loaded multiple sketches onto it in this way. However, when I attempt to load the sketch to the attiny85 I get this error message:

IRrecord.cpp: In function ‘void setup()’:
IRrecord.cpp:36:3: error: ‘Serial’ was not declared in this scope
IRrecord.cpp: In function ‘void storeCode(decode_results*)’:
IRrecord.cpp:55:5: error: ‘Serial’ was not declared in this scope
IRrecord.cpp:72:37: error: ‘DEC’ was not declared in this scope
IRrecord.cpp:78:7: error: ‘Serial’ was not declared in this scope
IRrecord.cpp:86:7: error: ‘Serial’ was not declared in this scope
IRrecord.cpp:89:7: error: ‘Serial’ was not declared in this scope
IRrecord.cpp:92:7: error: ‘Serial’ was not declared in this scope
IRrecord.cpp:95:7: error: ‘Serial’ was not declared in this scope
IRrecord.cpp:96:30: error: ‘DEC’ was not declared in this scope
IRrecord.cpp:99:5: error: ‘Serial’ was not declared in this scope
IRrecord.cpp:99:36: error: ‘HEX’ was not declared in this scope
IRrecord.cpp: In function ‘void sendCode(int)’:
IRrecord.cpp:109:7: error: ‘Serial’ was not declared in this scope
IRrecord.cpp:113:7: error: ‘Serial’ was not declared in this scope
IRrecord.cpp:114:33: error: ‘HEX’ was not declared in this scope
IRrecord.cpp:119:5: error: ‘Serial’ was not declared in this scope
IRrecord.cpp:120:31: error: ‘HEX’ was not declared in this scope
IRrecord.cpp:131:7: error: ‘Serial’ was not declared in this scope
IRrecord.cpp:132:33: error: ‘HEX’ was not declared in this scope
IRrecord.cpp:137:7: error: ‘Serial’ was not declared in this scope
IRrecord.cpp:138:33: error: ‘HEX’ was not declared in this scope
IRrecord.cpp:144:5: error: ‘Serial’ was not declared in this scope
IRrecord.cpp: In function ‘void loop()’:
IRrecord.cpp:154:5: error: ‘Serial’ was not declared in this scope
IRrecord.cpp:159:5: error: ‘Serial’ was not declared in this scope

What is going wrong?

Thanks,

Will

Does the attiny85 have a hardware UART?

Just the raw attiny85 chip. My limited understanding was that UART refers to the hardware necessary to connect to the computer via USB. I am using the arduino's usb UART as i am using the arduino duemilanove as an ISP programmer to program the attiny85 on a breadboard.

A UART gives a hardware serial port. Another chip does serial to usb conversion. I don't think you can use hardware serial on an attiny85.

Yeah, attinys don't have hardware serial. Avrfreaks seems to have a soft serial solution, although I haven't tried it because I'm still waiting for my attiny in the mail. http://www.avrfreaks.net/index.php?module=Freaks%20Academy&func=viewItem&item_type=project&item_id=1895

This came up earlier today: http://arduino.cc/forum/index.php/topic,91125.0.html

Just a short-circuit link to the good bit... http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1285218245/25#25

Coding Badly and dxw00d,

How do I implement the solutions you link to into my code?

Thank you so much!

Will

Download the Tiny Core. Install the Tiny Core. Ensure your sketch compiles. Upload your sketch. Connect TTL-serial-to-USB converter (an Arduino or compatible board will work) to the ATtiny processor. Run your favourite terminal application.

Is it ok to use the tiny core you linked to for arduino version 1.0 if I have ardiuno 022 running? I can only get arduino as ISP running properly with 022.

Yes.

Ah ok. This was my confusion. I am using the arduino as an ISP. In the High-Low tech tutorial with their tiny core files there was a board selection for 'attiny85 with arduino as ISP' This new core wants me to program the attiny85 directly as I understand it. How do I do that?

http://code.google.com/p/arduino-tiny/source/browse/trunk/hardware/tiny/boards.txt#143

upload.using defines which programmer is used. Tiny Core is configured to use a board running ArduinoISP (arduino:arduinoisp).

Ok I installed the core files.

I uploaded the ISP sketch onto the arduino

I opened the blink example sketch

I selected the Attiny85 from the board menu

I attempt to compile the blink example sketch and get this error:

In file included from /usr/lib/gcc/avr/4.5.3/../../../avr/include/util/delay.h:44:0,
                 from /usr/lib/gcc/avr/4.5.3/../../../avr/include/avr/delay.h:37,
                 from /home/will/sketchbook/hardware/tiny/cores/tiny/wiring_private.h:32,
                 from /home/will/sketchbook/hardware/tiny/cores/tiny/WInterrupts.c:37:
/usr/lib/gcc/avr/4.5.3/../../../avr/include/math.h:426:15: error: expected identifier or ‘(’ before ‘double’
/usr/lib/gcc/avr/4.5.3/../../../avr/include/math.h:426:15: error: expected ‘)’ before ‘>=’ token

http://code.google.com/p/arduino-tiny/issues/detail?id=29&q=round

ok loading the blink sketch is working fine now. However still cannot load the IR code was originally trying to put on the attiny85. I get this compiler error:

/home/will/sketchbook/libraries/IRremote/IRremote.cpp: In member function ‘void IRsend::mark(int)’:
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:172:3: error: ‘TCCR2A’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:172:13: error: ‘COM2B1’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp: In member function ‘void IRsend::space(int)’:
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:180:3: error: ‘TCCR2A’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:180:15: error: ‘COM2B1’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp: In member function ‘void IRsend::enableIROut(int)’:
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:198:3: error: ‘TIMSK2’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:198:14: error: ‘TOIE2’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:207:3: error: ‘TCCR2A’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:207:12: error: ‘WGM20’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:208:3: error: ‘TCCR2B’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:208:12: error: ‘WGM22’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:208:25: error: ‘CS20’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:211:3: error: ‘OCR2A’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:212:3: error: ‘OCR2B’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp: In member function ‘void IRrecv::enableIRIn()’:
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:224:3: error: ‘TCCR2A’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:229:3: error: ‘TCCR2B’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:229:3: error: ‘CS22’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:230:3: error: ‘CS21’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:231:3: error: ‘CS20’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:234:3: error: ‘TIMSK2’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:234:3: error: ‘TOIE2’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:236:3: error: ‘TCNT2’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp: In function ‘void TIMER2_OVF_vect()’:
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:266:3: error: ‘TCNT2’ was not declared in this scope

The ATtiny85 processor does not have a timer 2. Timer 0 on the ATtiny85 is very similar to the even numbered timers (like timer 2) on ATmega processors. Changing the code to use timer 0 should work. You may even be able to make the change with a simple search-and-replace…

TCCR2A → TCCR0A
COM2B1 → COM0B1

I can find neither TCCR2A nor COM2B1 in the code or in the .h file it is referencing. I can however find these in the .cpp file in the folder with the code i downloaded. Changing just what you suggested gives me this error when running the code again:

/home/will/sketchbook/libraries/IRremote/IRremote.cpp: In member function ‘void IRsend::enableIROut(int)’:
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:198:3: error: ‘TIMSK2’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:198:14: error: ‘TOIE2’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:207:12: error: ‘WGM20’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:208:3: error: ‘TCCR2B’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:208:12: error: ‘WGM22’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:208:25: error: ‘CS20’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:211:3: error: ‘OCR2A’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:212:3: error: ‘OCR2B’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp: In member function ‘void IRrecv::enableIRIn()’:
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:229:3: error: ‘TCCR2B’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:229:3: error: ‘CS22’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:230:3: error: ‘CS21’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:231:3: error: ‘CS20’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:234:3: error: ‘TIMSK2’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:234:3: error: ‘TOIE2’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:236:3: error: ‘TCNT2’ was not declared in this scope
/home/will/sketchbook/libraries/IRremote/IRremote.cpp: In function ‘void TIMER2_OVF_vect()’:
/home/will/sketchbook/libraries/IRremote/IRremote.cpp:266:3: error: ‘TCNT2’ was not declared in this scope

the .cpp file is too large to post here but you can see it in this zip file: http://arcfn.com/files/IRremote.zip

Changing just what you suggested gives me this error when running the code again:

Those two items are examples. They are not a comprehensive listing. You will have to change all of the register and bit references from timer 2 to timer 0.