Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Capacitive Touch Sensing

sense capacity capacitive

  • Please log in to reply
2 replies to this topic

#1 martin2250

martin2250

    Advanced Member

  • Members
  • PipPipPip
  • 37 posts
  • LocationGermany

Posted 24 April 2014 - 10:06 PM

Hello guys, I just wanted to share this little piece of code I threw togehter, it will read a value from a capacitive sensor. The best part is: it only uses one (analog) pin.

 

to use the code as it is shown here, connect A0 to ground via a short piece of wire and connect a piece of wire to A1 which is used to detect a nerby conductive object. If you connect a large conductive surface to the sense wire, it will be more sensitive.

 

It works in the following steps:

  • create input, set it to pullup to charge the pin.
  • discharge the internal ADC capacitor by reading an analog input that's connected to ground via a wire
  • dispose the input, set it to tristate (=no pullup/down resistor) beforehand
  • create analog input, read it, dispose it

this pattern is repeated more than 100 times and the average is calculated to give more accurate results.

 

the code looks like that

public static int read()
{
	AnalogInput zero = new AnalogInput(AnalogChannels.ANALOG_PIN_A0);
	int ret = 0;
	for(int y = 0; y < 400; y++)
	{
		InputPort charge = new InputPort(Pins.GPIO_PIN_A1, false, Port.ResistorMode.PullUp);
		Thread.Sleep(1);
		zero.Read();
		charge.Resistor = Port.ResistorMode.Disabled;
		charge.Dispose();
		AnalogInput input = new AnalogInput(AnalogChannels.ANALOG_PIN_A1);
		ret += input.ReadRaw();
		input.Dispose();
	}
	zero.Dispose();
	return ret / 400;
}

in order to use it for a different input, you need to change both the charge and the input pin.

 

It works by distributing the charge between the (charged) capacitor formed by the input pin and the (discharged) capacitor inside the ADC, so it makes use of the internal structure of the chip.

 

with no wire connected it gives me a perfectly constant value of 1699, it goes up by two when I put my finger on the header.

 

with a large metal plate connected, just putting my hand under the desk (~3cm thick) will result in a change of over 200. Touching it with just a bit of insulation in between results in an even bigger change.

 

 

This particular way to abuse an ADC works better on an Arduino, but on the Netduino, it's the only way I have found to work at all, since it is too slow for the normal resistor + time measuring way of doing it. I am using a Netduino Plus 2, with the older models that have less bits on the ADC it will be less accurate.

 

anyways, I hope you found it useful for something,

 

Greetings.



#2 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 25 April 2014 - 04:06 AM

Martin, the idea is really valuable, but I'd warn about the hardware section before someone damage its board.

Touching an open (i.e. floating) pin is one of the easiest way to burn the input stage, because even a weak electrostatic charge can be disruptive.

 

I see you're in Germany, so I believe there is not so much different than here in Italy. When I wear rubber shoes and some wool short, I notice that my body charges a lot of electrostatic energy, then often it's discharged toward some grounded shield. When I see a 1cm-spark it means that's a roughly 2000V-spark!

 

My suggestion is to add an high value resistor in series to the pin. Try with 1Meg or even higher.

Also, more important, a couple of diodes (e.g. 1N4148) from the pin to the ground and +3.3V, respectively. Their aim is to short any too-high or too-low voltage to the positive and negative rail, respectively.

 

Again, it's NOT a critic to your project! It's just to avoid some dirty effect and a Netduino (or Arduino) to throw away.

Good luck!


Biggest fault of Netduino? It runs by electricity.

#3 martin2250

martin2250

    Advanced Member

  • Members
  • PipPipPip
  • 37 posts
  • LocationGermany

Posted 25 April 2014 - 10:49 AM

Hi Mario,

 

your concern is very appropriate, an electrostatic discharge will very likely do damage, and the limiting diodes are a very good addition. I don't know about STMicros controllers, but at least AVRs do have internal clamping diodes. Some external diodes won't do harm though (decrease accuracy a bit though).

Although the capacitances are in the range of 50pF, a large value resistor does decrease the sensitivity dramatically.

 

Normally, you'd have the sensing plate behind a dielectric to prevent arcs alltogether or use an actual sensing IC.

 

Anyways, this is of course more of a proof-of-concept and not really feasible for anything that is supposed to last.

 

Greetings,

Martin







Also tagged with one or more of these keywords: sense, capacity, capacitive

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.