Welcome to the Parallax Discussion Forums, sign-up to participate.

# Can smart pins be capacitive touch inputs?

Posts: 54
I know the P1 had an object that could emulate capacitive touch inputs with just a resistor, so i figure with the smart pins expanded capabilities the resistor might become unnecessary and capacitive sensing could be a built in feature, more or less

• Posts: 11,944
Absolutely! You could configure a pin to be a Schmitt relaxation oscillator with 150k-ohm or 10uA drive. Use the associated smart pin logic to measure frequency. As something gets closer, it will increase the capacitance and lower the frequency. There are a bunch of other ways you could measure nearby capacitance, but that seems like a simple one. You'll need to write some code to filter the frequency changes, in order to get some hysteresis for your output decision. Or, let it be continuously variable.
• Posts: 54
Neat! Can the schmitt relaxation oscillator generate an interrupt if the frequency drops below a threshold?
• Posts: 11,944
edited 2019-08-22 - 21:57:00
Actually, there is a smart pin mode that does that:
%10010 AND Y[2] = Timeout on X clocks of missing A-input high/rise/edge

If no A-input high/rise/edge occurs within X clocks, IN is raised, a new timeout period of X clocks begins, and Z maintains a running count of how many clocks have elapsed since the last A-input high/rise/edge. Z will be limited to \$80000000 and can be read any time via RDPIN/RQPIN.

If an A-input high/rise/edge does occur within X clocks, a new timeout period of X clocks begins and Z is reset to \$00000001.

X[31:0] establishes how many clocks before a timeout due to no A-input high/rise/edge occurring.

Y[1:0] establishes A-input high/rise/edge sensitivity:

%00 = A-input high
%01 = A-input rise
%1x = A-input edge

During reset (DIR=0), IN is low and Z is set to \$00000001.

I would recalibrate the thing periodically, though, to get rid of drift due to temperature or voltage change.
• Posts: 8,354
Software will be sampling the frequency value anyway, I'd just add a software check for low threshold.
We have the vastness of the internet and yet billions of people decided to spend most of their time within a horribly designed, fake-news emporium of a website that sucks every possible piece of personal information out of you so it can sell it to others. And they see nothing wrong with that.
• Posts: 217
What kind of range/resolution might this be capable of?
I'm thinking that this might be usable like an Encoder wheel.

If my application only needed 180 deg of turn (back and forth) and I used several pins, do you think this would be viable?

Jason
• Posts: 8,354
edited 2019-08-22 - 23:06:52
Jason,
Controlling drift/accuracy will be the key. It'll depend a large amount on mechanical construction of the transducer. And presumably also requires controlling the dielectric properties for best results. Resolvers are the more robust way.

EDIT: That said, If you can find an old AM/FM radio with one of those mechanical tuners then the variable capacitor used for tuning is pretty much exactly 180 deg turn. And as long as you can keep the grime out then it won't drift. Not designed for lots of motion though.
We have the vastness of the internet and yet billions of people decided to spend most of their time within a horribly designed, fake-news emporium of a website that sucks every possible piece of personal information out of you so it can sell it to others. And they see nothing wrong with that.
• Posts: 54
@thej using just 8 pins and a pcb with copper pours you can get something like an old school ipod touch wheel: https://hackaday.io/project/1395-open-source-science-tricorder
From what i can tell, the IC being used for sensing doesn't do anything special to make it work, all the calculation are done on the arduino in the project, which is convenient as you can just grab the code.