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!
View attachment serial output.txt
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
}
View attachment serial output.txt