Jump to content
p2baron

Problems with CapTouch library

Recommended Posts

Guys, I am having some problems with the CapTouch library and need some help from the experts to resolve this.

 

I modified (stripped) the CapTouch button example an uploaded that code to a G2553:

#include <CapTouch.h>
#define LEFT_BUTTON 10
#define MIDDLE_LED P1_6

uint8_t state = false;

CapTouch left = CapTouch(LEFT_BUTTON, TOUCH_BUTTON);

void setup() {
  /* Use the middle LED to indicate touch */
  pinMode(MIDDLE_LED, OUTPUT);  
}
void loop() {
  /* State will be 1 if any of the buttons was touched, otherwise 0 */
  state = left.isTouched();
  /* Turn on the LED if any of the buttons was touched */
  digitalWrite(MIDDLE_LED, state);  
}

This code runs fine for over 20 hours but then stalls. The the green led (as defined in the code) is constantly on and the board no longer responses.

 

Any clues to what might cause this behaviour?

 

Share this post


Link to post
Share on other sites

This could be hard to reproduce as it takes 20 hours.

To narrow it down, can you run the following Sketch?

#include <CapTouch.h>
#define LEFT_BUTTON 10
#define MIDDLE_LED P1_6

uint8_t state = false;

CapTouch left = CapTouch(LEFT_BUTTON, TOUCH_BUTTON);

void setup() {
  /* Use the middle LED to indicate touch */
  pinMode(MIDDLE_LED, OUTPUT);
  pinMode(GREEN_LED, OUTPUT);
}

void loop() {
  /* State will be 1 if any of the buttons was touched, otherwise 0 */
  state = left.isTouched();
  /* Turn on the LED if any of the buttons was touched */
  digitalWrite(MIDDLE_LED, state);  
  
  digitalWrite(GREEN_LED, HIGH);
  delay(100);
  digitalWrite(GREEN_LED, LOW);
  delay(100);
}

This will blink the GREEN_LED constantly. If after 20 hours the GREEN_LED is still flashing but the CapTouch button is no longer responding then we know it's not hanging in the CapTouch library. If the GREEN_LED did stop blinking then the isTouched() api hangs or worse case, the MSP430 went into the weeds all together.

 

Robert

Share this post


Link to post
Share on other sites

Thanks. I will give it a go. I've replaced middle_led with red_led. I hope that isn't a problem. 

Yes, that works. They are the same pin.

 

I also started a test this morning and will check back on monday if it indeed froze.

Share this post


Link to post
Share on other sites

Hi Robert, just got home and noticed that the red light is on all of the time. The green light is still blinking so it seems to be something in the CapTouch library.

 

Verstuurd vanaf mijn HTC One met Tapatalk

 

 

Share this post


Link to post
Share on other sites

@@p2baron I have had the test running for 3 days straight now and am not able to reproduce it. The LED is still blinking and the touching the button still turns the middle LED on and off. I remember that there were some CapTouch boosterpacks that showed strange behaviour. I believe that the one I have on there right now is a good one. I will dig up one of the none behaving ones and restart the test.

 

Below is a test sketch that reads the raw values. I hope this will show what is going on when things stop working. Would you please be so kind to load this Sketch and log the output when it goes into the weeds? This will print a lot of data. Best is to close the Serial terminal while the test is running and then open it when it goes into the weeds to see what values are printed.

/*
  CapTouchRaw
  CapTouch library example for the capacitive booster pack
  http://www.ti.com/tool/430boost-sense1
  
  This example demonstrates how to get the raw, delta and base 
  sensor count and print them in the Serial monitor.

  Created 2012 by Robert Wessels from http://energia.nu
 
  This example code is in the public domain.
*/

#include <CapTouch.h>

#define LEFT_BUTTON 10
#define MIDDLE_LED P1_0

/* Create a CapTouch instance for the left sensor */
CapTouch left = CapTouch(LEFT_BUTTON, TOUCH_BUTTON);

uint16_t measured, base;
/* Delta can be negative */
int16_t delta;
uint8_t state;

void setup() {
  /* Use middle LED as indicator */
  pinMode(MIDDLE_LED, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  state = left.isTouched();
  digitalWrite(MIDDLE_LED, state);  
  
  measured = left.getMeasured();
  base = left.getBaseline();
  delta = left.getDelta();
  
  Serial.print("State: ");
  Serial.print(state);  
  Serial.print("\tBase: ");
  Serial.print(base);  
  Serial.print("\tMeasured: ");
  Serial.print(measured);  
  Serial.print("\tDelta: ");
  Serial.println(delta);  
}

Share this post


Link to post
Share on other sites

What kind of problems are you running into?

I just quick check and IRemote uses Timer1 and CapTouch uses Timer0 so there should be no conflict. Also the Sketch below compiles fine. I do not have access to hardware right now to test it.

/*
  CapTouchButton
  CapTouch library example for the capacitive booster pack
  http://www.ti.com/tool/430boost-sense1
  
  This example demonstrates turning on the middle
  led when one of the four buttons is touched.

  Created 2012 by Robert Wessels from http://energia.nu
 
  This example code is in the public domain.
*/
#include <IRremote.h>
#include <CapTouch.h>

#define LEFT_BUTTON P2_1
#define DOWN_BUTTON P2_2
#define RIGHT_BUTTON P2_3
#define UP_BUTTON P2_4

#define MIDDLE_LED P1_0

uint8_t state = false;

CapTouch left = CapTouch(LEFT_BUTTON, TOUCH_BUTTON);
CapTouch down = CapTouch(DOWN_BUTTON, TOUCH_BUTTON);
CapTouch right = CapTouch(RIGHT_BUTTON, TOUCH_BUTTON);
CapTouch up = CapTouch(UP_BUTTON, TOUCH_BUTTON);

IRsend irsend;

void setup() {
  /* Use the middle LED to indicate touch */
  pinMode(MIDDLE_LED, OUTPUT);  
}

void loop() {
  /* State will be 1 if any of the buttons was touched, otherwise 0 */
  state = left.isTouched();
  state |= down.isTouched();
  state |= right.isTouched();
  state |= up.isTouched();

  if(state) {
     irsend.sendSony(0xa90, 12); // Sony TV power code
  }
  
  /* Turn on the LED if any of the buttons was touched */
  digitalWrite(MIDDLE_LED, state);  
}

Share this post


Link to post
Share on other sites

 

@@p2baron I have had the test running for 3 days straight now and am not able to reproduce it. The LED is still blinking and the touching the button still turns the middle LED on and off. I remember that there were some CapTouch boosterpacks that showed strange behaviour. I believe that the one I have on there right now is a good one. I will dig up one of the none behaving ones and restart the test.

 

Below is a test sketch that reads the raw values. I hope this will show what is going on when things stop working. Would you please be so kind to load this Sketch and log the output when it goes into the weeds? This will print a lot of data. Best is to close the Serial terminal while the test is running and then open it when it goes into the weeds to see what values are printed.

 

 

THanks. I've done some testing this weekend. Please note that I am not using the CapTouch boosterpack. Just a  wire and a piece of metal.

 

This is the output I am getting when it goes berzerk:

 

State: 1        Base: 18855     Measured: 10110 Delta: 8745State: 1        Base: 18855     Measured: 9983  Delta: 8872State: 1        Base: 18855     Measured: 10052 Delta: 8803

Share this post


Link to post
Share on other sites

My program use touch and IR control

 

 

#include <IRremote.h>
#include <CapTouch.h>
int RECV_PIN = 15;
#define LEFT_BUTTON P2_1
#define DOWN_BUTTON P2_2
#define RIGHT_BUTTON P2_3
#define UP_BUTTON P2_4
 
#define MIDDLE_LED P1_6
 
// IR 1(TH) 2(GND) 3(VCC)
IRrecv irrecv(RECV_PIN);
decode_results results;
int buttonState = 0;
uint16_t measured, base;
/* Delta can be negative */
int16_t delta;
uint8_t ktra;
uint8_t state = false;
uint16_t doluong;
CapTouch left = CapTouch(LEFT_BUTTON, TOUCH_BUTTON);
CapTouch down = CapTouch(DOWN_BUTTON, TOUCH_BUTTON);
CapTouch right = CapTouch(RIGHT_BUTTON, TOUCH_BUTTON);
CapTouch up = CapTouch(UP_BUTTON, TOUCH_BUTTON);
void setup()
{
  Serial.begin(9600);
  //irrecv.enableIRIn(); // Start the receiver
  pinMode(RED_LED, OUTPUT);
  pinMode(PUSH2, INPUT_PULLUP);  
  pinMode(GREEN_LED, OUTPUT);
  digitalWrite(GREEN_LED, LOW); 
}
void loop() 
{   
  state = left.isTouched();
  Serial.print("State: ");
  Serial.print(state);  
  delta = left.getDelta();
  Serial.print("\tDelta: ");
  Serial.println(delta);
  /* Turn on the LED if any of the buttons was touched */
  digitalWrite(MIDDLE_LED, state);  
  results.value=0; 
  ngatIR();
  delay(350);
  }
void ngatIR()
  if (irrecv.decode(&results)) 
    {    
    Serial.println(results.value);
    delay(150);
    irrecv.resume(); // Receive the next value
 
    }
   }
 
When i build it with IR, green led sometime is blink, system doesnt work.
Please test to help me.
Thanks

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

×