-->
Page 1 of 1

Using the CapacitiveSensor library on a NodeMCU

PostPosted: Thu Feb 23, 2017 3:51 am
by sumguy
Hi everyone
For a personal project, I need a capacitive sensor. I heard of the CapacitiveSensor library, and tried it successfuly with one of my Arduino Unos. Though, I'm having a hard time using it on my NodeMCU...
Here is the code that I've been using successfuly on the Arduino;

Code: Select all#include <CapacitiveSensor.h>

CapacitiveSensor sensor = CapacitiveSensor(5,4);    // I changed the pins though, to reflect my hardware setup

void setup()                   
{
   Serial.begin(9600);
}

void loop()                   
{
    long start = millis();
    long total = sensor.capacitiveSensor(30);

    Serial.print(millis() - start);   
    Serial.print("\t");                 

    Serial.print(total);         
    Serial.println();

    delay(10);                         
}


It's actually very close to the example given with the library.
As I said, it does work correctly on an Arduino Uno, but not on my NodeMCU. Here is the output:

Image

Would you know where the problem is coming from?

Thank you in advance