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.

martin2250

Member Since 27 Jan 2013
Offline Last Active Oct 18 2014 01:40 PM
-----

#57740 Capacitive Touch Sensing

Posted by martin2250 on 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.




#47034 NETDUINO PLUS 2 NOT RECOGNIZED

Posted by martin2250 on 11 March 2013 - 08:40 PM

first of all, don't use caps, this will make this forum much nicer for everyone

 

i think redeploying the firmware should fix the problem, Chris has a pretty good tutorialon this.

 

Greetings




#46343 Character LCD On N+2

Posted by martin2250 on 27 February 2013 - 04:41 PM

hi

 

i am using both,  a N+2 and MycroLiquidCrystalLib and it seems to work for me, if the Display does not show any characters, or wrong ones you can try hooking up the positive supply input of your display to a GPIO and turn it on just shortly before initializing the display, you don't even need any delay. If I do this, it works 100% reliable for me.

 

Generally it should work without that, so try using standart settings at first

 

Note: be sure to use a transistor for the supplyinput of the display if it needs more than 25mA (Backlight)

 

Greetings




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.