Go Down

Topic: One Pin Capacitive Sensor Library (Read 1 time) previous topic - next topic

makerman

I have created a one pin capacitive sensor library that supports multi-touch for the Leonardo (and UNO). You can download the library at: https://github.com/MrYsLab/OnePinCapSense

Paul Stoffregen

You might consider changing the name.  Sooner or later, you'll hear from Cypress Semicondutor who registered the trademark "CapSense" for their own capacitive sensing hardware+firmware.  I'm suspect Paul Badger's library pre-dates their trademark, but the reality is they're a big company with a well funded legal department, and Paul B (not me) wrote that library a long time ago and hasn't maintained it since.

If you do change the name, it might be worthwhile to begin with "CapacitiveSensor", perhaps "CapacitiveSensorOnePin"?  That way, when anyone makes an alphabetically ordered list of Arduino libraries, yours will appear right next to the old (but renamed) CapacitiveSensor library.

Paul Stoffregen

#2
Aug 08, 2013, 06:51 pm Last Edit: Aug 08, 2013, 06:56 pm by Paul Stoffregen Reason: 1
Also, in the code, you might consider disabling interrupts.  If an interrupt occurs anywhere between the instant you make the pin an input and the moment it reads high, your count will be less than it should be, because the CPU spent time updating the millis() count, or transmitting or received serial data, or updated servo motor pulses, or any number of other activities.

Of course, keeping interrupts disabled for a long time might cause those other activities to fail.

Another approach might involve using the 16 bit timer with input capture mode.  You'd configure it up to capture the rising edge while the pin is still driven low.  That way, you'd only need to disable interrupts for a very brief time, only while you change the pin to input mode and read the value of the timer (or set it to zero).   Then you could allow interrupts while you wait for the capture event.  The capture could even happen while an interrupt has the CPU.  The timer's rapidly increasing value gets captured to another register, which you can read at your leisure and use to report a highly accurate measure of the elapsed low->high time.

Then again, the input capture feature only exists on a single pin, so it's probably not so useful for more than just a single touch electrode.  :-(

makerman

Thanks for your comments. I am not sure what you mean by "Then again, the input capture feature only exists on a single pin, so it's probably not so useful for more than just a single touch electrode.  :-(".  You can create as many sensors as you have input pins available, and if you touch more than one sensor, you will get readings for all sensors touched.

Go Up