Showing posts with label capacitance sensing. Show all posts
Showing posts with label capacitance sensing. Show all posts

Monday, May 08, 2017

Teensy 3.6 Basics: TouchRead

Note for Teensy 4.1: All of the ideas explored in this post are compatible with Teensy 4.1 with two changes: 
1) Teensy 4.1 must use the FastTouchRead library by Adrian Freed instead of the native TouchRead functions
2) The FastTouchRead library will return values in the range of 15 - 75 instead of the 1000s, so any scaling or thresholds will have to reflect this. 



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.

Tuesday, November 17, 2015

32 Capacitive Touch Sensors and Ableton Live





Hardware










The hardware is quite straightforward. Two 4067 multiplexers have a common address bus, going from Teensy 3.2 digital pins 0, 1, 2 and 3 to s0, s1, s2 and s3. Teensy 3.3v is connected to VCC on both multiplexers. Teensy ground is connected to both gnd and en on both multiplexers. Sig from multiplexer 1 goes to Teensy digital pin 23, and sig from multiplexer 2 goes to Teensy digital pin 22.

The 32 inputs across both multiplexers can be connected to conductive things, and used as capacitive sensors. 






Software 

The code is for Teensy3.x and Teensy LC, as it makes use of the TouchRead function and the Teensy's touch pins. The board should be set to USB MIDI mode in the Arduino IDE.



Download the code here: http://milkcrate.com.au/_other/downloads/arduino/touchReadMultiCC/touchReadMultiCC.ino




Data
Multiplexer 1 appears as MIDI CC1 - 16, channel 1 and multiplexer 2 appears as MIDI CC1 - 16, channel 2. This data can be easily sent to Max. An example patch is shown below.






----------begin_max5_patcher----------
630.3oc4WFtaaBCDG+yjmBj+bZD1P.xdUllpb.qF2AFjwzkzp9tO6yPJsMMw
fBoSZJRP8YG6+2ub9tqurvCssZOqA4+C+e5648xBOOvjwfW2XOTIceVAsAVF
Rv9S01GQKsSoX6Uf4ZIqlIx8aXp94DskUspBlB9h3NqVSpC0L6ohP9+papc7
7blX3hqoprcbwC2KYYJ652DtJXo+cQAlWIQlmDxpfiaBOGziVi2gC6kRi5PA
bdnAhiKNpMisWWrv7XoibnrsPwaJ34L4wSg+LbH33SR.R+xXJ8Yq2LqCANBl
jLvG9LiVNjSmfJjH.Kqs3HA1xT7fsrlJokLESdOSP2ZgQP2bYTQ9A8CvX5I3
Xfqbry3C6pZTaoRis0AS.te2AYtGis4+lPrYL.K8ej3qmK7krmPmEsW.biH7
BG.+tDt4bwWINhFx0iBRsKx7w9jSChvyBhoBiDfEqSOGKhcjEgWwLNzre6yM
etEIbvgVJb1LNjaOExTEbwHiF3BkIXXvqIQjXfH1LweYc9IjCF1Gj1s9X2Of
TL1eOlZpZkY89VWhe+2TSNqQwETEuRLXMouaMe1sK440UZzzIALY0ZyUAa15
9+9syf2XRrB98oS54p1SbP6wWP6WO0D6fZ1LIRFEYdMXvLvRi5wWP8lFQGi7
CI19OrxOXV0OwA5mbyhE9.o9BbFLxngfAWrHqmyaVXGjOYRwx3vgAyvnYR+X
GzO1c8S5qsA52VgaV0OwA8SFwkwvg7OJYD72VjgVW+DS1zIBP55ptOVAsulr
DFxE1gPGyHcSn790CM5inRc8Qkt3XqzVfaepsaHTYk9eOPzx6JvoO4WW7WPO
46ns
-----------end_max5_patcher-----------

Tuesday, November 10, 2015

Multiplexing Capacitive Sensors and TouchRead with Teensy

Multiplexing multiple capacitive sensors via a 4067 multiplexer works surprisingly well with a Teensy 3.2 and the TouchRead function. Data is clean, there is little noise or crosstalk (see image below) and the multiplexing doesn't necessarily need to be slowed down in order to accommodate the switching of sensors.