Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 9 of 9

Thread: Capacitive resistance on analog pins

  1. #1
    Junior Member
    Join Date
    Feb 2017
    Posts
    4

    Capacitive resistance on analog pins

    Greetings everyone,

    I'm making a glove with 5 fingers, using Teensy 3.2, where each finger has 3 copper pads which should give out different resistance values.

    Click image for larger version. 

Name:	capacitive.JPG 
Views:	67 
Size:	22.2 KB 
ID:	9698

    I tested ADCTouch library from
    HTML Code:
    https://github.com/martin2250/ADCTouch/blob/master/examples/Buttons/Buttons.ino
    on Arduino Uno, and it worked well, I could divide the values into 3 categories.
    But when I tested it on Teensy 3.2, it says "Error compiling for board Teensy 3.2 / 3.1.". My whole project has the Teensy as the brain, so i need it on Teensy. I would appreciate it a lot if someone could help me modify the libraries so I can use the same code on Teensy, or if someone suggests a code with which I can read the capacitive resistance of the copper pads

    Buttons.ino
    Code:
    #include <ADCTouch.h>
    
    int ref0, ref1;     //reference values to remove offset
    
    void setup() 
    {
        // No pins to setup, pins can still be used regularly, although it will affect readings
    
        Serial.begin(9600);
    
        ref0 = ADCTouch.read(A0, 500);    //create reference values to 
        ref1 = ADCTouch.read(A1, 500);    //account for the capacitance of the pad
    } 
    
    void loop() 
    {
        int value0 = ADCTouch.read(A0);   //no second parameter
        int value1 = ADCTouch.read(A1);   //   --> 100 samples
    
        value0 -= ref0;       //remove offset
        value1 -= ref1;
    
        Serial.print(value0 > 40);    //send (boolean) pressed or not pressed
        Serial.print("\t");           //use if(value > threshold) to get the state of a button
    
        Serial.print(value1 > 40);
        Serial.print("\t\t");
    
        Serial.print(value0);             //send actual reading
        Serial.print("\t");
    	
        Serial.println(value1);
        delay(100);
    }
    Thanks

  2. #2
    Senior Member
    Join Date
    Jun 2013
    Location
    Torrance CA
    Posts
    397
    The Teensy 3.x has built in hardware for capacitive touch sense and there's a working library (https://www.pjrc.com/teensy/td_libs_...iveSensor.html), can't you just use that?

    [edit] - See Paul's message below. I was on phone and picked a bad link. This one is better: http://njhurst.com/blog/01356576041
    Last edited by potatotron; 02-14-2017 at 06:29 PM.

  3. #3
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,354
    On Teensy 3.2, you'll probably get much better results if you use the special touch sensing pins with touchRead(pin). It's built in and works pretty much the same as analogRead(pin), except it reads the capacitance on the pin in 1/50th of a pico Farad. Dedicated hardware inside the chip does all the hard work, so it's fast and quite stable compared to the result you'd get with external resistors.

  4. #4
    Junior Member
    Join Date
    Feb 2017
    Posts
    4
    Quote Originally Posted by potatotron View Post
    The Teensy 3.x has built in hardware for capacitive touch sense and there's a working library (https://www.pjrc.com/teensy/td_libs_...iveSensor.html), can't you just use that?

    [edit] - See Paul's message below. I was on phone and picked a bad link. This one is better: http://njhurst.com/blog/01356576041

    Quote Originally Posted by PaulStoffregen View Post
    On Teensy 3.2, you'll probably get much better results if you use the special touch sensing pins with touchRead(pin). It's built in and works pretty much the same as analogRead(pin), except it reads the capacitance on the pin in 1/50th of a pico Farad. Dedicated hardware inside the chip does all the hard work, so it's fast and quite stable compared to the result you'd get with external resistors.
    Thanks for your quick replies. I can read the values now, but they are intersecting. For example, as in the figure, i have used resistors to get different values, but i can't categorize them because the results are very close to each other. What resistors do you suggest using between the 2 pads?

  5. #5
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    2,551
    No resistors!!! Connect each pad directly to a different (touch capable) pin of the Teensy and handle the readings in a loop. Teensy touch detection is purely capacitive via internal current sources/sinks. That means that each touch pin has already its own internal and individual pseudo-resistor and just detects the capacitance (change) of whatever is connected to that pin with high precision.

    That's why resistors have no place in teensy's touch sensing in opposite to other, older, and smaller/cheaper MCUs, where one pin is driven high at regular intervals to detect roughly the time delay of an external resistor-capacitor low pass on a second pin.

  6. #6
    Senior Member
    Join Date
    Jun 2013
    Location
    Torrance CA
    Posts
    397
    I don't think you can chain touch pads together with resistors using the Teensy's built in touchRead() like you can in your original schematic, at least I haven't seen anything like that before.

    There's 12 touch pins available on a Teensy 3.2, if you need more you use a matrix. Here's an example: https://hackaday.io/project/1397-36-touch-sensor-matrix

  7. #7
    Junior Member
    Join Date
    Feb 2017
    Posts
    4
    Greetings, in fact i need to use 30 pads, and i have 10 free analog pins. I think i will be using two MPR121 which give me 24 touch pads, and the rest i will put on analog pins. But i've used the primary SDA and SCL pins for IMU, can I use the secondary SCL and SDA pins of Teensy 3.2 (16 and 17) for two MPR121? Thank you

  8. #8
    Senior Member
    Join Date
    Jun 2013
    Location
    Torrance CA
    Posts
    397
    Yes you can specify the alternate pins by using nox771's I2C library, https://forum.pjrc.com/threads/21680...ry-for-Teensy3

  9. #9
    Junior Member
    Join Date
    Feb 2017
    Posts
    4
    Quote Originally Posted by potatotron View Post
    Yes you can specify the alternate pins by using nox771's I2C library, https://forum.pjrc.com/threads/21680...ry-for-Teensy3
    ohoho seems like a nice solution to the multiple i2c-s, will give it a try when i will get the MPR121-s. Thanks for your answer

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •