Weird behaviour from digitalReadFast?

Status
Not open for further replies.

BrianC

Well-known member
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.
 
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/2733...r-(2-8-quot-TFT)?p=60320&viewfull=1#post60320

Cheers

Andy
 
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.....
 
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
 
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)
 
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.
 
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.
 
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.
 
Status
Not open for further replies.
Back
Top