Strange behaviour with CapSense on Teensy 3.5

Status
Not open for further replies.

seahorseshoes

New member
Hi all,
I'm trying to control a project's audio volume and LEDs using capacitive sensing. Everything except the audio component was working fine when I was using an Arduino R3, so then I switched to a Teensy 3.5 + audio shield, and now I cannot for the life of me seem to get the (super basic!!) capacitive sensor working.

I'm using the CapSense library and I've stripped the code and hardware (below) down to its very basics, but I'm getting very strange readouts. Instead of sensing proximity, I generally seem to be getting a value of -2 (which I believe indicates a timeout) unless I directly press a resistor. And I mean press; a light tap doesn't do it.

It's especially weird because the readout for the response time when I'm not touching it is ~400 ms (see attached), whereas the default value for the CS_Timeout_Millis function is 2000 ms, so as far as I can tell, it really shouldn't be timing out.

The board is plugged into my laptop for power, which is plugged into a wall socket, so it should be adequately grounded, I think.

What I'd really like is to have the sensor start detecting the presence of a body from a distance, as it did when I had it set up with the R3 I know the T3.6 has hardware-based capacitive sensing abilities, but I went with the 3.5 because I need to control a bunch of LEDs so I thought its 5v tolerance would be useful. Should I have just gotten the T3.6? I didn't think this would be such an issue :(

Things I've tried:
- different resistor values from 1M to 40M
- using other pin combinations on the T3.5
- various other programs; the teensy itself seems to be working just fine!

Apologies in advance if I've missed something super basic, but any ideas you all may have would be greatly appreciated. Thank you! :)



Code:
#include <CapacitiveSensor.h>

CapacitiveSensor   cs_4_2 = CapacitiveSensor(30,29);        // 10M resistor between pins 29 & 30, pin 29 is sensor pin

void setup()                    
{
   cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF);     // turn off autocalibrate on channel 1 - just as an example
   Serial.begin(9600);
}

void loop()                    
{
    long start = millis();
    long total1 =  cs_4_2.capacitiveSensor(30);

    Serial.print("ms response time:");   
    Serial.print(millis() - start);        // check on performance in milliseconds
    Serial.print("\t");                    // tab character for debug windown spacing
    Serial.print("total value:");   
    Serial.println(total1);                  // print sensor output 1

    delay(10);                             // arbitrary delay to limit data to serial port 
}

capsense.jpg

View attachment serial output.txt
 
Haha, I'm glad I'm not the only one! And no, I actually ended up just returning the 3.5 and going with the 3.6, which meant re-designing other parts of the project around it. Sorry I couldn't be of more help!
 
Thanks for the reply @seahorseshoes. Sometimes it's hard to know if any of these posts get read.

For reference, I figured out a solution. Not sure if it's a bug in the library or not, but it's working for me. In case you ever use a Teensy 3.5, I detailed it at:

https://forum.pjrc.com/threads/62507-CapacitiveSensor-library-not-working-with-Teensy-3-5

Incredible work!! It may have come too late to help me with this project, but I'm really glad to know the problem wasn't just with my ability to implement it. This'll be a great reference for the future :)
 
Status
Not open for further replies.
Back
Top