IRremote problem with ATTIny84

I have a code for ir receiving with #include <IRremote.h>.
Problem is, that IR block completete ATtiny.
I made "light" version of the code :

#include <IRremote.h>

const int relePin =  10;
const int led1Pin =  9;
const int led2Pin =  8;
const int rpiPin =  2;
const int irPin =  1;
const int eepromPin =  7;


int RECV_PIN = 1;
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
  irrecv.enableIRIn();
  pinMode(relePin, OUTPUT);                       
  pinMode(rpiPin, INPUT_PULLUP);             
  pinMode(irPin, INPUT_PULLUP);            
  pinMode(led2Pin, OUTPUT);         
  pinMode(led1Pin, OUTPUT);         
  pinMode(eepromPin, INPUT_PULLUP);  
 
  digitalWrite(relePin, LOW);
  digitalWrite(led2Pin, HIGH);       
  digitalWrite(led1Pin, HIGH);       
 }
  void loop() {
}

Problem is, that with this code after upload is led1PIN and led2PIN still OFF, but when I stop IR with :

//irrecv.enableIRIn();
then led1PIN and led2PIN is ON as expected.

So it looks like a problem with ATTiny84 and IRremote.h

Is there any solution ? What can be a problem ?
Thank you
Alda

What happens when you try a basic example: https://github.com/z3t0/Arduino-IRremote/blob/master/examples/IRrecvDemo/IRrecvDemo.ino.

Change the receive pin to match your hardware.

In your code, you reset the pinMode of pin 1 after the statement IRrecv irrecv(RECV_PIN); which is also using pin 1.

Example code isn't working, there is compile error "Serial" was not declared in this scope.

Only for better understanding:
I'm using arduino mini pro for ATtiny84/85 programming.

For ATtiny85 was all ok, but with ATtiny84 isn't working. So I did this light version of my code, to find what's a problem and found out, that problem is : irrecv.enableIRIn();

and I don't know what's a difference between ATTiny85 and ATTiny84 for library irremote.h - is necessary any modification ?

also this code isn't working :

#include <IRremote.h>

const int relePin =  10;
const int led1Pin =  9;
const int led2Pin =  8;
const int rpiPin =  2;
//const int irPin =  1;
const int eepromPin =  7;


int RECV_PIN = 1;
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
  irrecv.enableIRIn();
  pinMode(relePin, OUTPUT);                       
  pinMode(rpiPin, INPUT_PULLUP);             
  //pinMode(irPin, INPUT_PULLUP);            
  pinMode(led2Pin, OUTPUT);         
  pinMode(led1Pin, OUTPUT);         
  pinMode(eepromPin, INPUT_PULLUP);  
 
  digitalWrite(relePin, LOW);
  digitalWrite(led2Pin, HIGH);       
  digitalWrite(led1Pin, HIGH);       
 }
  void loop() {
}

So I overworked basic example :

#include <IRremote.h> 
#include <SoftwareSerial.h>
SoftwareSerial RFID(2, 3); // RX and TX

int RECV_PIN = 0; 
IRrecv irrecv(RECV_PIN); 
  
 decode_results results; 
  
 void setup() 
 { 
   RFID.begin(9600); 
   RFID.println("START");
   RFID.println("ENABLE");
  irrecv.enableIRIn(); // Start the receiver 
  RFID.println("ENABLE DONE");
 } 
  
 void loop() { 
  RFID.println("LOOP");
   if (irrecv.decode(&results)) {
    RFID.println("RESULT"); 
     RFID.println(results.value, HEX); 
     irrecv.resume(); // Receive the next value 
   } 
   delay(100); 
 }

But on the serial monitor no messages.

You have to specify the correct processor. An ATtiny84 is handled differently to an ATtiny85 by the IR library. See: GitHub - Arduino-IRremote/Arduino-IRremote: Infrared remote library for Arduino: send and receive infrared signals with multiple protocols (timer and send pin).

You've said you are using an Arduino Pro Mini to program the the ATtiny84, but a Pro Mini has no USB interface so how are you connecting it to the PC so you can use the serial monitor against the ATtiny84 ?

I downloaded latest IRremote library and make this code :

#include <IRremote.h> 

const int led1Pin =  9;
int RECV_PIN = 1; 
IRrecv irrecv(RECV_PIN); 
decode_results results; 
  
 void setup() 
 { 
  pinMode(led1Pin, OUTPUT);
  delay(4000);
  digitalWrite(led1Pin, HIGH); 
  delay(1000);
  digitalWrite(led1Pin, LOW);

  irrecv.enableIRIn(); // Start the receiver 

  delay(4000);
  digitalWrite(led1Pin, HIGH); 
  delay(1000);
  digitalWrite(led1Pin, LOW);

 } 
   void loop() { 
   if (irrecv.decode(&results)) {
    digitalWrite(led1Pin, HIGH);
    delay(1000); 
    digitalWrite(led1Pin, LOW);
    irrecv.resume(); // Receive the next value 
   } 
   delay(1000); 
 }

When this code is uploaded, I can see first LED blink, but not second one.
So it's sure that program will stop with: irrecv.enableIRIn(); // Start the receiver

So what I must modify in IRremote library to get it working on the ATTiny84?

Thank you for help

Alex

I made complete other code without IRremote library :

#include <SoftwareSerial.h>
SoftwareSerial RFID(2, 3); // RX and TX

// Pins 2/3 used for Software serial
int irPin     = 1;       //Sensor pin 1 wired to Arduino's pin D4
int statLED   = 9;       //Toggle the status LED every time Power is pressed
int start_bit = 2200;    //Start bit threshold (Microseconds)
int bin_1     = 1000;    //Binary 1 threshold (Microseconds)
int bin_0     = 400;     //Binary 0 threshold (Microseconds)

void setup() {
  pinMode(statLED, OUTPUT);
  digitalWrite(statLED, LOW);
  pinMode(irPin, INPUT);
  RFID.begin(9600);
  RFID.println("IR/Serial Initialized: ");
}

void loop() {
    RFID.println("Loop ");
    int key = getIRKey();   //Fetch the key
    RFID.println("key:");
    RFID.println(key);
  if(key != 0)            //Ignore keys that are zero
  {
    switch(key)
    {
      case 128: RFID.print("1"); break;
      case 129: RFID.print("2"); break;
      case 130: RFID.print("3"); break;
      case 131: RFID.print("4"); break;
      case 132: RFID.print("5"); break;
      case 133: RFID.print("6"); break;
      case 134: RFID.print("7"); break;
      case 135: RFID.print("8"); break;
      case 136: RFID.print("9"); break;
      case 137: RFID.print("0"); break;
      
      case 144: RFID.print("A"); break;  // CH Up
      case 145: RFID.print("B"); break;  // CH Down
      case 146: RFID.print("C"); break;  // VOL Right
      case 147: RFID.print("D"); break;  // VOL Left
      case 148: RFID.print("E"); break;  // Mute
      case 165: RFID.print("F"); break;  // AV/TV
      case 149: RFID.print("P");         // Power == MENU ACTIVE
        //This toggles the statLED every time power button is hit
        if(digitalRead(statLED) != 1)
          digitalWrite(statLED, HIGH);
        else
          digitalWrite(statLED, LOW);
        break;

      //default: Serial.println(key); // for inspection of keycode
    }
    delay(400);    // avoid double key logging (adjustable)
  }
}

int getIRKey() {
  int data[12];
  int i;

  while(pulseIn(irPin, LOW) < start_bit); //Wait for a start bit
  RFID.println("start bit");
  for(i = 0 ; i < 11 ; i++)
    data[i] = pulseIn(irPin, LOW);      //Start measuring bits, I only want low pulses
  
  for(i = 0 ; i < 11 ; i++)             //Parse them
  {      
    if(data[i] > bin_1)                 //is it a 1?
      data[i] = 1;
    else if(data[i] > bin_0)            //is it a 0?
      data[i] = 0;
    else
      return -1;                        //Flag the data as invalid; I don't know what it is! Return -1 on invalid data
  }

  int result = 0;
  for(i = 0 ; i < 11 ; i++)             //Convert data bits to integer
    if(data[i] == 1) result |= (1<<i);

  return result;                        //Return key number
}

When I press a button, sw will return a key (so he is receiving), but the key is still zero. How to adjust ?
Maybe it's better way how to receive IR and without IRremote library.

  1. RFID is an extremely odd name for an IR detector. Can you post a link to the device you are trying to integrate with your ATTINY84
SoftwareSerial RFID(2, 3); // RX and TX
  1. You have said that have an Arduino Pro Mini available. Why not try getting your code and detector working there first, then try later with the ATtiny84 ? Also, it is still not clear how you have connected all up to your PC.

  2. Can you edit your previous posts to add code tags around the code that you have posted. It makes it easier to read and it is not misinterpreted as formatting characters.

  1. I have a power supply which I'm already starting with IR remote with ATtiny85. And it's working.
    I took same code (only pin connection change) and tried upload to ATTiny84, because I need more pins for Led. But it isn't working. That's why I'm asking.

  2. I have a functional version with ATTiny85.

3: I will do

What I need : On the pin1 (arduino number) of the ATTiny84 receive signal from IR receiver TSOP4838. That's all. For ATTiny85 it was working for first time with IRremote library, but same code with same library isn't working with ATTiny84. So now I'm trying new and new codes to find what's a problem. Or is necessary change something inside IRremote library ?

OK. You have a working solution with the ATtiny85. You are trying to migrate it to an ATtiny84.

Are you using this version of the IRremote library? : GitHub - Arduino-IRremote/Arduino-IRremote: Infrared remote library for Arduino: send and receive infrared signals with multiple protocols

It appears to have code in the file boarddefs.h which handles the ATtiny85 and ATtiny84 differently:

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

//ATtiny85
#elif defined(__AVR_ATtiny85__)
#define IR_USE_TIMER_TINY0 // tx = pin 1

It should handle the difference automatically if you declared the correct boards type in the Arduino IDE.
Are there any other differences (clock rate etc.) ?

Yes, I changed adruino IDE setup from ATTiny85 8Mhz internal to ATTiny84 8Mhz internal.
I tried IRremote library 2.0.1; 2.0.2; and 2.1.0. All the same result, compilation is ok, but code which is after: irrecv.enableIRIn(); isn't working. All hangs on it.

That's why I started searching for solution without this IRremote library (code with getIrKey ).

Just to try, my next step to isolate the problem would be to force the use of the 8 bit timer 0 on the ATtiny84 (which you are apparently using successfully on the ATtiny85) by making the following change to the file boarddefs.h :

// ATtiny84
#elif defined(AVR_ATtiny84)
#define IR_USE_TIMER_TINY0 // tx = pin 6 was IR_USE_TIMER1

I haven't looked at the data sheets in detail so I can't promise it will work. If it doesn't compile, give up this test. Any anyway, even if it does work, you should investigate why.

See this, including the comment dated 28. Aug 2016. Apparently, ATtiny85 support came late to this library. ATtiny84 may not be there yet.

The only suggestion I can make if you don't get any further is to move to an ATmega328p chip where support is more or less guaranteed.

Solution with timer change doesn't work. Error during compilation :

C:\libraries\IRremote\IRremoteInt.h:568:31: error: 'TIMSK' was not declared in this scope

#define TIMER_ENABLE_INTR (TIMSK |= _BV(OCIE0A))

^

C:\libraries\IRremote\irRecv.cpp:123:2: note: in expansion of macro 'TIMER_ENABLE_INTR'

Maybe other solution is use function pulsein - it is sending data back, but no difference when I press different keys on IR remote.
I also can't use other (ATmega328) bigger chips.

The version of IRremoteInt.h on the GitHub version of the library here: GitHub - Arduino-IRremote/Arduino-IRremote: Infrared remote library for Arduino: send and receive infrared signals with multiple protocols does not have any reference to TIMSK so I guess you are using an old version.
However, anyway, that was only guess at how to proceed.

I can't comment on the chances of using pulseIn to achieve the same thing, but wish you success if you go down that route.

ok,
I downloaded last version a did a test again, but still a error :

In file included from C:\Arduino\libraries\Arduino-IRremote-master\IRremoteInt.h:111:0,

from C:\Arduino\libraries\Arduino-IRremote-master\IRremote.h:24,

from C:\Arduino\libraries\Arduino-IRremote-master\irRecv.cpp:1:

C:\Arduino\libraries\Arduino-IRremote-master\irRecv.cpp: In member function 'void IRrecv::enableIRIn()':

C:\Arduino\libraries\Arduino-IRremote-master\boarddefs.h:514:31: error: 'TIMSK' was not declared in this scope

#define TIMER_ENABLE_INTR (TIMSK |= _BV(OCIE0A))

^

C:\Arduino\libraries\Arduino-IRremote-master\irRecv.cpp:128:2: note: in expansion of macro 'TIMER_ENABLE_INTR'

TIMER_ENABLE_INTR;

^

exit status 1

now in boarddefs.h I have :
// ATtiny84
#elif defined(AVR_ATtiny84)
//#define IR_USE_TIMER1 // tx = pin 6
#define IR_USE_TIMER_TINY0 // tx = pin 6 was IR_USE_TIMER1

and simple code which I'm using to test it :

#include <IRremote.h> 

const int led1Pin =  9;
int RECV_PIN = 8; 
IRrecv irrecv(RECV_PIN); 
decode_results results; 
  
 void setup() 
 { 
  pinMode(led1Pin, OUTPUT);
  digitalWrite(led1Pin, LOW);
  irrecv.enableIRIn(); // Start the receiver 
  delay(4000);
  digitalWrite(led1Pin, HIGH); 
  delay(1000);
  digitalWrite(led1Pin, LOW);

 } 
   void loop() { 
   if (irrecv.decode(&results)) {
    digitalWrite(led1Pin, HIGH);
    delay(1000); 
    digitalWrite(led1Pin, LOW);
    irrecv.resume(); // Receive the next value 
   } 
   delay(1000); 
 }

So I did next test and found, if I will change in IRremote library the file irRecv.cpp :

//+=============================================================================
// initialization
//
void  IRrecv::enableIRIn ( )
{
	cli();
	// Setup pulse clock timer interrupt
	// Prescale /8 (16M/8 = 0.5 microseconds per tick)
	// Therefore, the timer interval can range from 0.5 to 128 microseconds
	// Depending on the reset value (255 to 0)
	TIMER_CONFIG_NORMAL();

	// Timer2 Overflow Interrupt Enable
	TIMER_ENABLE_INTR;

	TIMER_RESET;

	sei();  // enable interrupts

	// Initialize state machine variables
	irparams.rcvstate = STATE_IDLE;
	irparams.rawlen = 0;

	// Set pin modes
	pinMode(irparams.recvpin, INPUT);
}

And change TIMER_ENABLE_INTR;
to TIMER_DISABLE_INTR;

then uploaded code will not stop on the irrecv.enableIRIn();
but receiving isn't working.

SOLVED !!!!!!!

There is a bug in IRremote library for ATTiny84.
In the boaddefs.h under Timer1 is :

#define TIMER_INTR_NAME TIMER1_COMPA_vect

But for ATTiny84 must be :

#define TIMER_INTR_NAME TIM1_COMPA_vect

after this change all is working.

Hope will help more users

Alex

Well done ! That was a marathon. I guess it would be good to post the entire boarddefs.h here so the solution is obvious to anyone searching.

Just out interest, the chip is an ATtiny84, i.e. not a ATtiny84A ?

It's ATTiny84.
Attached is modified boarddefs.h which can be used for ATTiny84 and also for rest.

Alex

boarddefs.h (17.6 KB)

I downloaded the modified boarddefs.h, but still not responding
Iam using ATtiny84A