WiFiEsp and Keypad library conflict

Hello,
does anyone know why these two libraries can't work on mega2560?
When I put them in same program, there is error reporting :frowning:

#include <Keypad.h>
#include <WiFiEsp.h>

void setup() {
// put your setup code here, to run once:

}

void loop() {
// put your main code here, to run repeatedly:

}

When I put them in same program, there is error reporting :frowning:

Why don't you share the error message with us?

Here it is, but you will get the same if you try it...
Thank you in advance for reply ...

Arduino: 1.8.9 (Windows Store 1.8.21.0) (Windows 10), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

In file included from sketch\navodnjavanje_v161.ino.cpp:1:0:

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.21.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/Arduino.h:40:14: error: expected identifier before numeric constant

#define HIGH 0x1

^

C:\Users\boom beli\Documents\Arduino\libraries\Keypad\src/Keypad.h:56:16: note: in expansion of macro 'HIGH'

#define CLOSED HIGH

^

C:\Users\boom beli\Documents\Arduino\libraries\WiFiEsp\src/utility/EspDrv.h:103:2: note: in expansion of macro 'CLOSED'

CLOSED = 0,

^

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.21.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/Arduino.h:40:14: error: expected '}' before numeric constant

#define HIGH 0x1

^

C:\Users\boom beli\Documents\Arduino\libraries\Keypad\src/Keypad.h:56:16: note: in expansion of macro 'HIGH'

#define CLOSED HIGH

^

C:\Users\boom beli\Documents\Arduino\libraries\WiFiEsp\src/utility/EspDrv.h:103:2: note: in expansion of macro 'CLOSED'

CLOSED = 0,

^

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.21.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/Arduino.h:40:14: error: expected unqualified-id before numeric constant

#define HIGH 0x1

^

C:\Users\boom beli\Documents\Arduino\libraries\Keypad\src/Keypad.h:56:16: note: in expansion of macro 'HIGH'

#define CLOSED HIGH

^

C:\Users\boom beli\Documents\Arduino\libraries\WiFiEsp\src/utility/EspDrv.h:103:2: note: in expansion of macro 'CLOSED'

CLOSED = 0,

^

In file included from C:\Users\boom beli\Documents\Arduino\libraries\WiFiEsp\src/WiFiEsp.h:30:0,

from C:\Users\boom beli\Documents\Arduino\navodnjavanje_v161\navodnjavanje_v161.ino:18:

C:\Users\boom beli\Documents\Arduino\libraries\WiFiEsp\src/utility/EspDrv.h:114:1: error: expected declaration before '}' token

};

^

Multiple libraries were found for "RTClib.h"
Used: C:\Users\boom beli\Documents\Arduino\libraries\RTClib
Not used: C:\Users\boom beli\Documents\Arduino\libraries\RTCLib_by_NeiroN
Multiple libraries were found for "LiquidCrystal.h"
Used: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.21.0_x86__mdqgnx93n4wtt\libraries\LiquidCrystal
Not used: C:\Users\boom beli\Documents\Arduino\libraries\Newliquidcrystal_1.3.5
Not used: C:\Users\boom beli\Documents\Arduino\libraries\LiquidCrystalxx
exit status 1
Error compiling for board Arduino/Genuino Mega or Mega 2560.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Please post a link (using the chain links icon on the forum toolbar to make it clickable) to where you downloaded the Keypad and WiFiEsp libraries from. Or if you installed it using Library Manger (Sketch > Include Library > Manage Libraries in the Arduino IDE or Libraries > Library Manager in the Arduino Web Editor) then say so and state the full name of the library.

Hi again,
keypad.h and WiFiEsp.h library are from Arduino IDE library menager.

You can just put those two in any sketch, and see the errors...

You can try it online also...
Same error...
Just try to compile...

The problem is that both the Keypad library author did the very poor programming practice of using a common word "CLOSED" as a macro name defined in the header file. This resulted in a conflict in the WiFiEsp library, where "CLOSED" was used as an enum value. The easiest fix is to switch the order of your #include directives:

#include <WiFiEsp.h>
#include <Keypad.h>

The better fix is to change the name of the Keypad library's CLOSED macro name to something unique like KEYPAD_CLOSED.

Thank you for fast reply and help...

You're welcome. I'm glad if I was able to be of assistance. Enjoy!
Per

I also faced the same issue. By interchanging the position the problem gets resolved. I totally agree with pert there is a problem with a macro "CLOSED" in both the library.

#include <WiFiEsp.h>
#include <Keypad.h>


[img]https://drive.google.com/open?id=1aeA1qpBixaQJPX6UAU31WxUdqhsiKXIq[/img]
[img]https://drive.google.com/open?id=1rM1rSLBb7tnNeN7KPbT-i7mZUzcPo0NX[/img]