Teensy 3.6 with HX8357 tft and ILI9341_t3 library

Status
Not open for further replies.

Beervangeer

Active member
Hello,

Im trying to make this screen: https://learn.adafruit.com/adafruit-3-5-color-320x480-tft-touchscreen-breakout/pinouts to work with Teensy 3.6 and ILI9341_t3 library.

I discovered that this https://github.com/PaulStoffregen/Adafruit_HX8357_Library doesnt really work with my screen.

The original Adafruit_ILI9341 does work fine on teensy 3.6. But it is a bit to slow.
The adjusted ILI9341_t3 also works, but not always.
When i upload the example sketch it is running fine.
But when I plug the teensy in and out the laptop, or connect it to external usb power, the teensy get stuck with a noisy screen.

Can you help me get the ILI9341_t3 working properly, what could be wrong?

Greetings,
Berend
 
I figured out that the ILI9341_t3 only works correct, if i set the cpu speed to 168 mhz or lower.
Now it doesnt crash on start.
 
Looks like the Teensy is just too quick for that TFT, seen that it is sold by Adafruit for the slower Arduino CPUs...

If you had respected the forum rule and you had posted your sketch, someone could have shown you where you would have to add a short delay in setup(), so that the display has enough time to start up before the Teensy floods it with display data at full speed.
 
I just used the basic examples that come with the libraries.
I tried the delay, but that didnt work. You mean just a normal delay after setup right?
Slowering down cpu only works.
 
For anyone who wants to use the 3.5 inch touch shield of adafruit. It took me quite some time to find the right setup, because the HX8357 libraries dont work well on teensy.
Here example of my configuration (build on max 168mhz):

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

Check out the links above for our tutorials and wiring diagrams
These displays use SPI to communicate, 4 or 5 pins are required to
interface (RST is optional)
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
****************************************************/

/** NOT FOR USE WITH THE TOUCH SHIELD, ONLY FOR THE 3.5" BREAKOUT! **/

//#include <Adafruit_GFX.h> // Core graphics library
#include <SPI.h>
#include "ILI9341_t3.h"
#include "TouchScreen.h"

// These are the four touchscreen analog pins
#define YP A2 // must be an analog pin, use "An" notation!
#define XM A3 // must be an analog pin, use "An" notation!
#define YM 7 // can be a digital pin
#define XP 8 // can be a digital pin

// This is calibration data for the raw touch data to the screen coordinates
#define TS_MINX 110
#define TS_MINY 80
#define TS_MAXX 900
#define TS_MAXY 940

#define MINPRESSURE 10
#define MAXPRESSURE 1000

// For the Adafruit shield, these are the default.
#define TFT_DC 9
#define TFT_CS 10

// Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
ILI9341_t3 tft = ILI9341_t3(TFT_CS, TFT_DC);

// For better pressure precision, we need to know the resistance
// between X+ and X- Use any multimeter to read it
// For the one we're using, its 300 ohms across the X plate
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);

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

void setup(void) {
while (!Serial); // used for leonardo debugging

Serial.begin(115200);
Serial.println(F("Touch Paint!"));

tft.begin();
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);
tft.fillRect(BOXSIZE*6, 0, BOXSIZE, BOXSIZE, ILI9341_BLACK);
tft.fillRect(BOXSIZE*6, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);

// select the current color 'red'
tft.drawRect(0, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
currentcolor = ILI9341_RED;
}


void loop()
{
// Retrieve a point
TSPoint p = ts.getPoint();

// we have some minimum pressure we consider 'valid'
// pressure of 0 means no pressing!
if (p.z < MINPRESSURE || p.z > MAXPRESSURE) {
return;
}

Serial.print("X = "); Serial.print(p.x);
Serial.print("\tY = "); Serial.print(p.y);
Serial.print("\tPressure = "); Serial.println(p.z);

// Scale from ~0->1000 to tft.width using the calibration #'s
p.x = map(p.x, TS_MINX, TS_MAXX, 0, tft.width());
p.y = map(p.y, TS_MINY, TS_MAXY, 0, tft.height());


/*
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);
} else if (p.x < BOXSIZE*7) {
currentcolor = ILI9341_WHITE;
tft.drawRect(BOXSIZE*6, 0, BOXSIZE, BOXSIZE, ILI9341_RED);
} else if (p.x < BOXSIZE*8) {
currentcolor = ILI9341_BLACK;
tft.drawRect(BOXSIZE*7, 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 (oldcolor == ILI9341_WHITE)
tft.fillRect(BOXSIZE*6, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
if (oldcolor == ILI9341_BLACK)
tft.fillRect(BOXSIZE*7, 0, BOXSIZE, BOXSIZE, ILI9341_BLACK);
}
}
if (((p.y-PENRADIUS) > BOXSIZE) && ((p.y+PENRADIUS) < tft.height())) {
tft.fillCircle(p.x, p.y, PENRADIUS, currentcolor);
}
}
 
Thus, you should perhaps experiment a little with the delay(x) value. 100 was a blind guess, I don't know how much time this specific TFT needs to wake up, try increasing it until you don't see an amelioration. Then, the next step would be to check SPI signal speed (vs data sheet of the TFT) and quality with a logic analyzer and an oscilloscope.
 
yes i tried different delays.
thanks for your suggestions.
i dont have a logic analyser nor oscilloscope to dive deeper in this.
 
Do you have a data sheet for that TFT? Perhaps (still a blind guess) the 30MHz SPI clock are simply too much for it? You could try lowering it to 24MHz in the ILI9341_t3.cpp file on line 56. Or your wiring could be problematic, at these relatively high frequencies the wire length and capacitive coupling between wires play already an important role. Or a combination of all...
 
Do you have a data sheet for that TFT? Perhaps (still a blind guess) the 30MHz SPI clock are simply too much for it? You could try lowering it to 24MHz in the ILI9341_t3.cpp file on line 56. Or your wiring could be problematic, at these relatively high frequencies the wire length and capacitive coupling between wires play already an important role. Or a combination of all...

Thats a good blind guess! I changed the SPI clock to 24mhz and now it always works on when i build on cpu 180mhz.
Thanks.
 
Status
Not open for further replies.
Back
Top