Add ESP32 compatibility to an existing Arduino Library
New here? Learn about Bountify and follow @bountify to get notified of new bounties! x

This bounty was posted in a Github Issue that I opened on the repo of the library. It's a Capacitive Touch library. Some of the possible implementation details are posted in the issue.

In short, this bounty is to add support of this library to the ESP32. Not just so that it compiles, but that I can actually use it for it's intended purposes.

https://github.com/HCI-Lab-Saarland/MultiTouchKit/issues/2

I'm using an ESP32-WROVER specifically. If possible I would love to use this functionality without a multiplexer, but I'm not sure if this is possible.

The ESP should have the needed PWM and ADC functionality I think? But the library seems to specifically use PWM settings from the atmega328p. So this is why I've posted the bounty; I don't know how to make this work on the ESP32.

Requirements;

  • Make it run on the Arduino core for ESP32
  • If possible without the multiplexer
  • If possible by simply forking the library and adding compatibility
awarded to CyteBode
Tags
arduino
esp32

Crowdsource coding tasks.

1 Solution

Winning solution

Since you don't need the multiplexer, you would be better off using a different library. This one should support the ESP32: https://github.com/PaulStoffregen/CapacitiveSensor

Otherwise, if you really want to use MultiTouchKit, setting up PWM on the ESP32 should be as easy as this:

void MultiTouchKit::setupPWM() {
    #define PWM_PIN 3          // Whatever pin it may be
    analogWriteFreq(4000);     // 4 KHz frequency
    analogWrite(PWM_PIN, 255); // 25% Duty cycle
}

Since the library is just a header and a source file, you could add them to your sketch with the new implementation of setupPWM(), rename them to MultiTouchKit_esp32.hpp and MultiTouchKit_esp32.cpp (to avoid importing the original library), and change the include's to #include "MultiTouchKit_esp32.hpp" in your sketch and in MultiTouchKit_esp32.cpp.

I don't have an ESP32-WROVER to test, so I may be off track, but the rest of the code is generic enough that it should work with an ESP32. It at least compiles in the Arduino IDE with an ESP32 board as a target.

That sounds great! I will test with this on my hardware and report back. I'll probably accept this answer tomorrow. Would you possibly be available for incidental follow-up queries if stuff comes up after accepting the solution?
jwktje 8 months ago
Sure thing! It's the least I could do. You can PM me after clicking on my name.
CyteBode 8 months ago
This solution did push me in the right direction to get the code of the library to compile and run. However in practice it isn't really giving me the result I need yet. So I'm doubting my implementation. I will create a public github repo for this and accept the answer. Hopefully CyteBode wants to help me debug a little further. If it takes crazy amounts of time, additional compensation is ok with me.
jwktje 8 months ago