energia

[Energia Library] Capacitive Touch library

18 posts in this topic

[Edit: New library attached with a bug fix for CapTouch on port 1 in combination with Serial]

Attached CapTouch.zip 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.

 

p2baron, Rei Vilo, yosh and 6 others like this

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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.  

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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 

Share this post


Link to post
Share on other sites

@@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

Share this post


Link to post
Share on other sites

@@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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now