Jump to content
energia

[Energia Library] Capacitive Touch library

Recommended Posts

[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.

 

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

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

×