Library conflict: NewPing vs IRLib?

Anyone tried to combine NewPing.h and IRLib libraries?

There is a timer2 conflict using NewPing.h and IRremote.h.
I think IRLib gives a possibility to chance the timer it uses.

I am working with an autonomous shopping trolley for a performance.
So far ultrasonic sensors and motors are working together just fine.
I still need remote control to enable or disable pwm motor controllers.

Is there a example code anywhere?
I tried to modify IRLib example IRservo, but it was a failure.
I´m a newbie, studied this only since april.

Which ultrasonic rangefinder are you using? It is pretty easy to use a Ping or HCDR04 without a library using pulseIn() to measure echo time. That should not interfere with the Servo library. Edit I meant to say IR library.

groundfungus:
Which ultrasonic rangefinder are you using? It is pretty easy to use a Ping or HCDR04 without a library using pulseIn() to measure echo time. That should not interfere with the Servo library.

I use HC-SR04 sensors, L294N motor drivers and andruino Mega.
I´m happy with NewPing library.

It took a while to get everything working.
I just whish to add IR command in my code rather than rewriting it all over again.

Now I am using 4 sensors, but I may have to double it.

NewPing library seems to be the easiest way to handle with multiple sensors.
Anyone compared IRremote.h and IRLib.h libraries?

Sorry about my english: it is not my native language.
I hope someone understood.

For new projects I would suggest IRLib:

  • it a new re-write of the IRremote library
  • it is actively supported by the author and comes with documentation
  • its much more configurable
  • handles more complex IR signals than IRremote

IRremote is great, but I think IRLib is the way forward on Arduino.

If you check the documentation provided with the latest version of the library, it explains how timers can be changed. The docs are included in the the librarues folder. (\libraries\IRLib\manuals)

BTW: perfectly fine understanding the english in your posts. Actually, better than some posts from native speakers :slight_smile:

AnalysIR:
If you check the documentation provided with the latest version of the library, it explains how timers can be changed. The docs are included in the the librarues folder. (\libraries\IRLib\manuals)

Thank you.

I must be stupid or very tired.. Chancing the timer was easy.

Still I can not turn IR results to digitalWrite high or low.
How should I modify the example IRservo sketch?

Still I can not turn IR results to digitalWrite high or low.

I dont know what you mean by this?

Generally, its a good idea to try something yourself and if it doesn't work, post what you did for others to see & help/comment.

Also, play with the examples provided with each library first.

Once you are confident with each library on its own - then you will be better positioned to combine both for what you want them to do.

I´m still struggling with the IRLib.
Now there are no issues about timer-conflicts between NewPing and IRLib libraries.
I got results with IRanalyze: my protocol is RC5 and i got the codes for each button.

I still cannot figure out how to make something with the results.

IRLib is based on IRremote library -so can I try to modify a sketch using IRremote while I´m using IRLib?
There are some simple sketches like

The only example sketch using IRLib I have found is the example sketch IRservo.

/* Example program for from IRLib – an Arduino library for infrared encoding and decoding

  • Version 1.3 January 2014
  • Copyright 2014 by Chris Young http://cyborg5.com
  • “IRservo” Control a servo using an IR remote
    /
    #include <IRLib.h>
    #include <Servo.h>
    /
    Note: Servo library uses TIMER1. The default timer for IRLib on Arduino Uno
  • is TIMER2 so there is no conflict. However a default timer on Arduino Leonardo
  • is TIMER1 so you will have to modify the timer used to use TIMER3 or TIMER4
  • as specified in IRLibTimer.h. Also you will need to modify the input being used.
    */
    // You will have to set these values depending on the protocol
    // and remote codes that you are using. These are from my Sony DVD/VCR
    #define MY_PROTOCOL SONY
    #define RIGHT_ARROW 0x86bca //Move several clockwise
    #define LEFT_ARROW 0x46bca //Move servo counterclockwise
    #define SELECT_BUTTON 0xd0bca //Center the servo
    #define UP_ARROW 0x42bca //Increased number of degrees servo moves
    #define DOWN_ARROW 0xc2bca //Decrease number of degrees servo moves
    #define BUTTON_0 0x90bca //Pushing buttons 0-9 moves to fix positions
    #define BUTTON_1 0x00bca // each 20 degrees greater
    #define BUTTON_2 0x80bca
    #define BUTTON_3 0x40bca
    #define BUTTON_4 0xc0bca
    #define BUTTON_5 0x20bca
    #define BUTTON_6 0xa0bca
    #define BUTTON_7 0x60bca
    #define BUTTON_8 0xe0bca
    #define BUTTON_9 0x10bca

IRrecv My_Receiver(11);//Receive on pin 11
IRdecode My_Decoder;
Servo My_Servo; // create servo object to control a servo
int pos; // variable to store the servo position
int Speed; // Number of degrees to move each time a left/right button is pressed

void setup()
{
My_Receiver.No_Output();//Turn off any unused IR LED output circuit
My_Servo.attach(9); // attaches the servo on pin 9 to the servo object
pos = 90; // start at midpoint 90 degrees
Speed = 3; // servo moves 3 degrees each time left/right is pushed
My_Servo.write(pos); // Set initial position
My_Receiver.enableIRIn(); // Start the receiver
}

void loop()
{
if (My_Receiver.GetResults(&My_Decoder)) {
My_Decoder.decode();
if(My_Decoder.decode_type==MY_PROTOCOL) {
switch(My_Decoder.value) {
case LEFT_ARROW: pos=min(180,pos+Speed); break;
case RIGHT_ARROW: pos=max(0,pos-Speed); break;
case SELECT_BUTTON: pos=90; break;
case UP_ARROW: Speed=min(10, Speed+1); break;
case DOWN_ARROW: Speed=max(1, Speed-1); break;
case BUTTON_0: pos=020; break;
case BUTTON_1: pos=1
20; break;
case BUTTON_2: pos=220; break;
case BUTTON_3: pos=3
20; break;
case BUTTON_4: pos=420; break;
case BUTTON_5: pos=5
20; break;
case BUTTON_6: pos=620; break;
case BUTTON_7: pos=7
20; break;
case BUTTON_8: pos=820; break;
case BUTTON_9: pos=9
20; break;
}
My_Servo.write(pos); // tell servo to go to position in variable ‘pos’
}
My_Receiver.resume();
}
}

I just want to write something like

if (irrecv.decode(&results)){
if (results.value == 801)
digitalWrite (enableA, HIGH);
digitalWrite (enableB, HIGH);
}

What shoudl I do? Where I can learn this?

I ment

if (irrecv.decode(&results)){
if (results.value == 801){
digitalWrite (enableA, HIGH);
digitalWrite (enableB, HIGH);
}
}

There are quite a few examples provided with both IR libraries (you get to them via the Arduino IDE Menus).

The IRLib author has also provided quite a lot of documentation via Github. (you can also get to it via links on his website).

If you cannot get your simple function to work, I suggest you start by removing any non IR stuff from your sketch and just try to flash the onboard LED (pin 3) when you get a valid RC5 command. Once you have that working, then progress to integration with your servo stuff.