Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 12 of 12

Thread: Weird behaviour from digitalReadFast?

  1. #1

    Weird behaviour from digitalReadFast?

    I've been working with the ili9341 cap touch display recently. There is an active high interrupt pin that goes low when touched.

    Here is a simplified version of my code:
    Code:
    void setup(){
        ....
    }
    void loop(){
        while(digitalReadFast(IRQ) == HIGH);
        delay(1000);
        do{
            compass(); // print out compass data to display
        } while(digitalReadFast(IRQ) == HIGH); // check if display is touched
        delay(500); // delay just to make sure it doesn't instantly go back because it's still being touched
    }
    Essentially, the program should break out of doing the function compass() when the display is touched. This does happens, but I have to press my finger on the screen for around 1s for that to happen.
    However, running this is almost instantaneous:
    Code:
    void setup(){
        ....
    }
    void loop(){
        while(digitalRead(IRQ) == HIGH);
        delay(1000);
        do{
            compass(); // print out compass data to display
        } while(digitalRead(IRQ) == HIGH); // check if display is touched
        delay(500); // delay just to make sure it doesn't instantly go back because it's still being touched
    }
    Could someone please explain what's happening? Just curious.

  2. #2
    Actually. Disregard this. I'm experiencing the same behavior with both now.

  3. #3
    So you've managed to get the touch working on a teensy 3.1? Can I confirm it's the FT6206 adafruit capacitance touch tft? If so what library are you using coz I've so far failed completely to get this thing working,, I can print gfx at top speed with the spi fix, I can load bitmaps using sdfat library, but just cannot get the capacitance touch to be even 'found' in the setup / begin. Really annoying, and I think you and I are perhaps the only 2 people in the world with this screen and a teensy? Lol

    Any help would be muchos collios

    Original post:
    https://forum.pjrc.com/threads/27336...ll=1#post60320

    Cheers

    Andy

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    22,294
    Are you using this Adafruit library for the capacitive touch?

    https://github.com/adafruit/Adafruit_FT6206_Library

    I just looked at the code and it really seems like it ought to work, since it only uses the Wire library.

    Before going any further, make sure you have real pullup resistors on the SDA and SCL pins. Teensy 3.1 requires pullup resistors. I looked but could not find a schematic for this Adafruit product (#1947), so I can't tell if it has real pullup resistors. There's some jumpers for SDA & SCL in the corner of the board, which I also couldn't find documented.

    If you're sure real pullup resistors are used on SDA and SCL, the next step is probably to uncomment all the Serial.print stuff within their library. Also, put "while (!Serial)" at the beginning of your sketch, so you won't miss any of the stuff before you open the serial monitor.

    If all *that* doesn't make a solution clear, I might have to get one of these Adafruit displays to investigate.....

  5. #5
    Senior Member
    Join Date
    Nov 2012
    Posts
    275
    Design files for the TFT shield v2 and v2.3: https://github.com/adafruit/Adafruit...-Shield-v2-PCB
    schematic for the TFT shield v2.3 as pdf: Adafruit tftcaptouchshield v2.3.pdf
    Last edited by HWGuy; 01-04-2015 at 05:57 PM.

  6. #6
    Hey Paul, yeah I went all through the whole pull-up routine, I've been caught out by that in the past, but this issue as it turns out was even simpler thanks to HWGuy, wrong damn pins lol!

    I didn't even want the stupid shield version of the display since I was always gonna be using it with a teensy, but no stock so thought I'd buy the shield version anyway and make my own shield using Proto board... Little did i know, the tft uses the pins up the top to break out, not the (what I consider to be) usual A4/A5 pins as I'd wrongly assumed...

    Thanks for cutting in Paul. And thanks again to HWGuy for his suggestion

    Cheers

    Andy

  7. #7
    Senior Member
    Join Date
    Nov 2012
    Posts
    275
    the current version of the Adafruit 2.8" TFT breakout has no touch controller. Yes it comes with a touch screen with X-,X+,Y-,Y+ output, but it's not a drop in replacement... (just fyi)

  8. #8
    I believe this is regarding the capacitive breakout? http://www.adafruit.com/product/1770
    Just some tips from experience:
    1. you don't really need pullups if you've only got one i2c device
    2. don't rely on the irq pin. For some reason, it works very well when the screen is changing (the teensy isn't sending data to the tft) but doesn't like working when you're constantly printing data to the tft. Instead just poll the touch controller via i2c. It's much more responsive that way.

    Also, I've successfully got it working with 800kHz i2c, despite the datasheet specifying a 400kHz max.

  9. #9
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    3,771
    Quote Originally Posted by BrianC View Post
    1. you don't really need pullups if you've only got one i2c device
    You must be using a device that supplies pull-ups. Everything I've read says that the Teensy 3.x require pull-ups (including the bit from Paul S. earlier in the thread). My own experience is the i2c devices I tried did not work, until I provided 4.7K pull-up resistors (wired from the pin to the power rail). Of course another issue might be the i2c device requires 5v signaling, and you need to do the proper voltage translation.

  10. #10
    Senior Member
    Join Date
    Nov 2012
    Posts
    275
    The board includes an i2c level shifter, based on MOS-FETs and resistors. The resistors (10kOhm) are used as pull-ups.

    I believe this is regarding the capacitive breakout? http://www.adafruit.com/product/1770
    I see this now, there are two 2.8" TFT breakout boards from Adafruit - one with cap touchscreen and one with res touchscreen.

  11. #11
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    22,294
    Glad you got it working!

    Michael is correct, real pullup resistors are required when using Teensy 3.0 or 3.1. The 10K resistors on Adafruit's shield are fine.

    Regarding I2C speed, Teensy 3.1's I2C hardware monitors the voltage on both pins and will automatically wait if the voltages rise slowly, due to weak pullups. If you configure a fast I2C speed, you'll probably end up with something much slower using only the default 10K resistors and the extra capacitive loading of those level-shifting mosfet transistors.

  12. #12
    Sorry. Forgot to emphasise the built in 10k resistors (on both the breakout and the shield)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •