Jump to content
lordcape

Problem with Capacitive Touch Library

Recommended Posts

Hi. I'm using the capacitive touch library for my project of a touch-lamp. The code is very very simple. The idea is scan if the capacitive pad is touched and then activate a relee to drive the lamp. If you touch the pad again, the relee goes off. It works very well at beggining but after one day more or less the relee starts to oscillate. The lamp goes on and off until I reset the MCU. I think that is related with the mode that the library measures capacitance but I don't know. Here is the code:

#include <CapTouch.h>

#define BOTON P2_0  // Capacitive Sensor in a PCB.
#define RELEE P1_0

uint8_t state = false;
uint8_t k = 0;

CapTouch PRESS = CapTouch(BOTON, TOUCH_BUTTON);

void setup() 
{
    pinMode(RELEE, OUTPUT);
    digitalWrite(RELEE, 0);
}

void loop()
{
  
  while(k < 10)
  {
    if(PRESS.isTouched())
    {
      k++;
    }
    else
    {
      k = 0;
    }
  }
  if(k = 10)
  {
    state = !state;
    digitalWrite(RELEE, state);
    delay(1000);
    k = 0;
  }

}

Another question. Can I measure time intervals with millis() using functions of this CapTouch library? Because I want to use millis() and send the number with Serial but it only works if I pulse the sensor. I hope you can guide me.

 

Thanks     

 

lordcape

Share this post


Link to post
Share on other sites

I'm having similiar issue

Never managed to resolve this. I suspect this has something to do with the size of the object that is being used as the touchpad.

Also the power supply seems to make a difference. With some cheap usb-charger the MCU constantly registered touches that weren't there.

Share this post


Link to post
Share on other sites

Couple questions:

 

1: What are you using as the sensing pad?

2: What are you using as the power supply for the MSP430?

3: Is this a LaunchPad or is the MSP430 standalone (e.g. soldered onto a breadboard)?

 

When I last tested it, it was up for 2 weeks without any of the issues described above. This was with the official CapTouch BoosterPack on a LaunchPad that was powered from an iPhone USB adapter.

 

If you can provide me with the information below then I will restart the experiment and see if I can reproduce it this time around.

 

Robert

Share this post


Link to post
Share on other sites

Hi!

 

Can you use Cap Touch library together with millis() -function? If not what would be the best way to measure time while using CapTouch? I'm using G2553 so it has two timers. CapTouch uses timer0_A but I'm not sure about millis() if it can be set up to use timer1_A.

 

Thanks

 

Coyotek

Share this post


Link to post
Share on other sites

The millis() thing should still work, but it wont report time in milliseconds anymore. I timed it, and for each second in real time, millis() had incremented by 25. If you were waiting for half a second banking on millis() incrementing by 500, it will actually take 20 seconds. Im assuming the CapTouch library changes the clock frequency for whatever clock millis() was using.
 
I too had the issues with the oscillation, but it would start almost as soon as I had touched the sensor (im using the capacitive sliders on the 430BOOST-SHARP96 as buttons, with a G2553). I think this was partly because the isTouched function would eventually start reporting inverted values. (if it was touched it would send a 0, not a 1). The way I got around this was to go into CapTouch.cpp, and comment out from line 93 to line 95, (the if (delta < 0) stuff), and comment out the base--; on line 98. Then in the code I'm writing I set the threshold to 1000. I havn't tested this to see if it works over extended periods though.

 

 

I was also wondering if there was a plan to port the CapTouch library over to working on the fr5969?

Share this post


Link to post
Share on other sites

@@zormino Thanks, that solved the problem for me!!

 

@@energia Robert, sorry for the late reply. Here are my answers:

 

1: What are you using as the sensing pad? A piece of breadboard wire

2: What are you using as the power supply for the MSP430? Just a plain USB charger (LG, 5v, 800mA)

3: Is this a LaunchPad or is the MSP430 standalone (e.g. soldered onto a breadboard)? I used the launchpad

 

Zormino's solution fixed the problem for me. I am unsure why I am having this problem but you don't.

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

×