Go Down

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

sterretje

There are three timers on an 328P based board like the Uno. Timer0 is used for millis() and the other two are free.

All 3 timers are also used for PWM; I think that this usually does not pose issues (but I'm sure it can).

I'm quite sure a Mega will not have the problems although you might have to change the library files in similar fashion as you have done now.

And playing a tune using delay / millis() while moving will probably be too much asked; I was more thinking of a beep before the robot starts moving, not while the robot is moving.
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

supersmiler

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.

Worked!! Thanks

harshadgajera

I am new to the forum so pardon my typing and english. :)

I am making turntable for 360 photography. (on Arduino UNO)


I had working sketch for Canon (triggered with IR led) (ref and code from: https://github.com/roboanat/photo-turntable)

I want to work same for Nikon & canon both so I find IR code for Nikon, which gives me problem with tone() code. Which solved by above help (changing timer2 to timer1) and its working fine with Nikon.

But it stop working for canon now.

I want to use same IR LED for both cameras, though both have different codes for it


Please find attached sketch file (which I altered as per my retirement)
> Note: other supporting files/libraries are from above github link, i didnt change anything in those files, except "IRremoteInt.h" as per above topic.


Below are 2 IR signal for both cameras from attached file (rest of the sketch are tested OK)
----------------------------------------------------------------

// for canon ------------------------------ this code from original from github

void irStillsShot() {
  int khz = 33; // 33kHz frequency
  unsigned int irSignal[] = {480};
  ir_led.sendRaw(irSignal, sizeof(irSignal) / sizeof(irSignal[0]), khz);
  delayMicroseconds(7330);
  ir_led.sendRaw(irSignal, sizeof(irSignal) / sizeof(irSignal[0]), khz);
}


// for nikon ---------------------------- this is from some other program for nikon

void shutterClick() {
  tone(IRPin,38000);
  delay(2);
  noTone(IRPin);
  delay(28);//original delay 28ms
  tone(IRPin,38000);
  delayMicroseconds(200);
  noTone(IRPin);
  delayMicroseconds(1500);
  tone(IRPin,38000);
  delayMicroseconds(200);
  noTone(IRPin);
  delayMicroseconds(3300);
  tone(IRPin,38000);
  delayMicroseconds(200);
  noTone(IRPin);                     // 65ms delay before repeat
}

--------------------------------------------------------------------
Note: IR is assign to pin 3.

Now ---- If i compile sketch as it is then it give tone() conflict error, coz tone() is conflict with timer2, may be it is in use.

But --- If I change timer2 to timer1 in "IRremoteInt.h" then nikon works fine but canon code have no LED working.

>>> Now my main question is that in which code I am making mistake... in canon or in nikon. And is it possible to work like this with same LED? If yes then I might put my more time for the same. If not then I might have to use MEGA or make 2 different module for 2 cameras.

Hope I explain it proper and someone might help me with this.


Thanks in advance.

mmotiramani

Was there some resolution identified to this issue ? I yes can you plz share?
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
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
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

sterretje

Was there some resolution identified to this issue ? I yes can you plz share?
Reply #6 ?
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

Go Up