EasyButton library sample code does not work

I am using the Pressed example for the EasyButton library. It is not ESP32 specific but works for my AdaFruit Feather ESP32 board.

It does not compile and throws the following compilation errors:

In file included from /Users/jjs/Library/Arduino15/packages/esp32/hardware/esp32/2.0.11/cores/esp32/Arduino.h:223,
                 from /private/var/folders/6v/1p1396h55_72kp8gnv3gsnv00000gq/T/arduino/sketches/9AF4919C475D15D2FB9CC92B2D1DAFB4/sketch/Pressed-Nano-ESP32.ino.cpp:1:
/Users/jjs/Library/Arduino15/packages/esp32/hardware/esp32/2.0.11/cores/esp32/io_pin_remap.h:44:69: error: variable or field 'attachInterrupt' declared void
 #define attachInterrupt(pin, fcn, mode)             attachInterrupt(digitalPinToGPIONumber(pin), fcn, mode)
                                                                     ^~~~~~~~~~~~~~~~~~~~~~
/Users/jjs/Library/Arduino15/packages/esp32/hardware/esp32/2.0.11/cores/esp32/FunctionalInterrupt.h:18:6: note: in expansion of macro 'attachInterrupt'
 void attachInterrupt(uint8_t pin, std::function<void(void)> intRoutine, int mode);
      ^~~~~~~~~~~~~~~
/Users/jjs/Library/Arduino15/packages/esp32/hardware/esp32/2.0.11/cores/esp32/FunctionalInterrupt.h:18:30: error: expected primary-expression before 'pin'
 void attachInterrupt(uint8_t pin, std::function<void(void)> intRoutine, int mode);
                              ^~~
/Users/jjs/Library/Arduino15/packages/esp32/hardware/esp32/2.0.11/cores/esp32/io_pin_remap.h:44:92: note: in definition of macro 'attachInterrupt'
 #define attachInterrupt(pin, fcn, mode)             attachInterrupt(digitalPinToGPIONumber(pin), fcn, mode)
                                                                                            ^~~
/Users/jjs/Library/Arduino15/packages/esp32/hardware/esp32/2.0.11/cores/esp32/FunctionalInterrupt.h:18:61: error: expected primary-expression before 'intRoutine'
 void attachInterrupt(uint8_t pin, std::function<void(void)> intRoutine, int mode);
                                                             ^~~~~~~~~~
/Users/jjs/Library/Arduino15/packages/esp32/hardware/esp32/2.0.11/cores/esp32/io_pin_remap.h:44:98: note: in definition of macro 'attachInterrupt'
 #define attachInterrupt(pin, fcn, mode)             attachInterrupt(digitalPinToGPIONumber(pin), fcn, mode)
                                                                                                  ^~~
/Users/jjs/Library/Arduino15/packages/esp32/hardware/esp32/2.0.11/cores/esp32/FunctionalInterrupt.h:18:73: error: expected primary-expression before 'int'
 void attachInterrupt(uint8_t pin, std::function<void(void)> intRoutine, int mode);
                                                                         ^~~
/Users/jjs/Library/Arduino15/packages/esp32/hardware/esp32/2.0.11/cores/esp32/io_pin_remap.h:44:103: note: in definition of macro 'attachInterrupt'
 #define attachInterrupt(pin, fcn, mode)             attachInterrupt(digitalPinToGPIONumber(pin), fcn, mode)
                                                                                                       ^~~~

exit status 1

Compilation error: exit status 1

I will raise an issue on the EasyButton github page: GitHub - evert-arias/EasyButton: Arduino library for debouncing momentary contact switches, detect press, release, long press and sequences with event definitions and callbacks.

Anyone with similar experiences? Any workarounds?

Using Arduino 2.1.1 on a Mac. Board setting is Arduino Nano ESP32

1 Like

Since the example is small I will post it here:

/*
 Name:		Pressed.ino
 Created:	9/5/2018 10:49:52 AM
 Author:	Evert Arias
 Description: Example to demostrate how to use the library to detect a single pressed on a button.
*/

#include <EasyButton.h>

// Arduino pin where the button is connected to.
#define BUTTON_PIN D4

#define BAUDRATE 115200

// Instance of the button.
EasyButton button(BUTTON_PIN);

// Callback function to be called when the button is pressed.
void onPressed()
{
  Serial.println("Button pressed");
}

void setup()
{
  // Initialize Serial for debuging purposes.
  Serial.begin(BAUDRATE);

  Serial.println();
  Serial.println(">>> EasyButton pressed example <<<");

  // Initialize the button.
  button.begin();
  // Add the callback function to be called when the button is pressed.
  button.onPressed(onPressed);
}

void loop()
{
  // Continuously read the status of the button.
  button.read();
}
1 Like

Thanks for reporting this @jjs3579! I can confirm FunctionalInterrupt (a feature EasyButton depends on) is not handled properly on the current Nano ESP32 core, and we will fix this in the next release.

If you wish to test on your end, you can directly modify the file that is causing the error on your PC:

/Users/jjs/Library/Arduino15/packages/esp32/hardware/esp32/2.0.11/cores/esp32/FunctionalInterrupt.h

and change line 18 from:

void attachInterrupt(uint8_t pin, std::function<void(void)> intRoutine, int mode);

to

void (attachInterrupt)(uint8_t pin, std::function<void(void)> intRoutine, int mode);

(adding extra ( and ) around the function name).

Let me know if this works for you!
BR,
Luca

Thanks @lburelli for the reply and suggestion.

It worked for me. The Pressed demo for the EasyButton library now compiles and works.

Looking forward to an official fix being distributed.