I am having some issues with the capacitive sensor library and my node MCU board. (I believe that it is the v 1.0, and possibly a clone).
I got some errors that I don't quite understand how to fix while attempting to verify the code.
Here is the code I used:
#include <CapacitiveSensor.h>
CapacitiveSensor rightPad = CapacitiveSensor(12,13); // 2M resistor between pins 12 & 13, pin 13 is sensor pin
CapacitiveSensor leftPad = CapacitiveSensor(12,15); // 2M resistor between pins 12 & 15, pin 15 is sensor pin
const int rightSensorThreshold = 450; //threshold at which to to recognize input
const int leftSensorThreshold = 450;
void setup() {
Serial.begin(9600);
}
void loop() {
long total1 = rightPad.capacitiveSensor(30);
long total2 = leftPad.capacitiveSensor(30);
if (rightSensorThreshold > 450) { //prints R if right sensor is touched
Serial.println("R");
}
if (leftSensorThreshold > 450) { //prints L if left sensor is touched
Serial.println("L");
}
}
Here is the error message I got:
Arduino: 1.8.15 (Mac OS X), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, Disabled (new aborts on oom), Disabled, All SSL ciphers (most compatible), 32KB cache + 32KB IRAM (balanced), Use pgm_read macros for IRAM/PROGMEM, 4MB (FS:2MB OTA:~1019KB), 2, v2 Lower Memory, Disabled, None, Only Sketch, 115200"
/Users/<myusername>/Documents/Arduino/libraries/CapacitiveSensor/CapacitiveSensor.cpp: In member function 'long int CapacitiveSensor::capacitiveSensor(uint8_t)':
/Users/<myusername>/Documents/Arduino/libraries/CapacitiveSensor/CapacitiveSensor.cpp:77:75: error: call of overloaded 'abs(long unsigned int)' is ambiguous
77 | if ( (millis() - lastCal > CS_AutocaL_Millis) && abs(total - leastTotal) < (int)(.10 * (float)leastTotal) ) {
| ^
In file included from /Users/<myusername>/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.0.4-gcc10.3-1757bed/xtensa-lx106-elf/include/c++/10.3.0/cstdlib:75,
from /Users/<myusername>/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.0.4-gcc10.3-1757bed/xtensa-lx106-elf/include/c++/10.3.0/stdlib.h:36,
from /Users/<myusername>/Library/Arduino15/packages/esp8266/hardware/esp8266/3.0.2/cores/esp8266/Arduino.h:27,
from /Users/<myusername>/Documents/Arduino/libraries/CapacitiveSensor/CapacitiveSensor.cpp:13:
/Users/<myusername>/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.0.4-gcc10.3-1757bed/xtensa-lx106-elf/include/stdlib.h:74:5: note: candidate: 'int abs(int)'
74 | int abs (int);
| ^~~
In file included from /Users/<myusername>/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.0.4-gcc10.3-1757bed/xtensa-lx106-elf/include/c++/10.3.0/cstdlib:77,
from /Users/<myusername>/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.0.4-gcc10.3-1757bed/xtensa-lx106-elf/include/c++/10.3.0/stdlib.h:36,
from /Users/<myusername>/Library/Arduino15/packages/esp8266/hardware/esp8266/3.0.2/cores/esp8266/Arduino.h:27,
from /Users/<myusername>/Documents/Arduino/libraries/CapacitiveSensor/CapacitiveSensor.cpp:13:
/Users/<myusername>/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.0.4-gcc10.3-1757bed/xtensa-lx106-elf/include/c++/10.3.0/bits/std_abs.h:79:3: note: candidate: 'constexpr long double std::abs(long double)'
79 | abs(long double __x)
| ^~~
/Users/<myusername>/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.0.4-gcc10.3-1757bed/xtensa-lx106-elf/include/c++/10.3.0/bits/std_abs.h:75:3: note: candidate: 'constexpr float std::abs(float)'
75 | abs(float __x)
| ^~~
/Users/<myusername>/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.0.4-gcc10.3-1757bed/xtensa-lx106-elf/include/c++/10.3.0/bits/std_abs.h:71:3: note: candidate: 'constexpr double std::abs(double)'
71 | abs(double __x)
| ^~~
/Users/<myusername>/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.0.4-gcc10.3-1757bed/xtensa-lx106-elf/include/c++/10.3.0/bits/std_abs.h:61:3: note: candidate: 'long long int std::abs(long long int)'
61 | abs(long long __x) { return __builtin_llabs (__x); }
| ^~~
/Users/<myusername>/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.0.4-gcc10.3-1757bed/xtensa-lx106-elf/include/c++/10.3.0/bits/std_abs.h:56:3: note: candidate: 'long int std::abs(long int)'
56 | abs(long __i) { return __builtin_labs(__i); }
| ^~~
exit status 1
Error compiling for board NodeMCU 1.0 (ESP-12E Module).
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
After staring at this for a few minutes, it appears that it has some sort of issue with the capacitive sensor library, which strikes me as odd because it says in the documentation that capacitive sensor is compatible with all architectures, and I have seen other people be successful with this board.
If anyone knows a workaround/method to get this library to work with this board, it would be much appreciated.
Thanks for the help!