Digistump Forums

The Digispark => Digispark (Original) Support => Topic started by: s0beit on April 28, 2014, 02:52:06 pm

Title: Capacitive Touch Sensor?
Post by: s0beit on April 28, 2014, 02:52:06 pm
Hey guys!

So im new to the digispark, just ordered 5 of them to get some models of my project going but i seem to have hit a stump. A main part of my project is using a capacitive sensing touch sensor.. Using my Arduino UNO i was able to use the CapactiveSensor library, but that does not seem to work with the digispark. I've browsed the forums and the internet for a while and it doesn't seem like anyone is trying this. Anyone know of a way where i can do this?

For an example of how i was doing it with my arduino, it is exactly as shown in the arduino starter kits touchy-feely lamp

i am devoting the entire digispark to controlling 2 touch sensors so all pins are available

Please help, im puzzled...
Title: Re: Capacitive Touch Sensor?
Post by: gogol on April 29, 2014, 12:51:55 am
Can you post a minimized demo sketch, which works on the UNO and does not in the digispark?
For used libraries, which are not part of the Arduino-IDE refer the source and version.
Title: Re: Capacitive Touch Sensor?
Post by: s0beit on April 29, 2014, 10:58:36 am
Heres a link to the library (Version 4 btw) from arduino

http://playground.arduino.cc/Main/CapacitiveSensor

And here is a snippet of a sample sketch i used on my uno.

#include <CapacitiveSensor.h>
CapacitiveSensor moveSensor = CapacitiveSensor(3,5);
CapacitiveSensor touchSensor = CapacitiveSensor(8,10);
const int irrelevant = 100;

void setup() {
}

void loop() {
  long moveValue = moveSensor.capacitiveSensor(30);
  if (moveValue > irrelevant) {
    blah blah blah
  }
  long touchValue = touchSensor.capacitiveSensor(30);
  if (touchValue > irrelevant) {
    blah blah blah
  }
}
Title: Re: Capacitive Touch Sensor?
Post by: s0beit on April 29, 2014, 01:17:45 pm
also just to note..

I have looked into other options, such as 555/NE556 or using transisters.. however, the trade off of keeping my pcb design small with only 1 resistor and a library is way more ideal then 2 trans, 2 resistors || using a NE556...
Title: Re: Capacitive Touch Sensor?
Post by: MichaelMeissner on April 29, 2014, 07:16:52 pm
If you can't get it to work on the Spark, I noticed that Adafruit has an i2c Capacitive touch sensor for $8 + s/h: https://www.adafruit.com/product/1602 (https://www.adafruit.com/product/1602)

Also note, ATmel says that the ATtiny85 (chip inside of the digispark) does have 3 touch channels: http://www.atmel.com/devices/ATTINY85.aspx (http://www.atmel.com/devices/ATTINY85.aspx), and there is a QTouch library available (but I don't know anything more than that).

I know some of the Arm chips also have touch sensing.
Title: Re: Capacitive Touch Sensor?
Post by: gogol on April 30, 2014, 06:40:08 am
After looking to the library, I think, that it should work with the digispark without any problems.

I would connect  pin0 for send and pin2 and pin5 for receive (two sensors).

As pin1 has the LED connected, pins3-4 have the zeners for USB, those pins may interfere with the capacity-measurements.
Title: Re: Capacitive Touch Sensor?
Post by: s0beit on April 30, 2014, 10:10:03 am
After looking to the library, I think, that it should work with the digispark without any problems.

I would connect  pin0 for send and pin2 and pin5 for receive (two sensors).

As pin1 has the LED connected, pins3-4 have the zeners for USB, those pins may interfere with the capacity-measurements.

i have rearranged my sketch a little bit and rewired everything and i have come to realize that, gogol, you sir, you are a genius, and a life saver of course! it must have been those zeners messing with my signal before... i cant believe i didnt think of that =\

thank you so much...

and thank you as well michael, i never thought about the qTouch library.. honestly, had gogol not been able to figure it out, i probably would have went in that direction. Thank you both! and thank you digispark!
Title: Re: Capacitive Touch Sensor?
Post by: MichaelMeissner on April 30, 2014, 11:29:19 am
You are welcome.  I'm glad it is working.
Title: Re: Capacitive Touch Sensor?
Post by: gogol on May 02, 2014, 12:15:52 am
Glad that it works!
The digispark has a lot of limitations, as there are only 6 available pins. So the pinout documentation from semicolo (http://digistump.com/board/index.php/topic,455.msg3963.html#msg3963) is really helpful, when making decisions for pin-usage.
The new digispark PRO has for sure much more flexibility!