Library CapacitiveSensor supported by ESP8266

1,980 views
Skip to first unread message

Heleno

unread,
Mar 20, 2016, 8:29:39 PM3/20/16
to souliss
The library CapacitiveSensor version 0.5.1 available in https://github.com/PaulStoffregen/CapacitiveSensor now is supported by ESP8266. I'm trying to integrate with souliss, but there is a conflict with the wifi connection. Any help is appreciated.

Juan Pinto

unread,
Mar 21, 2016, 8:39:36 PM3/21/16
to souliss
Post your sketch :P

Btw I have a capacitive function working with ESP using only one pin instead of two, here you've an example :)


Regards

Heleno

unread,
Mar 21, 2016, 9:26:48 PM3/21/16
to souliss
Regards Juan!

This is my sketch:

// Configure the framework
#include "bconf/MCU_ESP8266.h"              // Load the code directly on the ESP8266
#include "conf/Gateway.h"                   // The main node is the Gateway, we have just one node
#include "conf/IPBroadcast.h"


// **** Define the WiFi name and password ****
#define WIFICONF_INSKETCH
#define WiFi_SSID               "ssid"
#define WiFi_Password           "pass"    

// Include framework code and libraries
#include <ESP8266WiFi.h>
#include <EEPROM.h>
#include <ESP8266mDNS.h>
#include <CapacitiveSensor.h>

/*** All configuration includes should be above this line ***/ 
#include "Souliss.h"

// This identify the number of the LED logic
#define MYLED          0               

// **** Define here the right pin for your ESP module **** 
#define OUTPUTPIN 14  

const int cap1 = 4; // 470k resistor between the pin 4 and 5
const int cap2 = 5; //Capacitive Sensor
const int sensibil = 100;  
CapacitiveSensor   csensy = CapacitiveSensor(cap1,cap2); 
    

bool ligado = 0;

OTA_Setup();

void setup()
{    
     csensy.set_CS_AutocaL_Millis( 0xFFFFFFFF);      
    Initialize();
     Serial.begin(115200);   
    // Connect to the WiFi network and get an address from DHCP
    GetIPAddress();                           
    SetAsGateway(myvNet_dhcp);       // Set this node as gateway for SoulissApp  

    Set_SimpleLight(MYLED);        // Define a simple LED light logic
 pinMode(OUTPUTPIN, OUTPUT);         // Use pin as output 
    
    OTA_Init();
}

void loop()
    long cape =  csensy.capacitiveSensor(30); //chama a funcao que le a capacitancia...
    Serial.println(cape);
    // Here we start to play
    EXECUTEFAST() {                          
        UPDATEFAST();   
          
        FAST_110ms() {   // We process the logic and relevant input and output every 50 milliseconds
             if (cape > sensibil ) 
      {    
            ligado = !ligado;
            mInput(MYLED) = Souliss_T1n_ToggleCmd ;      
      }
         
       Logic_SimpleLight(MYLED);
       DigOut(OUTPUTPIN, Souliss_T1n_Coil,MYLED);       
           
        } 
    }        
               
        FAST_GatewayComms(); 
         EXECUTESLOW() {
        UPDATESLOW();

        SLOW_10s() { 
                Timer_SimpleLight(MYLED);   
        }                                       
    }
  
   OTA_Process();
}
 

Juan Pinto

unread,
Mar 23, 2016, 7:49:47 PM3/23/16
to sou...@googlegroups.com

Can you explain where is the problem with wifi?
What values you see on Serial?
 
Regards

--
You received this message because you are subscribed to a topic in the Google Groups "souliss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/souliss/-xVRo9lsoTg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to souliss+u...@googlegroups.com.
To post to this group, send email to sou...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/souliss/36198edc-9e38-43aa-8ee6-356f967fefb9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Heleno

unread,
Mar 23, 2016, 8:51:25 PM3/23/16
to souliss
Regards Juan!
O IP Address of the board is 192.168.1.248, run comand ping 192.168.1.248 -t this is the answer:

Resposta de 192.168.1.248: bytes=32 tempo=782ms TTL=255
Resposta de 192.168.1.248: bytes=32 tempo=725ms TTL=255
Resposta de 192.168.1.248: bytes=32 tempo=664ms TTL=255
Resposta de 192.168.1.248: bytes=32 tempo=604ms TTL=255
Esgotado o tempo limite do pedido.
Esgotado o tempo limite do pedido.
Resposta de 192.168.1.248: bytes=32 tempo=90ms TTL=255
Resposta de 192.168.1.248: bytes=32 tempo=2329ms TTL=255

Serial monitor:

-2
-2
-2
-2
-2
-2
-2
-2
-2
-2
-2
-2
-2


When I keep finger on sensor is:

Resposta de 192.168.1.248: bytes=32 tempo=17ms TTL=255
Resposta de 192.168.1.248: bytes=32 tempo=17ms TTL=255
Resposta de 192.168.1.248: bytes=32 tempo=17ms TTL=255
Resposta de 192.168.1.248: bytes=32 tempo=17ms TTL=255
Resposta de 192.168.1.248: bytes=32 tempo=17ms TTL=255
Resposta de 192.168.1.248: bytes=32 tempo=18ms TTL=255
Resposta de 192.168.1.248: bytes=32 tempo=17ms TTL=255
Resposta de 192.168.1.248: bytes=32 tempo=17ms TTL=255
Resposta de 192.168.1.248: bytes=32 tempo=18ms TTL=255
Resposta de 192.168.1.248: bytes=32 tempo=17ms TTL=255
Resposta de 192.168.1.248: bytes=32 tempo=17ms TTL=255
Resposta de 192.168.1.248: bytes=32 tempo=17ms TTL=255
Resposta de 192.168.1.248: bytes=32 tempo=17ms TTL=255

Serial monitor:

635805
540264
422548
631511
407981
605764
491861
576888
566672
545663
450367
464828


Thomas Kowalski

unread,
Mar 12, 2017, 3:44:43 PM3/12/17
to souliss
Hi !
Has anyone succeded in resolving this issue ? I've been trying to use the CapacitiveSensor for a (long) while on my ESP8266 and I'm always getting -2 in the Serial monitor... My setup is simple : output → 1 MOhm resistor → Foil → Input (with DuPont cables.) 
The exact same thing works well on an Arduino but not on my NodeMCU. If anyone has any kind of info (or workaround, or alternative solution to make a capacitive sensor,) I'd be glad to hear about it.

Thank you

Digital Lumberjack

unread,
Apr 29, 2017, 4:00:44 AM4/29/17
to souliss
Hello, I just had the same issue than Thomas.

It's been a week since I play with the esp8266 12e and I upload the firmware from my laptop. 

I'm use to it now: as soon as I want to use analog input/output, or as soon as we are talking about capacitive sensor, I must unplug the serial/usb port, to have only one source of power and only the "real" ground and not the one of my battery.

I had the -2 result for one hour, and I just tested to light a led when the result is different than -2. As soon as i unplugged the usb, the capacitive sensor works just great :)

Heleno

unread,
Apr 30, 2017, 10:12:09 AM4/30/17
to souliss
Hello guys
Replace the 1M resistor with 330k parallel ceramic capacitor 22pF.
Let me know the result.

Thomas Kowalski

unread,
May 10, 2017, 5:29:24 AM5/10/17
to souliss
Well I'll have to find new components for that... 

Also I was wondering, does it work without grounding ? Because in the end, I used the classic CapacitiveSensor library for Arduino with the NodeMCU and it worked, but only if the ground for the NodeMCU was the same as mine (which seems logical)... 

Thomas Kowalski

unread,
May 10, 2017, 10:04:46 AM5/10/17
to souliss
I forgot to say, I used CapSense via another microcontroller, it wasn't working on the NodeMCU of course.
Reply all
Reply to author
Forward
0 new messages