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
-----

Topics I've Started

Capacitive Touch Sensing

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.


Netduino as Arduino Due

24 November 2013 - 02:49 PM

Hello everybody,

 

I recently bought an Arduino UNO, after experimenting with my Netduino+2 for some months. The most important reason was speed, toggling a Pin on my Netduino @170MHz i would only get 35kHz at max, whereas the Uno would give me 8MHz. Now Arduino released the Due, which also uses ARM architecture, a Cortex M-3. Would it be possible to make the Netduino apperar as a Serial Port on the Computer and accept native Programs like a Due? Essentially it's a similar Processor, just with some more storage and an FPU + some other new features.

I don't mind loosing object-oriented programming at all, since I can just reupload Netduino Firmware again. But it would be nice to have at Serial and maybe Ethernet available.

For a start, it would already be a huge success if it would just 'work', without any libraries, timers, etc. set up (I'm fairly familiar with using registers for that now).

 

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.