[SOLVED] Experiencing problems with Arduino IR Libraries

Hi Everyone!

I'm experiencing lot of problems with the Arduino IDE. I have tried loading several versions of the Arduino IDE, in order to make the IR Library work but nothing.

I'm using an Arduino DUE and the latest version of the Arduino IDE 1.6.5

I've tried with other different versions of the IDE: they're all able to compile the code, until the 1.0.5 version but, as we all know, they can't write into Arduino Due boards.

By looking on the internet I found out that the RobotIRremote library is making conflicts with the Arduino IR library, so I decided to remove it. It's a bit better but the ide isn't still able to compile the code; these are the errors I get everytime:

Arduino:1.6.5 (Windows 8.1), Scheda:"Arduino Due (Programming Port)"

NovaTag:27: error: 'IRsend' does not name a type
NovaTag.ino: In function 'void loop()':
NovaTag:46: error: 'irsend' was not declared in this scope
'IRsend' does not name a type

Pls I request you're help :frowning: I'm stuck in this problem :frowning:

Thank you, guys.

I'm stuck in this problem

With the code that you didn't post? I'm going to guess that your problem is on line 44525243626543.

Oh sorry… You’re right :smiley:

Here you are:

//LIBRERIE
#include <IRremote.h>

//DEFINE
#define codarma 0123456

//PIN
const int ricevitoreIR = 11;
const int grilletto = 2;

//VARIABILI GLOBALI
int vite = 10;
int caricatori = 5;
int colpi = 20;
int statogrilletto = 0;
int punti = 0;

//FUNZIONI
IRsend irsend;
IRrecv irrecv(ricevitoreIR);
decode_results codice;

void setup()
{
  Serial.begin(9600);  // apertura porta seriale @9600 baud
  irrecv.enableIRIn(); // abilitazione ricevitore IR
  pinMode(grilletto, INPUT); //abilitazione grilletto
  pinMode(13, OUTPUT); //led di stato
}

void loop() {
  
  statogrilletto = digitalRead(grilletto);
  
  if (statogrilletto == HIGH) {
    // sparo
    if(caricatori >=0){
      irsend.sendSony(codarma, 12);
      colpi = colpi - 1;
    } else {
      //ho terminato i caricatori, penalità punti e ricarica caricatori
      punti = punti - 100;
      caricatori = 5;
    }
    digitalWrite(13, HIGH);
  } else {
    // non sparo
    digitalWrite(13, LOW);
    if (irrecv.decode(&codice)) {
      Serial.println(codice.value, HEX);
      irrecv.resume(); // riceve il prossimo valore
    }
  }
}

Thank you :slight_smile:

There is a statement in the IRremote header file:

#ifdef SEND_SONY 
  void sendSony(unsigned long data, int nbits);

So, I added:

#define SEND_SONY

up with the other #define statements before the beginning of the IRrecv class.

After that, compiling for the Due, I get:

Sketch uses 4,482 bytes (13%) of program storage space. Maximum is 32,256 bytes.
Global variables use 430 bytes (20%) of dynamic memory, leaving 1,618 bytes for local variables. Maximum is 2,048 bytes.

Hi Paul,

thanks for your fast answer. Unfortunately I’m not understanding how did you get it to work since by adding the #define SEND_SONY line into the sketch, it still outputs too many errors. Here is the code and the errors I got:

//LIBRERIE
#define SEND_SONY
#include <IRremote.h>

//DEFINE
#define codarma 0123456

//PIN
const int ricevitoreIR = 11;
const int grilletto = 2;

//VARIABILI GLOBALI
int vite = 10;
int caricatori = 5;
int colpi = 20;
int statogrilletto = 0;
int punti = 0;

//FUNZIONI
IRsend irsend;
IRrecv irrecv(ricevitoreIR);
decode_results codice;

void setup()
{
  Serial.begin(9600);  // apertura porta seriale @9600 baud
  irrecv.enableIRIn(); // abilitazione ricevitore IR
  pinMode(grilletto, INPUT); //abilitazione grilletto
  pinMode(13, OUTPUT); //led di stato
}

void loop() {
  
  statogrilletto = digitalRead(grilletto);
  
  if (statogrilletto == HIGH) {
    // sparo
    if(caricatori >=0){
      irsend.sendSony(codarma, 12);
      colpi = colpi - 1;
    } else {
      //ho terminato i caricatori, penalità punti e ricarica caricatori
      punti = punti - 100;
      caricatori = 5;
    }
    digitalWrite(13, HIGH);
  } else {
    // non sparo
    digitalWrite(13, LOW);
    if (irrecv.decode(&codice)) {
      Serial.println(codice.value, HEX);
      irrecv.resume(); // riceve il prossimo valore
    }
  }
}

Errors:

Arduino:1.6.5 (Windows 8.1), Scheda:"Arduino Due (Programming Port)"

C:\Program Files (x86)\Arduino\libraries\IRremote\irRecv.cpp: In member function 'void IRrecv::enableIRIn()':
C:\Program Files (x86)\Arduino\libraries\IRremote\irRecv.cpp:115:6: error: 'cli' was not declared in this scope
  cli();
      ^
In file included from C:\Program Files (x86)\Arduino\libraries\IRremote\IRremote.h:24:0,
                 from C:\Program Files (x86)\Arduino\libraries\IRremote\irRecv.cpp:1:
C:\Program Files (x86)\Arduino\libraries\IRremote\IRremoteInt.h:246:3: error: 'TCCR2A' was not declared in this scope
   TCCR2A = _BV(WGM21); \
   ^
C:\Program Files (x86)\Arduino\libraries\IRremote\irRecv.cpp:120:2: note: in expansion of macro 'TIMER_CONFIG_NORMAL'
  TIMER_CONFIG_NORMAL();
  ^
C:\Program Files (x86)\Arduino\libraries\IRremote\IRremoteInt.h:246:16: error: 'WGM21' was not declared in this scope
   TCCR2A = _BV(WGM21); \
                ^
C:\Program Files (x86)\Arduino\libraries\IRremote\irRecv.cpp:120:2: note: in expansion of macro 'TIMER_CONFIG_NORMAL'
  TIMER_CONFIG_NORMAL();
  ^
C:\Program Files (x86)\Arduino\libraries\IRremote\IRremoteInt.h:246:21: error: '_BV' was not declared in this scope
   TCCR2A = _BV(WGM21); \
                     ^
C:\Program Files (x86)\Arduino\libraries\IRremote\irRecv.cpp:120:2: note: in expansion of macro 'TIMER_CONFIG_NORMAL'
  TIMER_CONFIG_NORMAL();
  ^
C:\Program Files (x86)\Arduino\libraries\IRremote\IRremoteInt.h:247:3: error: 'TCCR2B' was not declared in this scope
   TCCR2B = _BV(CS21); \
   ^
C:\Program Files (x86)\Arduino\libraries\IRremote\irRecv.cpp:120:2: note: in expansion of macro 'TIMER_CONFIG_NORMAL'
  TIMER_CONFIG_NORMAL();
  ^
C:\Program Files (x86)\Arduino\libraries\IRremote\IRremoteInt.h:247:16: error: 'CS21' was not declared in this scope
   TCCR2B = _BV(CS21); \
                ^
C:\Program Files (x86)\Arduino\libraries\IRremote\irRecv.cpp:120:2: note: in expansion of macro 'TIMER_CONFIG_NORMAL'
  TIMER_CONFIG_NORMAL();
  ^
C:\Program Files (x86)\Arduino\libraries\IRremote\IRremoteInt.h:248:3: error: 'OCR2A' was not declared in this scope
   OCR2A  = TIMER_COUNT_TOP / 8; \
   ^
C:\Program Files (x86)\Arduino\libraries\IRremote\irRecv.cpp:120:2: note: in expansion of macro 'TIMER_CONFIG_NORMAL'
  TIMER_CONFIG_NORMAL();
  ^
C:\Program Files (x86)\Arduino\libraries\IRremote\IRremoteInt.h:249:3: error: 'TCNT2' was not declared in this scope
   TCNT2  = 0; \
   ^
C:\Program Files (x86)\Arduino\libraries\IRremote\irRecv.cpp:120:2: note: in expansion of macro 'TIMER_CONFIG_NORMAL'
  TIMER_CONFIG_NORMAL();
  ^
C:\Program Files (x86)\Arduino\libraries\IRremote\IRremoteInt.h:222:30: error: 'TIMSK2' was not declared in this scope
 #define TIMER_ENABLE_INTR   (TIMSK2 = _BV(OCIE2A))
                              ^
C:\Program Files (x86)\Arduino\libraries\IRremote\irRecv.cpp:123:2: note: in expansion of macro 'TIMER_ENABLE_INTR'
  TIMER_ENABLE_INTR;
  ^
C:\Program Files (x86)\Arduino\libraries\IRremote\IRremoteInt.h:222:43: error: 'OCIE2A' was not declared in this scope
 #define TIMER_ENABLE_INTR   (TIMSK2 = _BV(OCIE2A))
                                           ^
C:\Program Files (x86)\Arduino\libraries\IRremote\irRecv.cpp:123:2: note: in expansion of macro 'TIMER_ENABLE_INTR'
  TIMER_ENABLE_INTR;
  ^
C:\Program Files (x86)\Arduino\libraries\IRremote\IRremoteInt.h:222:49: error: '_BV' was not declared in this scope
 #define TIMER_ENABLE_INTR   (TIMSK2 = _BV(OCIE2A))
                                                 ^
C:\Program Files (x86)\Arduino\libraries\IRremote\irRecv.cpp:123:2: note: in expansion of macro 'TIMER_ENABLE_INTR'
  TIMER_ENABLE_INTR;
  ^
C:\Program Files (x86)\Arduino\libraries\IRremote\irRecv.cpp:127:6: error: 'sei' was not declared in this scope
  sei();  // enable interrupts
      ^
Errore durante la compilazione

I think I’m missing something :frowning:

I think I'm missing something

You are. I added the #define SEND_SONY statement to the IRremote.h file.

Adding it to the sketch has no affect when the IRremote.cpp file is compiled, since that happens as a different compilation unit from the one that compiles the cpp file created from the sketch.

Thank you. After adding the #define SEND_SONY statement to the IRremote.h file it looks a bit better but still can't compile the code correctly.

Now the IDE outputs:

Arduino:1.6.5 (Windows 8.1), Scheda:"Arduino Due (Programming Port)"

In file included from prova.ino:2:0:
C:\Program Files (x86)\Arduino\libraries\IRremote/IRremote.h:275:16: error: #if with no expression
 #  if SEND_SONY
                ^
prova.ino: In function 'void loop()':
prova:38: error: 'class IRsend' has no member named 'sendSony'
'class IRsend' has no member named 'sendSony'

I've added the define in the library, now the file IRremote.h looks like this:

//******************************************************************************
// IRremote
// Version 2.0.1 June, 2015
// Copyright 2009 Ken Shirriff
// For details, see http://arcfn.com/2009/08/multi-protocol-infrared-remote-library.html
// Edited by Mitra to add new controller SANYO
//
// Interrupt code based on NECIRrcv by Joe Knapp
// http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1210243556
// Also influenced by http://zovirl.com/2008/11/12/building-a-universal-remote-with-an-arduino/
//
// JVC and Panasonic protocol added by Kristian Lauszus (Thanks to zenwheel and other people at the original blog post)
// LG added by Darryl Smith (based on the JVC protocol)
// Whynter A/C ARC-110WD added by Francesco Meschia
//******************************************************************************

#ifndef IRremote_h
#define IRremote_h

//------------------------------------------------------------------------------
// The ISR header contains several useful macros the user may wish to use
//
#include "IRremoteInt.h"

//------------------------------------------------------------------------------
// Supported IR protocols
// Each protocol you include costs memory and, during decode, costs time
// Disable (set to 0) all the protocols you do not need/want!
//
#define DECODE_RC5           1
#define SEND_RC5             1

#define DECODE_RC6           1
#define SEND_RC6             1

#define DECODE_NEC           1
#define SEND_NEC             1

#define DECODE_SONY          1
#define SEND_SONY            1

#define DECODE_PANASONIC     1
#define SEND_PANASONIC       1

#define DECODE_JVC           1
#define SEND_JVC             1

#define DECODE_SAMSUNG       1
#define SEND_SAMSUNG         1

#define DECODE_WHYNTER       1
#define SEND_WHYNTER         1

#define DECODE_AIWA_RC_T501  1
#define SEND_AIWA_RC_T501    1

#define DECODE_LG            1
#define SEND_LG              1 

#define DECODE_SANYO         1
#define SEND_SANYO           0 // NOT WRITTEN

#define DECODE_MITSUBISHI    1
#define SEND_MITSUBISHI      0 // NOT WRITTEN

#define DECODE_DISH          0 // NOT WRITTEN
#define SEND_DISH            1

#define DECODE_SHARP         0 // NOT WRITTEN
#define SEND_SHARP           1

#define DECODE_DENON         1
#define SEND_DENON           1

#define DECODE_PRONTO        0 // This function doe not logically make sense
#define SEND_PRONTO          1

//------------------------------------------------------------------------------
// When sending a Pronto code we request to send either the "once" code
//                                                   or the "repeat" code
// If the code requested does not exist we can request to fallback on the
// other code (the one we did not explicitly request)
//
// I would suggest that "fallback" will be the standard calling method
// The last paragraph on this page discusses the rationale of this idea:
//   http://www.remotecentral.com/features/irdisp2.htm
//
#define PRONTO_ONCE        false
#define PRONTO_REPEAT      true
#define PRONTO_FALLBACK    true
#define PRONTO_NOFALLBACK  false

//------------------------------------------------------------------------------
// An enumerated list of all supported formats
// You do NOT need to remove entries from this list when disabling protocols!
//
typedef
	enum {
		UNKNOWN      = -1,
		UNUSED       =  0,
		RC5,
		RC6,
		NEC,
		SONY,
		PANASONIC,
		JVC,
		SAMSUNG,
		WHYNTER,
		AIWA_RC_T501,
		LG,
		SANYO,
		MITSUBISHI,
		DISH,
		SHARP,
		DENON,
		PRONTO,
	}
decode_type_t;

//------------------------------------------------------------------------------
// Set DEBUG to 1 for lots of lovely debug output
//
#define DEBUG  0

//------------------------------------------------------------------------------
// Debug directives
//
#if DEBUG
#	define DBG_PRINT(...)    Serial.print(__VA_ARGS__)
#	define DBG_PRINTLN(...)  Serial.println(__VA_ARGS__)
#else
#	define DBG_PRINT(...)
#	define DBG_PRINTLN(...)
#endif

//------------------------------------------------------------------------------
// Mark & Space matching functions
//
int  MATCH       (int measured, int desired) ;
int  MATCH_MARK  (int measured_ticks, int desired_us) ;
int  MATCH_SPACE (int measured_ticks, int desired_us) ;

//------------------------------------------------------------------------------
// Results returned from the decoder
//
class decode_results
{
	public:
		decode_type_t          decode_type;  // UNKNOWN, NEC, SONY, RC5, ...
		unsigned int           address;      // Used by Panasonic & Sharp [16-bits]
		unsigned long          value;        // Decoded value [max 32-bits]
		int                    bits;         // Number of bits in decoded value
		volatile unsigned int  *rawbuf;      // Raw intervals in 50uS ticks
		int                    rawlen;       // Number of records in rawbuf
		int                    overflow;     // true iff IR raw code too long
};

//------------------------------------------------------------------------------
// Decoded value for NEC when a repeat code is received
//
#define SEND_SONY
#define REPEAT 0xFFFFFFFF

//------------------------------------------------------------------------------
// Main class for receiving IR
//
class IRrecv
{
	public:

BLABLABLA... it looks too long for this message so I've cut it here

Unfortunately I'm still not able to get it work :frowning: Pls help me one more time...

My version of the IRremote.h file does not have 276+ lines.

My version of the IRremote.h file does not have any #if SEND_SONY lines. It DOES have #ifdef SEND_SONY statements.

I think you need to dump your version of the IRremote library and start over.

Here is the solution:

actually it seems that the Arduino Due and other Arm Boards are not supported by the IRremote library.

In fact, by changing the board, the code compiles without errors.

It took me 3 days to understand this :o

I can’t seem to fix my code- I get more errors than solutions!!! Could somebody please help me???

#include <IRLibRecvPCI.h>
#include <IRLibRecv.h>
#include <IRLibCombo.h>
#include <IRLibHardware.h>
#include <IRLibProtocols.h>
#include <IRLibSAMD21.h>
#include <IRLibSAMD51.h>
#include <IRLibSendBase.h>
#include <IRLib_HashRaw.h>
#include <IRLib_P01_NEC.h>
#include <IRLib_P02_Sony.h>
#include <IRLib_P03_RC5.h>
#include <IRLib_P04_RC6.h>
#include <IRLib_P05_Panasonic_Old.h>
#include <IRLib_P06_JVC.h>
#include <IRLib_P07_NECx.h>
#include <IRLib_P08_Samsung36.h>
#include <IRLib_P09_GICable.h>
#include <IRLib_P10_DirecTV.h>
#include <IRLib_P11_RCMM.h>
#include <IRLib_P12_CYKM.h>
#include <IRLib_P99_Additional.h>
#include <IRLibFreq.h>
#include <IRLib2.h>
#include <IRLibAll.h>
#include <IRLibDecodeBase.h>
#include <IRLibGlobals.h>
#include <IRLibRecvBase.h>
#include <IRLibRecvLoop.h>

#define decode_results
#define receiver.resume

#include <Stepper.h>
#define STEPS 32

//IR receiver
int RECV_PIN = 1;
IRrecv receiver(RECV_PIN);
decode_results results;

void setup() {
Serial.begin(9000);
}
String button;
void loop() {
if (receiver.decode(&results)) {
button = (results.value, HEX);
receiver.resume();
}
}
// stepper motor1+ button 0
void setup() {
if (button = “FF6897”) {
Stepper stepper(STEPS, 11, 13, 12, 14);
stepper.step(11);
}
}

//stepper1- button 1
void setup() {
if (button = “FF30CF”) {
Stepper stepper(STEPS, 11, 13, 12, 14);
stepper.step(-11);
}
}

// stepper motor2+ button 2
void setup() {
if (button = “FF18E7”) {
Stepper stepper(STEPS, 7, 9, 8, 10);
stepper.step(11);
}
}
//stepper2- button 3
void setup() {
if (button = “FF7A85”) {
Stepper stepper(STEPS, 7, 9, 8, 10);
stepper.step(-11);
}
}
// stepper motor3+ button 4
void setup() {
if (button = “FF10EF”) {
Stepper stepper(STEPS, 3, 5, 4, 6);
stepper.step(11);
}
}
//stepper3- button 5
void setup() {
if (button = “FF38C7”) {
Stepper stepper(STEPS, 3, 5, 4, 6);
stepper.step(-11);
}
}

hmm I'm pretty sure you don't need all of those libraries. Double check which one you need to let the project run correctly and delete all the others.