Monday, May 08, 2017

Teensy 3.6 Basics: TouchRead

Overview
The Teensy 3.6 is able to use capacitive sensing through the included touchRead functions, which are part Teensyduino. Capacitive sensing can sense the capacitance of the human body as a data value, and requires a conductive element that forms the sensor. This could be a copper plate, antenna, or a piece of fruit / vegetable.

The sensor is simply connected to a touch input on the Teensy, shown in yellow on the pinout reference.

In this way, the Teensy 3.6 can easily accomodate up to eleven capacitive sensors. Depending on the type of sensor and physical configuration, many more can be multiplexed.





Hardware Setup
The hardware setup is simple. A sensor - in this case an apple - is connected to digital pin 0 of the Teensy 3.6, which is a touch pin.









Example 1 - Sending Capacitive Touch Values from an Apple as Serial Data
The touchRead function is used to read the value of the apple. This data is sent to the serial port, and displayed using the Arduino serial monitor. Minimum values might range from 800 - 1200. Maximum values might range from 2500 - 10,000. The sensor, power supply of the Teensy, grounding, signal noise and individual may all influence a reading.

Due to the large data value range, it is important to test out a capacitive touch sensor to determine the boundaries of expected values, so that the input can be scaled, constrained and mapped for use.












Example 2 - Sending Capacitive Touch Values from an Apple as MIDI Continuous Control Data
The touchRead function is used to read the value of the apple. This data is then scaled, and constrained, and then sent as a USB MIDI CC message if the reading has changed from the previous value.


Download here: http://milkcrate.com.au/_other/downloads/arduino/teensy_3_6_basics/TouchRead_Example_2/








Example 3 - Triggering a MIDI Note Using an Apple
When the apple is touched, a MIDI note on message is generated. When the apple is let go a MIDI note off message is generated.

A threshold value is used to set the point at which the note is triggered. A play flag variable allows the Teensy program to keep track of whether or not a note is currently playing, thereby avoiding repeated note on or note off events.

The value from the touchRead function is compared to the threshold value.

If the touch value is above the threshold and the note is currently not playing, then a note on event is generated and the play flag is set to 1 indicating that there is now currently a note playing.

If the touch value is above the threshold and the note is currently playing, no action is taken.

If the touch value is below the threshold and the note is currently playing, then a note off event is generated and the play flag is set to 0 indicating that there is not currently a note playing.

If the touch value is below the threshold and the note is currently not playing, no action is taken.


Download here: http://milkcrate.com.au/_other/downloads/arduino/teensy_3_6_basics/TouchRead_Example_3/








Example 4 - Triggering Two Different MIDI Notes Using Two Apples



A second apple is added to the setup, using digital pin 1.

When a given apple is touched, a MIDI note on message is generated. When the apple is let go a MIDI note off message is generated. Each apple has its own unique MIDI note, and is triggered individually. Chords can be played by touch both apples at once.

A threshold value is used to set the point at which the note is triggered. A play flag variable allows the Teensy program to keep track of whether or not a note is currently playing, thereby avoiding repeated note on or note off events.

The value from the touchRead function is compared to the threshold value.

If the touch value is above the threshold and the note is currently not playing, then a note on event is generated and the play flag is set to 1 indicating that there is now currently a note playing.

If the touch value is above the threshold and the note is currently playing, no action is taken.

If the touch value is below the threshold and the note is currently playing, then a note off event is generated and the play flag is set to 0 indicating that there is not currently a note playing.

If the touch value is below the threshold and the note is currently not playing, no action is taken.

Download here: http://milkcrate.com.au/_other/downloads/arduino/teensy_3_6_basics/TouchRead_Example_4/







Conclusion
Capacitive sensing can be an interesting addition to a control scheme, whether used as a continuous control or triggering events.

0 comments: