Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error Compiling For ESP32 C3 #45

Closed
ryancasler opened this issue Nov 1, 2022 · 5 comments
Closed

Error Compiling For ESP32 C3 #45

ryancasler opened this issue Nov 1, 2022 · 5 comments
Labels

Comments

@ryancasler
Copy link
Contributor

When compiling a Button2 sketch using an ESP32 C3 board (I tried 2 different brands, DFRobot and Adafruit), I get the following error:

c:\LIBRARY DIRECTORY\Button2\src\Button2.cpp: In member function 'byte Button2::_getState()':
c:\LIBRARY DIRECTORY\Button2\src\Button2.cpp:293:18: error: 'touchRead' was not declared in this scope
       int capa = touchRead(pin);
                  ^~~~~~~~~
c:\LIBRARY DIRECTORY\Button2\src\Button2.cpp:293:18: note: suggested alternative: 'timerRead'
       int capa = touchRead(pin);
                  ^~~~~~~~~
                  timerRead
exit status 1
Compilation error: exit status 1

One thing that sets the C3 apart from other members of the ESP32 family is the fact that it doesn't support touch. I can't seem to figure out why it's reading this as capacitive. Here are the relevant sections of my sketch:

Button2 button_0, button_1, button_2, button_3, button_4, button_5, button_6, button_7;
Button2 myButtons[] = { button_0, button_1, button_2, button_3, button_4, button_5, button_6, button_7 };
int buttonPins[] = {A0, A1, A2, A3, SDA, SCL, TX, RX};
int numButtons = 8;

void setup() {
  Serial.begin(115200);
  delay(100);
  Serial.println("Initialized");
  for (int i = 0; i < numButtons; i++) {
    myButtons[i].begin(buttonPins[i], INPUT_PULLUP, false, true);
    myButtons[i].setClickHandler(clickHandler);
    myButtons[i].setDoubleClickHandler(doubleHandler);
    myButtons[i].setLongClickDetectedHandler(longHandler);
    myButtons[i].setReleasedHandler(released);
    myButtons[i].setLongClickTime(800);
    myButtons[i].setDoubleClickTime(400);
    myButtons[i].setDebounceTime(75);
  }
}

And of course I have all the relevant callbacks and whatnot.

Now, If I switch to an ESP32 S2 board, the exact same sketch compiles perfectly with zero changes. So, I assume there is something wrong in the board definition or the variants pin definition for the C3 boards but for the life of me I can't find it. I also tried to define a custom state function for all of the buttons and that didn't help. I still got the same error when compiling. Any advice on where to look and what might need to be changed? I'm using the latest version of the ESP32 Core for Arduino, v2.0.5.
https://github.com/espressif/arduino-esp32/releases/tag/2.0.5
Thanks so much!!

@ryancasler
Copy link
Contributor Author

ryancasler commented Nov 1, 2022

I found a temporary workaround. If I comment out lines 310, and 312-317 of the latest Button2.cpp file (d7d62e8) then it compiles correctly. So, there is definitely something about the definition of those pins that is making it think those pins are capacitive. And none of the pins on a C3 can be capacitive.

@LennartHennigs
Copy link
Owner

LennartHennigs commented Nov 1, 2022

Hey @ryancasler,
yes, there is a problem with the C3s.
Back then I assumed that all ESP32s have capacitive touch.
In line 313 of Button2.cpp I check for this.

Could you try this sketch and tell me if all your C3s are detected?

#if defined(ESP32) 
  #pragma message "Using ESP32"
  #if defined(ARDUINO_ESP32C3_DEV) 
    #pragma message "Using ESP32_C3"
  #endif
#elif defined(ESP8266) 
  #pragma message "Using ESP8266"
#else
  #pragma message "Using something else"
#endif

#if defined(SOC_TOUCH_SENSOR_SUPPORTED)
  #pragma message "Touch senor is there"
#endif

void setup() { }
void loop()  { }

(Reminder to myself: Using this comment as a starting point.)

@LennartHennigs
Copy link
Owner

LennartHennigs commented Nov 2, 2022

Hey @ryancasler,
I decided that I don't want to add another special case for the exclusion of the C3.
Using capacitive touch with the library is the special case here.
I will move the cap. touch code out of the library and use the custom handler to provide an example.
No more checking different ESP variants in the library itself.
Thus, your error will be gone with the next update.

@LennartHennigs
Copy link
Owner

pushed new version

@ryancasler
Copy link
Contributor Author

Yup...new version worked perfectly. Thanks!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants