Sunday, November 15, 2015

How does the Tooba's keyboard work?

The question I was most frequently asked when exhibiting the Tooba was about how the keyboard works. I was asked this by people who were obviously intelligent, and I have a deep understanding of it myself, so you would think there would be no problem in communicating it.

The short answer is, when you touch the copper contact, its effective capacitance increases, causing a change in an RC time constant which can be quickly measured with very simple electronics. The problem is that nearly zero otherwise intelligent people in our society understand capacitance.

I tried several different ways to explain this to people. Usually I said, "it works the same way as the touch screen on your phone", and that's true but it doesn't explain anything. It only gives people a known reference point to indicate that it's not physically impossible.


Capacitance is actually a pretty straightforward idea. You have two parallel metal plates. A battery or some other force pulls electrons out of one plate and pushes them into the other, so the first plate becomes positively charged and the second plate becomes negatively charged.

Opposite charges attract, so there is a force pulling the plates together, but they are mechanically held apart, usually by a layer of insulating material. The attractive force therefore acts upon the charges themselves, the excess electrons in the negative plate and the "holes" where electrons are missing in the positive plate. The negative and positive charges want to stay where they are, a bit like inertia, and this manifests as a measurable voltage difference between the plates. The only way to change that inertia is a current, a flow of electrons, into one plate and out of the other. A flow of 6.24x1018 electrons per second (or one coulomb per second) is one ampere.

Capacitors can be big or small. Capacitance is the size C measured in farads. Great, what the hell does that mean? Remember that the inertia of charge is measurable as a voltage V. The amount of charge is Q, the number of coulombs originally pumped into the plates by the battery. Then the magic formula is Q = C x V, or V = Q / C. How this pertains to the Tooba is that if Q is the same and C gets bigger, then V gets smaller.

Here is the touch-sensor circuit in the Tooba. The input on the left and the output on the right are I/O pins of the microcontroller. The left one is an output that drives electrons into and out of the capacitor, and the right one is an input to measure the voltage on the capacitor. It's a crude measurement, just a comparison to a threshold voltage that gives a zero or one.

BRIEF DIVERSION: In electronics, current is actually the direction opposite to how electrons are moving. This backwards convention is (no kidding) because Benjamin Franklin didn't have know whether the carriers of charge were positive or negative; the observable behavior was the same to him. He guessed, with a fifty-fifty chance of getting it right, and got it wrong. His mistake got codified into all of electronics, forever and ever, amen.

The output on the left is set to logical zero for a little while. The diode quickly discharges the capacitor to the same low output voltage representing a logical zero. Then the output is set to logical one, a higher voltage. The current flows to the right, against the direction of the one-way diode, so all the current flows through the resistor which slows down the movement of electrons. Here's the tricky part: if the capacitor is small, the voltage rises quickly, and if the capacitor is large, the voltage rises slowly. After a certain fixed amount of time, the voltage will just cross the zero-one threshold if your finger was not touching the copper, and the input will read a one. But if you touched the copper, the voltage will rise too slowly and the input will read a zero.

There is one more tricky bit to this. You may have been told in school that you always need to complete a circuit. Pushing current into the top of the capacitor would require that the bottom of the capacitor is connected to the ground in the Tooba. It turns out that capacitors are the one exception to this "complete the circuit" rule. You can (briefly) push current into a single plate and it will behave like a capacitor even without a second plate. That's why you can play the Tooba (or use the touch screen of your phone) without having a wire attached to you to complete the circuit.

Addendum - a friend read this post and wrote:
There's a missing piece in your explanation of capacitance: yes, the negative and positive charges do attract one another, but the charges in each plate also more strongly repel the same-sign charges in that same plate. That creates a restoring force that tries to push current back through the circuit to discharge the capacitor. 
The greater the capacitance, the smaller this net restoring force is. (You can think of a capacitor of higher capacitance as giving more room for the charges to spread out so they're not so crowded, or putting the plates closer together so that the "inertial" attraction across the gap is greater, or both.) 
If you touch one plate, a teeny bit of the charge can flow into your finger, or charges can become polarized in your finger so that some of the electric restoring force is cancelled out. Either way, it increases the capacitance by relieving some of the electric back-pressure through the circuit. And that's why you don't have to complete a circuit yourself.