Touch sensor testing

Jeff Haas

Senior Member
I've been trying out the built-in touch sensor commands, and tested a few different touch pads to see what (if any) difference there was between materials.

I tried out a solder blob (ala Erco - see his first video in post 5: https://picaxeforum.co.uk/threads/self-calibrating-touch-on-m2.31620/), aluminum tape and copper tape.
I looked at a couple of videos on soldering to aluminum, but I can't make it work. I've ordered some liquid flux and will give that a try. Right now the wire is just taped to it.

25615

Top left: Solder blob
Right: Strip of copper tape, aluminum tape
Bottom left: Copper tape soldered into a square.

The manual suggests a 15mm x 15mm pad on the back of plastic. The yellow and black are leftovers from my 3D printer. The narrow strip of copper works but is hard to hit.

Copper tape is pretty easy to find, gardening stores have it. Here's how it's used:

I didn't see that much difference between the materials. The main thing you need to do in your code is determine the "ambient" level of reading and then set the detected level at the right number. I used the suggested code with some additions. The debug statements help you figure out what the right numbers are.

Code:
symbol LED = C.2
symbol ReadTouch = 5700

#no_data

main:
touch16 C.1, w0 ; read value into w0
'debug  ' Remove for final

if w0 > ReadTouch then
    high LED ; output C.2 on
else
    low LED ; output C.2 off
endif

'pause 10  ' Slows down debug display update, remove for final

goto main ; else loop back to start
 

erco

Senior Member
Nice! Touchpads are fun to mess around with. The readings can change a lot over time, periodic auto-recalibration would be a good idea.

This was fun, using pennies as sensors, behind a layer of clear tape:



Of course these hardware switches are cheap and abundant. IIRC some of them can be converted to toggle easily. https://www.ebay.com/itm/254255700734
 

steliosm

Senior Member
I did some touch buttons using copper tape on the back of a plywood sheet for a project I built a few years back. Each pad would be around 2x2cm bit. I had cables about 8-10cm going from the touch pads (5 in total) to the Picaxe. I didn't work correctly. There was cross-talk between the touch buttons, mainly due to the cables being too close to each other, and the touch sensor's sensitivity would change during the day. I had to switch to ttp223 touch sensors to make it work properly.
 

Jeff Haas

Senior Member
I've been digging up older posts on touch pads, and this one from Hippy on making them adaptive caught my eye (see post #6):

Along with #2 here:

I thought I had set this up right but I can't get it working. I could use a bit of help here.

Code:
symbol LED = C.2
symbol TouchThreshold = 70
symbol Baseline = w0
symbol Detect = w1
symbol Increase = w2
symbol PctIncrease = w3

#no_data

Init:
touch16 C.1, Baseline        ; store baseline at power on


Main:
touch16 C.1, Detect        ; detect touch
debug

; check to see if detection is higher than baseline
Let Increase = Detect - Baseline   
Let PctIncrease = Increase / Baseline
Let PctIncrease = PctIncrease * 100

if PctIncrease > TouchThreshold then
'if Increase > TouchThreshold then
    
    high LED
    pause 50

else
    low LED
    'touch16 C.1, Baseline    ; Update baseline to current environment
    
endif

pause 10
goto Main
The code above doesn't show any values for PctIncrease in the Debug window. If I swap "if Increase > TouchThreshold then..." for "if PctIncrease..." it works but that's the basic implementation.

Also uncommenting the line in the else section that updates the baseline overflows Increase.
 

inglewoodpete

Senior Member
Two points that I found when working with the Touch command (on a 28X2).
  • All Touch pins do not give the same response to a touch. It's best to try various pins and select accordingly.
  • The response of pins changes when other pins in the same port are set high or low. The change in sensitivity may be related to the current flowing in or out of the other pins in that port.
 

Jeff Haas

Senior Member
Forgot to mention I worked this out on a spreadsheet, I just can't get the same results on the Picaxe.

25621

"Touched" at B7 uses an Excel IF formula: =IF(B4 >B6, "Touched", "Not") so I can play with the Detect and Threshold values.

"Touched" at B17 uses =IF(B16 >25, "Touched", "Not touched").

I can't get PctIncrease to show in Debug on the Picaxe. Then the next step is to resample the baseline, making it adaptive.
 

erco

Senior Member
Cheap premade touch switch arrays come in 4, 8 and 16 button flavors AFAIK. Very sensitive, my only complaint is the pads are too small and too close together.

 
Top