You are reading a single comment by @Oscar and its replies. Click here to read the full conversation.
  • Hi,

    I'm just getting starting with Espruino and I'm new to the setWatch function.

    I have a MDBT42Q board that I want to read a button input from a capacitive touch sensor momentary switch from Adafruit (https://www.adafruit.com/product/1374). The code is as follows:

    digitalRead(D28);
    pinMode(D28, "input_pulldown");
    
    setWatch(function() {
      digitalPulse(LED2, 1, 50);
      console.log("Pressed");
    }, D28, {repeat:true, debounce:50, edge:"rising"});
    

    If I connect briefly D28 to the 3.3V pin it works as expected.
    But if I connect it to the output of the momentary switch (and I touch the switch) it doesn't.

    I played with the pin D28 as an analog input and I have observed the following:
    D28 reads 0.99 when connected to the 3.3V pin.
    D28 reads 0.97 when connected to the output of the switch (and the switch is touched). This corresponds to around 3.22V.
    D28 reads close to zero when the switch is in open position (no touch).

    All results make sense and in analog mode I can read the sensor being touched.
    But it appears that the setWatch function interprets in digitalRead mode 0.99 as high but 0.97 as low, as if the threshold for a high would be beyond 0.97.

    Is this an expected behavior? Can this threshold be changed? I would have expected that anything beyond 1V would be detected as high.

    The end application is a bluetooth media controller with a play/pause touch sensor and a next touch sensor to be integrated in the handle of my rowing machine, so that I can control playback while rowing.

    Oscar.

  • Thr 2020.01.02

    Hi @Oscar, thank you for your interest in this exciting world with Espruino!

    Haven't worked with a capacitive touch sensor, and am on lunch break, so not a lot of time on this end as I'll need to get back to the salt mine shortly. Will have time later this evening.

    Will need to determine the internal resistance for 'pulldown' mode. Has a different pinMode been tried?

    Pin D28 is also an ADC. Possible conflict with that mode? Try a non ADC pin comparrison.

    Does setWatch() read analog pins? Would analogRead() be a better choice?

    http://www.espruino.com/Reference#l__global_analogRead

    L1 is only used once. How is the 3.3v input test being performed?

    A working example:

    https://www.espruino.com/MPR121

    In the mean time, would you please post links to datasheets, page references that pertain to wiring, I/O, I2C, examples etc. and also process.env

    Try searching google with the site keyword qualifier:

    Google    capacitive sensor site:espruino.com

About

Avatar for Oscar @Oscar started