TOUCHE’ MEETS PD AND MAX/MSP
Touché is a capacitive-sensing technology developed by Walt Disney Research, which is able to provide touch and gesture detection to virtually any kind of object or surface. Unlike common capacitive sensing, which detects the capacitive load of a resonant circuit over a single frequency, Touché uses a variable frequency oscillator, taking many readings at many different frequencies. Outside world activity with the object can be then inferred by the resulting data profile.
The original paper is here.
DZL and Mads Hobye are 2 awesome guys @ Illutron which figured out a very clever way to implement this neat device using an Arduino and a bunch of very cheap and common passive components. They were kind enough to share their effort to the world here and here, and to make this wonderful instructable. So we decided to try and build the little thingie on our own and to interface it with two environments we love: PureData and Max/MSP.
Components list for the touché board:
|| Resistors: 10k, 1M, 3,3k
|| Capacitors: 100pf, 10nf
|| Diode: 1N4148
|| Coil / inductor: 10mH
We decided to build a separate board with standard PCB instead of an Arduino shield, to possibly make it portable on other microcontrollers or different layouts of the Arduino board (micro, mega and so on). These are the schematics:
and this is what we built:
The RED wire on the left is connected to pin 9, which will act as a variable frequency oscillator. The YELLOW wire carries the output signal and is connected to analog pin 0. The BLUE wire on the left is connected to ground. On the right side, the RED wire is attached to the object, while the BLUE wire may be connected to ground or to another object, depending on the applications.
The original implementation by Disney uses a very precise sine wave generator, while we have to live with a much less fancy square wave with lots of unwanted harmonics. As DZL found out this is not a major problem, since the signal picked AFTER the coil is stable enough to be used and processed.
The ATMEL processor of the Arduino provides three programmable hardware clocks, which can operate at the frequencies needed by Touché and thus provide the needed oscillating signal. Programming the hardware clocks of an Arduino is a bit trickier than writing your average sketch because we have to mess directly with the ATMEL registers. Please look at this very well made tutorial if you need further information. Basically what we did was to setup CTC mode for Timer1 and increment the compare register inside a for loop, in order to progressively swipe from the highest generable frequency (8MHz) to the lower ones.
The original project from DZL and Mads Hobye sends the digitized measures coming from analog pin 0 through the serial port in binary format. We decided to make things a little less efficient but more human (and patcher) readable using ASCII encoding. Each line of data is made by the frequency index, a space character, the measured value for that frequency and a newline character.
PureData and Max/MSP patches are very similar between them: they read the lines of data coming from the serial port, store the values into an array and find the index of the greatest value in the array. To detect a new gesture, the user has to perform it on the object and record the peak index as a reference. The closest reference to the new peak will then correspond to the detected gesture.
We decided to add an exponential moving average on the signal readings, in order to further reduce noise and improve detection consistency. For each frequency index i, the new value y at time n is calculated as follows:
y[i,n] = a * y[i,n-1] + (1 – a) * x[i,n]
where x[i,n] is the current reading and a is a factor ranging from 0 to 1. Little values of a mean little smoothing and fast updates, while great values of a mean lots of smoothing but very slow updates.
Both the detection and the smoothing algorithm are very simple yet cumbersome to write inside of a patcher language such as PureData or Max/MSP. We found it much easier to do all the data processing inside of the Arduino, outputting just index and value of the maximum for each iteration. It becomes impossible to plot the fancy graph, but the patches become a lot cleaner and we don’t clog the slow serial Arduino to PC communication with lots of unwanted data.
You can download the code for both versions (touche_graph and touche_peak, respectively) on our github repository.
Best from Stefanos
A possible scenario: Interaction Between Humans