touchRead value bouncing all over the place

Ando_Shy

Member
Good day,

I am working with a motorized fader and have been trying to use to touchRead function as a way to interrupt the fader when it is in motion. I've been experiencing some odd (maybe) behaviour and although I have a work around I wanted to check if this is normal, if there is a problem with my use of touchRead or if maybe I need to improve my circuit. so here's the simplest form of the code that returns the result I'm talking about:

Code:
#define TOUCH_PIN A9

void setup() {
     Serial.begin(115200);
     pinModer(TOUCH_PIN, INPUT_PULLUP);
}

void loop() {
     int touchVAL = touchRead(TOUCH_PIN);
     Serial.println(touchVAL);

}

I am using a teensy 3.6 and I have the CPU speed (of the teensy) set down to 96MHz as some other parts of my code are unstable when it is running at 180MHz. But basically when the fader is not touched the touchRead function returns a value that is pretty stable around 3800 however, when I touch the fader the touchRead function returns a value that bounces between maybe 200-300 and to over 4000. For the moment I am averaging reads and for the most part it works because touchRead is very stable when not touched however, this introduces a slight delay from when I touch the fader to when it detects a touch. As the motorized fader in this project is mostly snapping from one value to another as quickly as possible I would like to get a more stable read from the touchPin so that, for example, the fader motor stops as quickly as possible if it slams into someone's finger.
As for the circuit I have the touch sense pin on the motorized fader going directly into the pin A9 on the teensy. The teensy is mounted inside an enclosure with a PC (motherboard, processor, GPU, power supply, etc) and the motorized fader is mounted to the outside of the chasis which is grounded. So maybe there is some interference going on? Any assistance on this would be greatly appreciated as I have not been able to find much documentation on the touchRead function.
Best regards,
-Andrew
 
TouchRead counts on you yourself being grounded to get stable readings, the more grounded you are the higher your touchRead value will be, at the same token the more grounded you are the slower touchReads become and your whole sketch slows down. If you are properly grounded your values should be well above 4000, I’ve found touchRead to be inaccurate at best for reading faders and that’s not to mention the problem of always having to be grounded to get good readings. There is external circuitry that can do a much better job of detecting touchs that doesn’t use a microcontroller and you don’t even need to be grounded in order for it to detect you. The best part is the touches can just be read like a regular button, either low or high with no threshold calibration, I happen to own a system that uses such a circuit for motorized faders so I’m going to be working on reverse engineering a schematic for it. It’s quite a few component for just reading touch, but it’s always been 100 percent reliable for me when I tested it vs touchRead.

Here’s pictures of the circuit, it’s only a 2 layer board so it’s pretty simple, but the only thing this whole board does is read the touch value, all the other wires you see are routed directly to the ribbon cables.
3B8E25B2-5E16-45F7-B1D1-E0F3C89910B9.jpg
52D8431C-49D7-4353-A856-7F344CC7FC35.jpeg
With this circuit if you really wanted to you could connect the output from the touch value and directly connect it to the enable pin on your motor driver chip without using the Teensy to turn it off. You would probably need an inverter to do this though since most chips are active low and this circuit outputs low when touched, but again that’s if you really wanted it to be as “real time” as possible.
 
Hey Vjmuzik,
Thanks again for the info! I was hoping I could find a simpler solution (even if it's quick and dirty) as things are already pretty cramped in my enclosure as it is and I need some space for cooling the CPU effectively. I don't care so much about accuracy but the problems is sometimes the touch values overlap the non touched values so even with a threshold I get false positives. Averaging gets rid of that but is far too slow as I still have the motor grinding for a few fractions of a second before it cuts. It really is just to protect the motor though, I'm not triggering reads with touch or anything like that. In any case I'll consider your solution and whether it fits into the scope of my project.
Thanks!
-Andrew
 
Hi joshnishikawa :) .. just picking up this older thread and wanted to send you my THANKY YOU, as I always use (and love) your library, works awesome, great ! fyi: Using your TouchSwitch (on-off_stable example)

The issue I have now: as The Teensy 3.2 (and LC) might no longer be supported (at least no chips available) it looks like that we have to migrate to e.g. Teensy 4.0, right ?. But 4.0 does not support touch pins. Do you have any plans to get you perfect Flicker Touch library running on those newer Teensy ? I cross my finger you have an idea, let us know.

Thanks !
 
But 4.0 does not support touch pins.

That pretty much says it. It's a pity. Capacitive sensing is such a useful feature! I guess the newer chips just don't do it natively.

I believe the CapacitiveSensing library would still work on the 4.x but it requires 2 pins and 2 resistors. Still, it would be worth adapting Flicker for it if that's what it comes down to. I haven't actually gotten my hands on a 4.0 or 4.1 for testing yet.

Of course there are very cheap dedicated chips like the CAP1206 that could be used but where would you put it? Real estate on the Teensy is at an absolute premium I'm sure. The best bet might be to convince PJRC to include a dedicated touch chip on the prop shield(s) or possibly create a new shield.
 
Thanks for feedback joshnishikawa ;) ..

.. in case the Touch Pins will not come back: maybe i would go the path with dedicated Touch chips (e.g. CAP1206 as you mentioned), because i am using a dedicated Breadboard anyhow, so i could include them there (see Dark Board), but i still hope the next Teensy generation will have them back again (allowing you to update of your Flicker library). What i did as mitigation for now: I ordered a dozen Teeny LC for now (summer back in stock), and cross my finger there will be a Teensy in future with Touch pins back)
 
Back
Top