p2baron 11 Posted January 31, 2014 Share Posted January 31, 2014 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? Quote Link to post Share on other sites
energia 485 Posted January 31, 2014 Share Posted January 31, 2014 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 p2baron 1 Quote Link to post Share on other sites
p2baron 11 Posted January 31, 2014 Author Share Posted January 31, 2014 Thanks. I will give it a go. I've replaced middle_led with red_led. I hope that isn't a problem. Quote Link to post Share on other sites
energia 485 Posted February 1, 2014 Share Posted February 1, 2014 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. Quote Link to post Share on other sites
p2baron 11 Posted February 1, 2014 Author Share Posted February 1, 2014 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 Quote Link to post Share on other sites
energia 485 Posted February 1, 2014 Share Posted February 1, 2014 Wild guess that it's a counter overflow that is not being taken into account. I'll look into. p2baron 1 Quote Link to post Share on other sites
p2baron 11 Posted February 4, 2014 Author Share Posted February 4, 2014 @@energia , how did your test go? Not pushing for a solution but just curious if you've experienced the same behaviour. I will do a test tonight to see if this also affects the Stellaris boards. Quote Link to post Share on other sites
energia 485 Posted February 4, 2014 Share Posted February 4, 2014 @@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); } p2baron 1 Quote Link to post Share on other sites
tranduythai 1 Posted February 7, 2014 Share Posted February 7, 2014 why we cant use library touch and IRemote in same skecht? Quote Link to post Share on other sites
energia 485 Posted February 7, 2014 Share Posted February 7, 2014 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); } Quote Link to post Share on other sites
p2baron 11 Posted February 8, 2014 Author Share Posted February 8, 2014 @@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 Quote Link to post Share on other sites
tranduythai 1 Posted February 9, 2014 Share Posted February 9, 2014 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 Quote Link to post Share on other sites
p2baron 11 Posted July 1, 2014 Author Share Posted July 1, 2014 Solved. See this thread: http://forum.43oh.com/topic/5465-problem-with-capacitive-touch-library/ Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.