Highly optimized ILI9341 (320x240 TFT color display) library

same pins for Teensy 3.2 and LC

The Teensy LC is not compatible with the ILI9341_t3 library. Instead, use Adafruit's original Adafruit_ILI9341 library with Teensy LC.
 
Yeah - that lib's example graphicstest works on my LC.

I added #if for LC to my TOUCHPAINT sample - it won't work on pin 2 interrupt. And running on Timer_interrupt it is 10 or perhaps 50 times slower when I do my tft debug prints. Turning those abusive writes off and it works with the XPT2046_Touchscreen as well as its included ili9341.
<edit - update below>: it works on pin 2 interrupt - just not as well as on the T_3's.
 
Last edited:
same pins for Teensy 3.2 and LC

The Teensy LC is not compatible with the ILI9341_t3 library. Instead, use Adafruit's original Adafruit_ILI9341 library with Teensy LC.

I do have a 3.2 board that I will use. I do most of my breadboarding using the LC's but for this LCD I will setup a new breadboard with the 3.2...thanks for clarifying.
 
Correction to P#328 :: Pin Int_2 Falling - does work - but not as well or smoothly - it is intermittent. Some paint touches catch and some slip by. Even with my overbearing screen debug prints gone - that hid it completely - it can wholly appear to fail to register and re-act to the event.
The Timer interrupt works much better - nearly perfectly.
But my code somehow misses the timing and response to the arriving interrupt that works perfectly on the T_3's.
 
TFTDisplayText Example Code?

Is the Ardunio TFTDisplayText example code the correct sketch to be using with this display? I looked in the IDE->Teensy but didn't see a TFT example?

I connected the 9 wires on the TFT LCD to my Teensy 3.2 according to this link: http://www.pjrc.com/store/display_ili9341.html

But when I power up my breadboad, I don't see any text on the LCD screen.

Code:
/*
  Arduino TFT text example

  This example demonstrates how to draw text on the
  TFT with an Arduino. The Arduino reads the value
  of an analog sensor attached to pin A0, and writes
  the value to the LCD screen, updating every
  quarter second.

  This example code is in the public domain

  Created 15 April 2013 by Scott Fitzgerald

  http://www.arduino.cc/en/Tutorial/TFTDisplayText

 */

#include <TFT.h>  // Arduino LCD library
#include <SPI.h>

// pin definition for the Uno
#define cs   10
#define dc   9
#define rst  8

// pin definition for the Leonardo
// #define cs   7
// #define dc   0
// #define rst  1

// create an instance of the library
TFT TFTscreen = TFT(cs, dc, rst);

// char array to print to the screen
char sensorPrintout[4];

void setup() {

  // Put this line at the beginning of every sketch that uses the GLCD:
  TFTscreen.begin();

  // clear the screen with a black background
  TFTscreen.background(0, 0, 0);

  // write the static text to the screen
  // set the font color to white
  TFTscreen.stroke(255, 255, 255);
  // set the font size
  TFTscreen.setTextSize(2);
  // write the text to the top left corner of the screen
  TFTscreen.text("Sensor Value :\n ", 0, 0);
  // ste the font size very large for the loop
  TFTscreen.setTextSize(5);
}

void loop() {

  // Read the value of the sensor on A0
  String sensorVal = String(analogRead(A0));

  // convert the reading to a char array
  sensorVal.toCharArray(sensorPrintout, 4);

  // set the font color
  TFTscreen.stroke(255, 255, 255);
  // print the sensor value
  TFTscreen.text(sensorPrintout, 0, 20);
  // wait for a moment
  delay(250);
  // erase the text you just wrote
  TFTscreen.stroke(0, 0, 0);
  TFTscreen.text(sensorPrintout, 0, 20);
}

TFT4.jpg
TFT3.jpg
TFT2.jpg
TFT1.jpg
 
Connect VCC from the display to 5V!
Why don't you use the Teensy library?
(there might be more issues)
 
Last edited:
Isn't this display a 3.3v display? That's why I bought it...to use with my Teensy 3.2 board.

I can't find my Teensy libraries...what is the default folder?

Thanks...
 
If you fully follow that wiring - and have the proper software settings for those pins - I have found it to work.

And this sample uses the good SPI customized Teensy library you can start with - I just powered it to run :: Teensy166\hardware\teensy\avr\libraries\ILI9341_t3\examples\graphicstest.

Code:
#include "SPI.h"
#include "ILI9341_t3.h"
 
Isn't this display a 3.3v display?

Just seeing your cross post - looks like I exposed the right directory for you.

IIRC - it is 3.3v and runs low enough power from Teensy 3.3v output. My PJRC OSH board pulls the power from 3.3v - I didn't have the parts to make the regulator active so I just ran the 3.3v wire into the one half of the power CAP to feed the display controller - though it looks like it feeds the LED from the 5v USB VIN? Not sure how that works if fed from 3.3v.
 
Just seeing your cross post - looks like I exposed the right directory for you.

IIRC - it is 3.3v and runs low enough power from Teensy 3.3v output. My PJRC OSH board pulls the power from 3.3v - I didn't have the parts to make the regulator active so I just ran the 3.3v wire into the one half of the power CAP to feed the display controller - though it looks like it feeds the LED from the 5v USB VIN? Not sure how that works if fed from 3.3v.

Don't you have to close the jumper on the board for 3.3v ? I never tried it with 3.3v.

Edit:
Pauls table says: Power: 3.6 to 5.5 volts.
-> 3.3 is too less without closing the jumper.
 
@FrankB is correct the spec table says 3.6 to 5.5 volts.

I have one with J1 open and running - on that board I can confirm the controller on my OSH PJRC board is taking 3.3v from Teensy LC or T_3.1 just fine. I closed J1 on one display - that made it work - but it is getting 5v VIN on VCC. I have not tried the LED on anything but 5v (across 100ohm) though as noted.
 
>#include "SPI.h"
>#include "ILI9341_t3.h"

I added these two lines to my TFTDisplayText example and I still don't see anything on my screen.

However, I can load and run the Adafruit graphicstest sketch from the IDE examples (un-modified). The graphicstest runs fine and goes through all the graphics tests ok.

I'm a bit confused as to which sketch I should start with to be able to use the Teensy 3.2 board and this threads Teensy ILI9341 library?

Thanks...
 
Look for this under examples - from my same post #334

>> Teensy166\hardware\teensy\avr\libraries\ILI9341_t3 \examples\graphicstest.

That should run as is - then you can hack it and add your own text printing to see it work.
 
Look for this under examples - from my same post #334

>> Teensy166\hardware\teensy\avr\libraries\ILI9341_t3 \examples\graphicstest.

That should run as is - then you can hack it and add your own text printing to see it work.

Yes...that worked...and it compiled on the first try!!

So I can see the visual speed difference between the Adafruit graphicstest and when the Teensy ILI9341_t3 lib is used on the same sketch code. Very large speed difference indeed!!

OK, so this got me started...thanks for the help...!!!
 
@rfresh737 - Great! Are you running the whole display on 3.3v? Wondering how the LED responds brightness wise. IIRC Paul said he saw under 100ma the other day to run the Teensy and display.

I saw the "Ctrl + K" the other day in the IDE will open to your sketch directory - I found that very handy to get to where the sketch is stored - worked there for that example too.
 
Yes I'm wired into the 3.3v pin on the Teensy 3.2 to power my breadboard red line and my LCD is powered from the 3.3v red line.

I would say the screen brightness is 'ok' really...very readable...it would be nice if I could have a line of code to change the brightness but as far as I know the device doesn't support that. But I'm pleased with the display readability on 3.3v.

Here is a pic I took on my bench with really, not a lot of overhead light on the table. The pic reflects pretty much what I see in regards to brightness...very readable.

What I'd like to do now is learn how to detect screen touch points...you can see my last line is touch screen to continue, so any touch will work here but on other screens, I need to build touch 'buttons'. I loaded the Adafruit examples of touchpaint but that sketch wouldn't work (didn't display anything on the screen and no text in the serial window).

So, I'm asking:

1. For my Teensy 3.2/ILI9341 Lib, is there any example code on how to do this?

2. I looked at the Adafruit touchpaint tutorial on this TFT and the 4 wires to control the touch film on top of the LCD screen looks to me like I already have that wired up, but I am not 100% sure.

Color_LCD_Touch_Screen2.jpg
 
Last edited:
Isn't this display a 3.3v display? That's why I bought it...to use with my Teensy 3.2 board.

I can't find my Teensy libraries...what is the default folder?

Thanks...

I, too, am curious about running the ILI9341 display from 3.3V rather than 5V as it would simplify a design I'm working on. If the board is spec'ed at 3.6V then I think I'd rather have the reliability. The suggested RST input is tied to 3.3V too, and I imagine there could be a race condition between power up and this signal. Any thoughts? (Also, great project everyone!)
 
I, too, am curious about running the ILI9341 display from 3.3V rather than 5V

It seems to work fine. We ran them at 3.3V for the workshop last weekend.

The ILI9341 datasheet says the chip works down to 2.5V, so if it's getting 3.0V after the LDO, it should still have plenty of margin.

The suggested RST input is tied to 3.3V too, and I imagine there could be a race condition between power up and this signal. Any thoughts?

The ILI9341 has on-chip power on reset circuitry, so a physical reset line really isn't necessary.
 
Hello Guys,
Quick question, on the past I created my fork of this library to include scrolling functionalities (basically copying screen memory and pasting shifting the position). I saw that few more methods were added to the library, I'm wondering if is there any new way to accomplish text scrolling...
 
Hello Guys,

So I updated a version that I kept of this library that allows easy text scrolling, now supporting the custom fonts, like this video:


You can find my branch here: https://github.com/vitormhenrique/ILI9341_t3

Paul, should I create a pull request to add new functions to the original library? Can someone else take a look on my modifications? I'm not an experienced c++ developer.

I also had a problem using println with the new fonts, I could not get the new line printing correctly. I noticed that line 838 was commented with a question mark. After changing it to cursor_y += font->line_space; it works perfectly.
 
Last edited:
@vitormhenrique: let me know if you can't see the Bad I found I may be able to look more tomorrow.

I pulled a copy - it compiled - on my existing sketch no new functions called: ram up 12 bytes - Sketch went from 33,392 to 35,552 - up 2160 bytes. My current Touch Sketches load and runs fine, before and after the bad below.

Bad??:: Something very wrong:: << IT WAS MY TIRED SOLDERED PCB BOARD >>
I got the sample scrollTest to run like 3 times out of 10 (and counting)? Only on one of my display units that both run my recent touch work.
>> single LED flicker and screen stays dark, no USB output.
- device does power on USB, didn't add any test prints
- added while wait on serial just to slow the start down - no help
- removed the reset pin definition I've not used - no help

Good::
Used: C:\tCode\libraries\ILI9341_t3
Not used: I:\Teensy166\hardware\teensy\avr\libraries\ILI9341_t3



Dropped it in my libraries and didn't even restart IDE 1.6.6 and it found it next compile - this seems like good 'new' behavior - except the "FILE menu - Examples" isn't updated without a restart?
 
Last edited:
Bad??:: Something very wrong::
I got the sample scrollTest to run like 3 times out of 10 (and counting)? Only on one of my display units that both run my recent touch work.
>> single LED flicker and screen stays dark, no USB output.
- device does power on USB, didn't add any test prints
- added while wait on serial just to slow the start down - no help
- removed the reset pin definition I've not used - no help

Not sure if I understood what went wrong here.... did you noticed that the test code has a " while (!Serial)" ? So it will only start printing stuff to the tft when you open the serial monitor, i probably should have removed it.
I tested the code on the adafruit tft, I'll test it using the one provided by Paul today. Which one are you using?

Is the size increase a deal breaker? Is the functionality even worth it?
 
Back
Top