Go Down

Topic: IRRemote library conflicts with tone() function (Read 9058 times) previous topic - next topic

Automative

Hi,

I'm currently working on a project that combines an IR remote and a piezo sounder to play confirmation sounds.

To produce a beep on the sounder I use the command tone();

When I integrated this in my main sketch, when I got the right sounds. Tried to compile it and got the following error:

core.a(Tone.cpp.o): In function `__vector_13':
C:\Users\Vincent\Desktop\ARDUINO\arduino-1.0.1\hardware\arduino\cores\arduino/Tone.cpp:523: multiple definition of `__vector_13'
IRremote\IRremote.cpp.o:C:\Users\Vincent\Desktop\ARDUINO\arduino-1.0.1\libraries\IRremote/IRremote.cpp:311: first defined here
c:/users/vincent/desktop/arduino/arduino-1.0.1/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/bin/ld.exe: Disabling relaxation: it will not work with multiple definitions

The IRremote.cpp files is attached

An example of a tone function I'll be using:

Code: [Select]
void PlayTone1() {
  tone(PiezoSounderPin, 3000, 8);
  delay(10);
  noTone(PiezoSounderPin);
}


Hope someone can help me with this... Thanks in advance

Automative

With a bit more scouting work i figured it out myself.

Apperently the function tone() uses timer 2 wich, by default, the IRremote also uses when using a ATmega2560 chip.

In the file IRremoteInt.h, you can define wich timer to use. Everything works now!

vicvegax



agcastaldin

worked good to me too. i used timer 5 pin 46

Jamsel

Hi Karma
I am having the same trouble as you with the tone() not working with IR remote. Your comments look really useful except I don't know how to change an existing library. Could you please share your adapted library, with another pin (other than pin2) activated for the IR timer? Please that would be most useful.

Otherwise any advice on changing an existing library? When I try to open an .h file it does not allow it. So not able to get into the library to select the correct pin.

nunesdi01

Hi Jamsel, I just solved the problem too.

You need to go on your Arduino folder --> Libraries --> IR folder
then you need to find the IRremoteInt.h file. You can open with wordpad.
Try to find the part that says

"
// Define which timer to use
//
// Uncomment the timer you wish to use on your board.
// If you are using another library which uses timer2, you have options to
//   switch IRremote to use a different timer.

..."

You need to find the line that has your Arduino type, mine is the UNO so I used this one:

// Arduino Duemilanove, Diecimila, LilyPad, Mini, Fio, Nano, etc
#else
   //#define IR_USE_TIMER1    //tx = pin 9
   #define IR_USE_TIMER2     tx = pin 3

Now you put the "//" in the second line and remove them from the first line. Will look like that:

// Arduino Duemilanove, Diecimila, LilyPad, Mini, Fio, Nano, etc
#else
   #define IR_USE_TIMER1    tx = pin 9
   //#define IR_USE_TIMER2    // tx = pin 3

 Save the changes and your program should work great.

nunesdi01

Automotive thank you so much for your help!

JonRon

Hi,

I'm quite new to Arduino things and tinker occasionally when I have time. Recently I followed a tutorial on using old TV remotes. http://goo.gl/62c1d8 and got as far as getting an LED to dim with the remote.

I thought I would then modify the sketch to include a bleep (using a piezo speaker) each time a button on the remote was pushed using tone(). No luck, got a compiler upload error, found this thread and did the mod to the IRremoteInt.h detailed above by nunesdi01. Uploaded to my Uno OK but then nothing worked including the dimming led.

LED dimming sketch:

Code: [Select]
#include <IRremote.h>
#define irPin 11
IRrecv irrecv(irPin);
decode_results results;

int ledPin = 9;
int brightness = 10;

void setup() {
   Serial.begin(9600);
   irrecv.enableIRIn();

   pinMode(ledPin, OUTPUT);
}

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

       switch (results.value) {
         case 0x1000405:
            if(brightness < 255) {brightness = brightness+5;}
            analogWrite(ledPin, brightness);
            Serial.println(brightness);
            
            break;

         case 0x1008485:
            if(brightness > 0) {brightness = brightness-5;}
            analogWrite(ledPin, brightness);
            Serial.println(brightness);
            
            break;

         case 0x100BCBD:
            Serial.println("OFF");
            analogWrite(ledPin, 0);
            brightness = 20;
            
            break;
         }
   irrecv.resume();
   }
}


LED dimming sketch with tone() added to one button

Code: [Select]
#include <IRremote.h>
#define irPin 11
IRrecv irrecv(irPin);
decode_results results;

int ledPin = 9;
int brightness = 10;
int buzzer = 8;



void setup() {
   Serial.begin(9600);
   irrecv.enableIRIn();

   pinMode(ledPin, OUTPUT);
   pinMode(buzzer, OUTPUT);
  
}

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

       switch (results.value) {
         case 0x1000405:
            if(brightness < 255) {brightness = brightness+5;}
            analogWrite(ledPin, brightness);
            Serial.println(brightness);
            tone(buzzer, 1000); // Send 1KHz sound signal...
            delay(1000);        // ...for 1 sec
            noTone(buzzer);  
                    
            break;

         case 0x1008485:
            if(brightness > 0) {brightness = brightness-5;}
            analogWrite(ledPin, brightness);
            Serial.println(brightness);
            
            break;

         case 0x100BCBD:
            Serial.println("OFF");
            analogWrite(ledPin, 0);
            brightness = 20;
            
            break;
         }
   irrecv.resume();
   }
}


I know I've done something wrong...can someone help me please?

Thanks

Gerri1981

can somen sent a link for the <IRremoteINT.h> please

DangerouslyExplosive

In the newer version of the IRremote library, the timer control is moved to the file boarddefs.h, which deals directly with board-specific functions. You will no longer be able to find the timer pin control in the other files if you have the new version.

Go Up