Capacitive touch shield fails to initialise after power cycl

For other supported Arduino products from Adafruit: Shields, accessories, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
seb_r
 
Posts: 12
Joined: Mon Jan 05, 2015 6:00 pm

Capacitive touch shield fails to initialise after power cycl

Post by seb_r »

Hello, I use a TFT Touch Shield w/Capacitive Touch (PRODUCT ID: 1947) on an Arduino Leonardo. I can upload the examples (graphicstest and CapTouchPaint) and they work as expected. However, when I then power cycle the Arduino (by briefly unplugging the USB, or unplugging it and connecting a USB pwr supply instead, or by pressing the reset button), the sketch fails to start up again. The backlight comes on but then nothing else happens. Note that sketches which don't use the screen (e.g. AnalogReadSerial from the basic examples) work fine, therefore I think it's not the Arduino but the touch shield that has a problem. Any help would be much appreciated!

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Capacitive touch shield fails to initialise after power

Post by adafruit_support_mike »

That may be an issue with the shutdown timing in the TFT..

LCD drivers are complicated beasts, and it takes a while to start them up and shut them down properly. The have internal charge pumps that need to start and come up to a stable voltage, support systems that need to be started and verified before trying to start the next piece, etc.

I assume the display works again after you wait some amount of time between shutting it down and starting it again.. if you test various wait times, how long does that take?

User avatar
seb_r
 
Posts: 12
Joined: Mon Jan 05, 2015 6:00 pm

Re: Capacitive touch shield fails to initialise after power

Post by seb_r »

Hello, thanks for the swift reply. I appreciate your help.

Actually, waiting (even many hours) makes no difference. The only way to get it to work is to re-upload the sketch. This works 9 times out of 10. Sometimes, I have to try re-uploading several times before it works, and sometimes I even need to restart the Arduino software and then re-upload the sketch. In the end, I can always get it to work, though.

Once it's working, if I do any of the following:
- Disconnect and re-connect USB
- Disconnect USB and connect USB power supply instead
- press the reset button
it will always hang on a white screen.

Can you think of anything else I could try to help diagnose the problem?

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Capacitive touch shield fails to initialise after power

Post by adafruit_support_mike »

That's somewhere between odd and freaky..

I know the Leonardo's reset and boot cycles are different from an Uno's, but a hard power cycle should BANNED everything.

Let me check with some of the other device gurus and see if they have any ideas.

For the sake of comparison, does the shield work as expected with an Uno?

User avatar
seb_r
 
Posts: 12
Joined: Mon Jan 05, 2015 6:00 pm

Re: Capacitive touch shield fails to initialise after power

Post by seb_r »

The Leonardo is the only Arduino I have, I'm afraid. I'm not sure I want to buy a Uno just to test the touchscreen... For my project I specifically need the Leonardo because it will need to emulate a USB keyboard.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Capacitive touch shield fails to initialise after power

Post by adafruit_support_mike »

No need to buy any additional hardware.

Testing with an Uno would have given us more information, but it isn't crtical.

We don't have clear evidence of a production error, but something is obviously going wrong. I can authorize a one-time replacement to see if that solves the problem, but if you have the same problem with the new unit we'll have to assume it's something in your operating environment.

Send a note to [email protected] with a link to this thread and the folks there will get you a new Capacitive Touch Shield.

User avatar
seb_r
 
Posts: 12
Joined: Mon Jan 05, 2015 6:00 pm

Re: Capacitive touch shield fails to initialise after power

Post by seb_r »

Hello,

The replacement shield has arrived, and it behaves in exactly the same way as the previous one. I have also moved from a macbook to a win 7 64 bit PC, and that makes no difference, either.

Here are a few more things I tried: I realised that after uploading CapTouchPaint, the system always hangs on a white screen, but starts working normally as soon as I activate the serial monitor. So I commented out all the lines to do with serial in CapTouchPaint, and now it always works straight away after uploading. (Not surprising, as the first line in the setup function is "while (!Serial);").

However, after power cycling it still hangs on the white screen. Only freshly uploading the sketch makes it work. So I took the CapTouchPaint with all the serial commands commented out and replaced

" if (! ctp.begin(40)) { // pass in 'sensitivity' coefficient
Serial.println("Couldn't start FT6206 touchscreen controller");
while (1);
}"

with

" if (! ctp.begin(40)) { // pass in 'sensitivity' coefficient
// Serial.println("Couldn't start FT6206 touchscreen controller");
while (1){
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
}
"

(having defined pin 13 as an output in the setup function).

After uploading the sketch, it works, but after power cycling, it hangs on the white screen, and the LED blinks. This means that ctp.begin(40) returns true only directly after uploading, but returns an error after power cycling.

Does this help? Anything else I could try?

User avatar
seb_r
 
Posts: 12
Joined: Mon Jan 05, 2015 6:00 pm

Re: Capacitive touch shield fails to initialise after power

Post by seb_r »

Further to my last message, I have also found that it will now work after pressing the reset button. (This was not the case until I commented out the serial commands in CapTouchPaint.) So, it looks like upon power-up, ctp.begin(40) returns an error, but works fine after reset (by bootloader or button).

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Capacitive touch shield fails to initialise after power

Post by adafruit_support_mike »

Glad to hear you've found a solution. ;-)

User avatar
seb_r
 
Posts: 12
Joined: Mon Jan 05, 2015 6:00 pm

Re: Capacitive touch shield fails to initialise after power

Post by seb_r »

But I haven't! The capacitive touch shield still hangs on a white screen after powering up! How is having to press the reset button on the PCB a "solution"? It's an acceptable temporary workaround while I develop the sketch, but not for the finished product. The whole reason I bought a touch screen was so that I wouldn't have to add any buttons - and certainly not a reset button that the user has to press every time after switching the device on because it hangs on power-up. Please help me to get this fixed.

User avatar
seb_r
 
Posts: 12
Joined: Mon Jan 05, 2015 6:00 pm

Re: Capacitive touch shield fails to initialise after power

Post by seb_r »

OK, now I have found what you could call a solution. It turns out there were 3 distinct problems:

1.) By default, the sketch waits indefinitely for the user to open the serial port monitor. A user who is unaware of that, or who tries to run the sketch as it is on an Arduino Leonardo connected to a power supply, is in for a long wait indeed. I suggest commenting out that line by default.

2.) Initialising the TFT as soon as the Leonardo has booted can fail, because the TFT is slower to wake up. The time this takes is different following a software reset (upload), a hardware reset (button), or a power cycle (e.g. after connecting to a power supply). A 100 ms delay before initialising the TFT seems to cover it all.

3.) Similarly, the touch screen controller takes a while to come to life - this is even more variable than the time it takes for the TFT. Luckily, the initialisation function ("ctp.begin()") returns a result (success or failure), so it's quite straightforward to try several times until it succeeds.

Please see below for my modified version of CapTouchPaint, which seems to work fine now on my Leonardo, in case you are interested. It may also be an idea to modify the ctp.begin() and tft.begin() functions in your libraries so they try to execute several times over a period of time before returning an error.

Thanks again for your help!

Best,

Seb

Code: Select all

/***************************************************
  This is our touchscreen painting example for the Adafruit ILI9341
  captouch shield
  ----> http://www.adafruit.com/products/1947

  Check out the links above for our tutorials and wiring diagrams

  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.
  MIT license, all text above must be included in any redistribution
 ****************************************************/
 
 /***************************************************
  A few lines added by SWR to debug a startup problem
  when used on Arduino Leonardo
 ****************************************************/


#include <Adafruit_GFX.h>    // Core graphics library
#include <SPI.h>       // this is needed for display
#include <Adafruit_ILI9341.h>
#include <Wire.h>      // this is needed for FT6206
#include <Adafruit_FT6206.h>

// The FT6206 uses hardware I2C (SCL/SDA)
Adafruit_FT6206 ctp = Adafruit_FT6206();

// The display also uses hardware SPI, plus #9 & #10
#define TFT_CS 10
#define TFT_DC 9
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);

// Size of the color selection boxes and the paintbrush size
#define BOXSIZE 40
#define BANNED 3
int oldcolor, currentcolor;

void setup(void) {
  
  //while (!Serial);     // used for leonardo debugging
  /* Additional comment by SWR:
  The line "while (!Serial);", used for Leonardo debugging,
  waits for the user to activate the serial port monitor. If you
  don't know that, or if you forget to remove this line and try to 
  run the Arduino as standalone (from a power supply), it will just
  hang at this line forever. It might therefore be better to have it 
  commented out by default in CapTouchPaint, and leave it to users
  who need it to uncomment that line.
  */

  
  Serial.begin(115200);
  Serial.println(F("Cap Touch Paint!"));
  
  // SWR:
  // Wait for the TFT to wake up - this takes some time
  // depending on whether it was reset or power cycled:
  delay(100);
  // Now initialise the TFT:
  tft.begin();

/* original code removed by SWR:
  if (! ctp.begin(40)) {  // pass in 'sensitivity' coefficient
    Serial.println("Couldn't start FT6206 touchscreen controller");
    while (1);
    
    Serial.println("Capacitive touchscreen started");

  }
*/

  // SWR:
  // Now try 10 times, every 50ms, to initialise the capacitive touch 
  // screen controller. This is necessary because it can be slow to wake 
  // up after a reset and even slower after power cycling:
  int attempt = 1;
  while (! ctp.begin(40)){
    if (attempt > 10){
      Serial.println("Couldn't start FT6206 touchscreen controller");
      while (1);
    }
    attempt++;
    delay(50);
  }
  Serial.println("Capacitive touchscreen started");
  

  
  tft.fillScreen(ILI9341_BLACK);
  
  // make the color selection boxes
  tft.fillRect(0, 0, BOXSIZE, BOXSIZE, ILI9341_RED);
  tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, ILI9341_YELLOW);
  tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, ILI9341_GREEN);
  tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, ILI9341_CYAN);
  tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, ILI9341_BLUE);
  tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, ILI9341_MAGENTA);
 
  // select the current color 'red'
  tft.drawRect(0, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
  currentcolor = ILI9341_RED;
}

void loop() {
  // Wait for a touch
  if (! ctp.touched()) {
    return;
  }

  // Retrieve a point  
  TS_Point p = ctp.getPoint();
  
 /*
  // Print out raw data from screen touch controller
  Serial.print("X = "); Serial.print(p.x);
  Serial.print("\tY = "); Serial.print(p.y);
  Serial.print(" -> ");
 */

  // flip it around to match the screen.
  p.x = map(p.x, 0, 240, 240, 0);
  p.y = map(p.y, 0, 320, 320, 0);

  // Print out the remapped (rotated) coordinates
  Serial.print("("); Serial.print(p.x);
  Serial.print(", "); Serial.print(p.y);
  Serial.println(")");
  

  if (p.y < BOXSIZE) {
     oldcolor = currentcolor;

     if (p.x < BOXSIZE) { 
       currentcolor = ILI9341_RED; 
       tft.drawRect(0, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
     } else if (p.x < BOXSIZE*2) {
       currentcolor = ILI9341_YELLOW;
       tft.drawRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
     } else if (p.x < BOXSIZE*3) {
       currentcolor = ILI9341_GREEN;
       tft.drawRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
     } else if (p.x < BOXSIZE*4) {
       currentcolor = ILI9341_CYAN;
       tft.drawRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
     } else if (p.x < BOXSIZE*5) {
       currentcolor = ILI9341_BLUE;
       tft.drawRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
     } else if (p.x <= BOXSIZE*6) {
       currentcolor = ILI9341_MAGENTA;
       tft.drawRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
     }

     if (oldcolor != currentcolor) {
        if (oldcolor == ILI9341_RED) 
          tft.fillRect(0, 0, BOXSIZE, BOXSIZE, ILI9341_RED);
        if (oldcolor == ILI9341_YELLOW) 
          tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, ILI9341_YELLOW);
        if (oldcolor == ILI9341_GREEN) 
          tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, ILI9341_GREEN);
        if (oldcolor == ILI9341_CYAN) 
          tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, ILI9341_CYAN);
        if (oldcolor == ILI9341_BLUE) 
          tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, ILI9341_BLUE);
        if (oldcolor == ILI9341_MAGENTA) 
          tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, ILI9341_MAGENTA);
     }
  }
  if (((p.y-BANNED) > BOXSIZE) && ((p.y+BANNED) < tft.height())) {
    tft.fillCircle(p.x, p.y, BANNED, currentcolor);
  }
}

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Arduino products from Adafruit”