CapSense library - stuttering

Hello - I've run into a bug using the CapSense https://playground.arduino.cc/Main/CapacitiveSensor/ library.

I have capacitance being detected above a threshold and setting another pin HIGH as a momentary switch, when it drops below the threshold (you're not touching the touch point anymore) the pin is set LOW. The idea being that the output pin is HIGH as long as your finger is on the touchplate (this is to provide a gate signal to an synth oscillator, which will sound as long as it receives a HIGH (5v) input to its gate)

It all works great whilst my arduino is connected to my laptop via USB but when I've tried powering it from the 5v supply the synth is running off I get regular periodic drops to 0v - as if the pin is resetting? This causes stuttering in the sound. Likewise if I monitor the output pin with an LED it flicks on and off.

I'm really confused - any ideas?

Without schematics I can only take a SWAG and say it sounds like you are having feedback through the synth via the power supply. Try using an opto isolator. Also you had the metal of the laptop that helps coupling that is not there.

Thanks for taking the time to answer.

I'll have a go at putting a schematic together.

Two experiments I've tried - completely independently of the synth - running from a barrel jack power supply (5v). Same result, this weird periodic 'reset to ground' pulse. With the USB power from the laptop everything is fine.

Also if I ground myself i.e. grab a lead connected to ground rail of my breadboard with the other hand then touch the capacitive contact it works same as when plugged in to the USB - no glitching.

I guess capacitive sensing is really sensitive to ground and somehow when it's plugged in via an external PSU (my synths rails or another wallwart) something is going wrong. I can't monitor the serial messages (capacitive touch above threshold or not) because that involves having the usb plugged in so the error isn't reproduced.

So an opto-isolator? On the power rails?

As promised. This is just my test - one sensor (really just grabbing a bit of wire) which should send pin 12 HIGH 9 (+5v).

#include <CapacitiveSensor.h>
CapacitiveSensor Sensor = CapacitiveSensor(4, 6);
long val;
int pos;
bool pressed;

void setup()
{
Serial.begin(9600);

pinMode(12, OUTPUT);
}

void loop()
{

val = Sensor.capacitiveSensor(30);
//Serial.println(val);
//Serial.println(pressed);

  if (val >= 1000)

{
pressed = true;

digitalWrite(12, HIGH);

delay(50);
}

else if(val <= 500)
{
digitalWrite(12, LOW);
pressed = false;
}

delay(50);
//

}

and (sort of) schematic

Really simple (as per capsense tuorials) - the 1M resistor goes between pins 4 and 6. When a bare wire is pressed with a finger at pin 6 then the code detects the threshold has been reached and pin 12 goes high and lights the LED.

Like I said it all works great - provided the arduino is plugged in to a laptop via USB. It must be a grounding thing but I just have no idea how to solve the problem if I want to embed the arduino in my synth as a module.

Just to be a bit clearer with the picture - the LED is grounded!

and it does have a current limiting resistor! I just left it off.

The opto-isolator would not be needed, you are picking up a ground field from the laptop. Placing some metal maybe a screen connected to the ground of the Arduino should fix it. If you can ground to earth that would probably be the best. I had wrongly assumed you were using a module of some type that gave you a digital output. You can test this by clipping a wire on the USB ground and the Arduino ground without plugging it in.

Why? You know about it but we don't know you know. That is rank bad behavior.

The capSense example is not a very robust method of creating a touch sensors.

Yes this is what people find all the time. The problem is your lack of a ground reference point for the charging capacitor.

Yes you are supplying a good solid reference that is normally supplied by the chassis of your computer.

Normally when I use a capacitave sensor, first I use a proper capacitave sensor chip. Search the AdaFruit website, they have a couple.

Then I use a grounded foil of adhesive copper strip close to the exposed contacts on the under side of the board.

Like in this project of a Hex Pad touch musical instrument

On the under side of these brass touch sensors I had this:-

Notice the underside, a copper foil ring runs round the outside, providing grounding.

Video

It is my son playing not me.

I'm sorry, I realised as I put it up and just didn't want to go back and post yet another picture.

Thanks for the tips - the adafruit MPR121 breakout looks good, I'm going to pick one up and give it a try.

OK fine. Have a look at what I edited my last post to. You were replying while I was editing.

You can always edit your posts using the pencil icon.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.