Skip to content

Conversation

@nickzoic
Copy link

@nickzoic nickzoic commented Jan 27, 2019

A much-simplified approach to touch sensing for #1048 !

This is a capacitive touch sensing routine using a single digital
pin. The pin should be connected to the sensing pad, and to ground
via a 1Mohm or thereabout drain resistor. When a reading is taken,
the pin's capacitance is charged by setting it to a digital output
'high' for a few microseconds, and then it is changed to a high
impedance input. We measure how long it takes to discharge through
the resistor (around 50us), using a busy-waiting loop, and average
over N_SAMPLES cycles to reduce the effects of noise.

@nickzoic
Copy link
Author

nickzoic commented Jan 27, 2019

Manually tested on Feather NRF52832 and Feather NRF52840 Express boards, with code like:

import board
import touchio

t0 = touchio.TouchIn(board.A0)
t1 = touchio.TouchIn(board.A1)

while True:
    print("%4d %d %4d %d" % (t0.raw_value, t0.value, t1.raw_value, t1.value))

@tannewt
Copy link
Member

tannewt commented Jan 27, 2019

How about auto setting a threshold on object creation? That's what the SAMD does already. That way folks don't need to set it themselves before using it.

@nickzoic
Copy link
Author

nickzoic commented Jan 27, 2019 via email

@nickzoic
Copy link
Author

Threshold is now automatically set: I've adjusted the example code accordingly.

@nickzoic nickzoic requested review from dhalbert and tannewt January 28, 2019 07:24
Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Thank you!

@tannewt tannewt merged commit 765d877 into adafruit:master Jan 28, 2019
@ladyada
Copy link
Member

ladyada commented Feb 1, 2019

tested, works well - thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants