Jump to content


Photo

[Energia Library] Capacitive Touch library


  • Please log in to reply
17 replies to this topic

#1 energia

energia

    Level 4

  • Members
  • 932 posts


Posted 04 January 2013 - 05:17 PM

[Edit: New library attached with a bug fix for CapTouch on port 1 in combination with Serial]
Attached Attached File  CapTouch.zip   7.84KB   664 downloads is a capacitive touch library for the MSP430. All examples are written for the capacitive touch boosterpack (http://www.ti.com/tool/430boost-sense1). If you do not have one of these then it's fairly simple to create a capacitive sensor from a bare piece of PCB. Just solder a wire to it and hook it up to one of the pins. The library is based on the relaxing oscillator method. Each of the MSP430 pins can be connected to the internal relaxing oscillator peripheral called PinOsc. The PinOsc is a comparator based relaxing oscillator that changes frequency based on a change in capacitance. The idea is to "measure" the capacitance by counting the number of relaxing oscillator cycles during a fixed amount of time. The time during which we measure is called the gate time. So we need a counter to count the number of cycles and a timer to set the gate time during which we count. In this case the watchdog timer in interval mode is used as the gate timer and the capture compare feature of Timer0 is used as the counter. To trigger a measurement, the watchdog timer is set to a certain gate time, the counter start running and the MSP430 is put into LPM3. When the watchdog triggers, the MSP430 wakes up and triggers the capture of the Timer0 counter.
 
There is a lot more to it than this though such as baseline tracking, threshold, etc. If you would like to get to the details then I recommend reading the following literature:
 
 
There are 4 examples included in the library to show how to use the API's. To install the library, unzip the attached and copy it to a folder called libraries in you Energia Sketch folder. 
 
API:
Include CapTouch.h in your Sketch.
 
CapTouch(uint8_t pin, uint8_t sensorType);
 
Description:
Creates a CapTouch instance and calculates the baseline.
 
Parameters:
pin: The pin to use as a capacitive touch or proximity pin.
 
sensorType: This is either TOUCH_PROXIMITY for a proximity sensor or TOUCH_BUTTON for a button.
 
void setThreshold(uint16_t threshold);
 
Description:
Sets the threshold that needs to be exceeded for the button to be considered as touched. See isTouched() for more details.
 
uint16_t getBaseline();
 
Description:
Returns the the current baseline value of the last measurement of the untouched sensor. Note that a call to this library does not trigger a measurment.
 
uint16_t getMeasured();
 
Description:
Returns the measured value of the last measurement of the sensor. Not that a call to this library does not trigger a measurment.
 
int16_t getDelta();
 
Description:
Returns the difference between the baseline value and the las measured value. Note that a call to this function does not trigger a measurement.
 
uint8_t isTouched();
 
Description:
If the the difference between the baseline (untouched sensor) and the measured value exceeds the threshold then the button is considered to be touched.
A call to this function triggers a measurement of the sensor.
 
Returns 1 if the sensor is touched otherwise 0.
 

  • bluehash, pine, neirons and 6 others like this

#2 energia

energia

    Level 4

  • Members
  • 932 posts


Posted 04 January 2013 - 05:32 PM

As a make shift sensor, a wire and tin foil does wonders as a proximity sensor ;-)


  • sirri likes this

#3 VirtualEnder

VirtualEnder

    Noob Class

  • Members
  • 9 posts

Posted 24 January 2013 - 06:50 PM

Awesome thanks so much for this!  Will this be included in the next Energia release?  Been waiting for this for a while!



#4 energia

energia

    Level 4

  • Members
  • 932 posts


Posted 29 January 2013 - 12:09 AM

We have not yet decided what the distribution mechanism will be going forward but whatever it will be, we will include as many libraries as possible.



#5 dany_mar24

dany_mar24

    Noob Class

  • Members
  • 7 posts
  • LocationMexico

Posted 09 March 2013 - 04:24 AM

hi, i have just downloaded Energia, and i have to say it is amazing, and i downloaded this library but i cant get it to work with the msp430g2231, i just change the options in the example to the pin 1.7 and 1.4, but it only keeps the red led on, can u help me with this or upload an example for 2231?



#6 chunterosa

chunterosa

    Noob Class

  • Members
  • 1 posts

Posted 20 March 2013 - 11:51 AM

how difficult do you think it's going to be for me to learn how to turn this into a serial mouse??? it's the goal i set out for myself, i had some experience with the arduino before i killed it last year, and now i'm refreshing again, but still extreme noob in terms of trying to understand whats going on with the cap sense stuff.  



#7 Raul

Raul

    Noob Class

  • Members
  • 1 posts
  • LocationMexico

Posted 26 July 2013 - 06:46 AM

 
I can not make use of the center sensor connected to P2_5


#8 mikikg

mikikg

    Noob Class

  • Members
  • 1 posts
  • LocationSerbia

Posted 15 October 2013 - 07:56 AM

Hi to all, just few questions, is it possible to use this library with Stellaris or LM4F120 based LaunchPads?

Is there any other HW or SW requirements to get this working on Stellaris + 430BOOST-SENSE1?



#9 fretless

fretless

    Noob Class

  • Members
  • 2 posts

Posted 29 December 2013 - 07:11 PM

Does anyone have the problem of serial not working when using this library? The example works fine, but as soon as you change anything it starts outputting weird messages. To replicate try changing CapTouchRaw example's 

 

#define PROXIMITY_SENSOR P2_0

 

to

 

#define PROXIMITY_SENSOR P1_3 



#10 yosh

yosh

    Level 2

  • Members
  • 207 posts
  • LocationGermany

Posted 28 March 2014 - 08:24 AM

@energia thanks for posting this lib.

 

I got CapTouch working for Pins 2.x without problems, but not for Pins 1.x (e.g. 1.0, 1.3, 1.4, 1.5, 1.6 and 1.7 - I need 1.1 and 1.2 for serial).

 

I'm using a Rev. 1.5 LP with G2553 and Energia 0101E0012. Of course I removed the jumpers for 1.0 and 1.6.

Serial output:

Delta on P1.0: 32766 //never changes
Delta on P2.1: 264 //working, here: not touched
Delta on P2.4: 8340 //working, here: touched
Delta on P2.6: -3 //working, here: not touched

Am I missing something?

 

 

Best wishes

yosh



#11 rustw

rustw

    Noob Class

  • Members
  • 4 posts

Posted 03 April 2014 - 11:43 PM

@energia thanks for posting this lib.

 

I got CapTouch working for Pins 2.x without problems, but not for Pins 1.x (e.g. 1.0, 1.3, 1.4, 1.5, 1.6 and 1.7 - I need 1.1 and 1.2 for serial).

 

I'm using a Rev. 1.5 LP with G2553 and Energia 0101E0012. Of course I removed the jumpers for 1.0 and 1.6.

Serial output:

Delta on P1.0: 32766 //never changes
Delta on P2.1: 264 //working, here: not touched
Delta on P2.4: 8340 //working, here: touched
Delta on P2.6: -3 //working, here: not touched

Am I missing something?

 

 

Best wishes

yosh

All of the pins on Port 2 do not have analog functionality.

 

Refer to the Cap Touch Booster pack docs at www.ti.com/lit/ug/slau337b/slau337b.pdf‎ where there is a very little note about this in section 3.2 that mentions something about this. You may only need to add resistors to make it work properly.

 

I have not tried this (only used Port 2 pins), so I would like to know if this solves your problem.

 

Wayne



#12 yosh

yosh

    Level 2

  • Members
  • 207 posts
  • LocationGermany

Posted 04 April 2014 - 05:45 AM

Hi @rustw,

 

@energia found the bug, see here.

 

Kind regards

yosh



#13 chicken

chicken

    Level 4

  • Members
  • 832 posts

Posted 30 May 2014 - 12:06 AM

Just found this short article demonstrating the use of the CapTouch library together with conductive paint.

http://macetech.com/blog/node/124

 


  • Rei Vilo likes this

#14 zenki

zenki

    Noob Class

  • Members
  • 1 posts

Posted 21 February 2015 - 08:09 PM

I have found the example code is not working well. The LED light will directly turn on after programming. It doesn't need to sense. So what is the problem here? If anyone has met this before, please tell me how to solve it. Thank you very much.



#15 benbergman

benbergman

    Noob Class

  • Members
  • 5 posts

Posted 01 April 2015 - 02:44 AM

Will this library + examples work with the new MSP432 launchpad when coupled with the 430BOOST-SENSE1 boosterpack? It seems the 432 has cap sensing on all GPIO.



#16 MarkV

MarkV

    Noob Class

  • Members
  • 9 posts

Posted 07 August 2015 - 04:09 PM

With energia16 and launchpad msp430g2 p1 jumpers removed m430g2553 chip the proximity sensor returns too many false positives to be useful on all demo examples.

I tried setting the threshhold to 250 and 300 but still have the same problem.
Any suggestions?
 
 proximity.setThreshold(150);
  
  Serial.begin(9600);
}


void loop() {
  scanButtons();
  scanProximitySensor();
  ledSequence();
}


void scanProximitySensor() {
    digitalWrite(MIDDLE_LED, HIGH);
    while(!proximity.isTouched());
    Serial.print("proximity touched: ");
    Serial.println(proximity.getBaseline());
    digitalWrite(MIDDLE_LED, LOW);    
}


proximity touched: 50874
proximity touched: 50874
proximity touched: 50874
proximity touched: 50874
proximity touched: 50932
proximity touched: 50932
proximity touched: 50932


raw
State: 0 Base: 55684 Measured: 55661 Delta: 24
State: 0 Base: 55683 Measured: 55657 Delta: 27
State: 1 Base: 55683 Measured: 54950 Delta: 733
State: 0 Base: 55682 Measured: 55663 Delta: 20
State: 0 Base: 55681 Measured: 55674 Delta: 8
State: 1 Base: 55681 Measured: 55004 Delta: 677
State: 1 Base: 55681 Measured: 54946 Delta: 735
State: 0 Base: 55680 Measured: 55642 Delta: 39
State: 1 Base: 55680 Measured: 54958 Delta: 722
State: 1 Base: 55680 Measured: 54930 Delta: 750
State: 0 Base: 55679 Measured: 55659 Delta: 21
State: 1 Base: 55679 Measured: 54959 Delta: 720
State: 1 Base: 55679 Measured: 54929 Delta: 750
State: 0 Base: 55683 Measured: 55690 Delta: -11
State: 1 Base: 55683 Measured: 54955 Delta: 728
State: 1 Base: 55683 Measured: 54948 Delta: 735
State: 0 Base: 55682 Measured: 55651 Delta: 32
State: 0 Base: 55687 Measured: 55694 Delta: -12
State: 1 Base: 55687 Measured: 54961 Delta: 726
State: 0 Base: 55686 Measured: 55656 Delta: 31
State: 0 Base: 55685 Measured: 55668 Delta: 18
State: 1 Base: 55685 Measured: 54950 Delta: 735
State: 0 Base: 55684 Measured: 55639 Delta: 46
State: 0 Base: 55683 Measured: 55659 Delta: 25
State: 1 Base: 55683 Measured: 54956 Delta: 727
State: 1 Base: 55683 Measured: 54956 Delta: 727
State: 0 Base: 55682 Measured: 55647 Delta: 36
State: 1 Base: 55682 Measured: 54955 Delta: 727
State: 1 Base: 55682 Measured: 54958 Delta: 724
State: 0 Base: 55691 Measured: 55702 Delta: -20
State: 1 Base: 55691 Measured: 54963 Delta: 728
State: 1 Base: 55691 Measured: 54967 Delta: 724


#17 colinives2

colinives2

    Noob Class

  • Members
  • 3 posts

Posted 12 December 2015 - 06:56 PM

I'm trying to use the cap sense library to work with my own sensors on an FR5959 Launchpad - currently I have the sharp booster pack fitted. When i compile the CapTouch library I get the following errors:

/Users/colin/Documents/Energia/libraries/CapTouch/CapTouch.cpp: In member function 'uint16_t CapTouch::measure()':/Users/colin/Documents/Energia/libraries/CapTouch/CapTouch.cpp:124:16: error: 'BCSCTL3' was not declared in this scope
/Users/colin/Documents/Energia/libraries/CapTouch/CapTouch.cpp:143:2: error: 'IE1' was not declared in this scope
/Users/colin/Documents/Energia/libraries/CapTouch/CapTouch.cpp:147:13: error: 'LFXT1S_2' was not declared in this scope
/Users/colin/Documents/Energia/libraries/CapTouch/CapTouch.cpp:151:3: error: 'BCSCTL1' was not declared in this scope
/Users/colin/Documents/Energia/libraries/CapTouch/CapTouch.cpp:163:4: error: 'BCSCTL1' was not declared in this scope
 
Is there another library I need to add?
 
Thanks


#18 bthomsen

bthomsen

    Noob Class

  • Members
  • 1 posts

Posted 04 July 2016 - 09:01 PM

Just a note for those of you interested in using this code to create a touch slider in order to control the brightness of an LED using PWM. When used with the TOUCH_BUTTON option which tends to give the most accurate response, the MSP430 is put into Low Power mode 3 (LPM3_bits) which turns of SMCLK and ACLK, if you happen to be using these to clock TimerA1as your PWM then this will stop working every time you call isTouched. The simplest solution is to replace LPM3_bits on line 165 of the CapTouch.cpp file with LPM0_bits.


  • Fmilburn likes this




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users