ILI9341 and XPT2046 for Teensy Touchscreen 320x240 display

Status
Not open for further replies.
I have a work in progress where:

User button text is a pointer to "TEXT" the compiler puts in FLASH, 4 byte pointer can be a string of user entered size, and the string* can change at runtime.

Pointer to button struct is passed on ButtonInit - so you can have multiple screens of buttons to swap.

Requires a 'sentinel' button to terminate the button list.

Button struct re-ordered - but it was going to change anyhow - put text string first - where it was the compiler was adding padding for word boundary it seemed
 
MULTIPAGE BUTTON SAMPLE, Button Text in FLASH, Code Prints usable Button Struct

TO RUN:
LC OFF as saved, and INTERRUPT used pin 2 :: Edit at top of sketch for otherwise
Uncomment this for the TeensyDuino 1.26 library and comment the latter line that gives a compile error:
Code:
//XPT2046_Touchscreen ts(CS_PIN);  // Param 2 - NULL - No interrupts and TeensyDuino version 1.26 libs

Compile and LOAD - it shows three button sets on screen 2 second delay
> The needed struct data is cut and paste ready on USB MONITOR

Then you must touch a button twice and it show the current screens

Final screen is loaded and buttons 1-4 are active:
#1 : Rotate screen
#2: switch to button map #2
#3: switch to button map #3
#4: switch to button map #4


Comments welcome!

Demonstrates:
Button draw from a struct
Struct can be changed during execution
Text strings from pointers to FLASH not RAM, the Pointers can be changed to RAM space during run time
Programmatic button creation of the struct from the sketch

<GitHub Tree is filled with weak stuff and subject to removal to make the good stuff easy to find, for now this is the ultimate>
 
Touch_Examples/tree/master/ColorButtonsMark3
Modularized version of the Mark2 code, Edited Page change buttons for functional labels.

User code now separate from the 260 lines of ButtonMap code, and the Button Map struct's are in a 62 line header file not the main INO file.

Not as Daunting to look at the minimal setup() and loop() under 100 lines.

I also clipped BTest() button test creator buttons so they are not stored if they go off 320 wide.

Buttons can be any location or size and a touch within them is returned by button. Here is the updated Auto Generated example.

Page2.jpg page3.jpg Page4.jpg Rotated.jpg
 
Purged some older examples from GitHub. Two are labeled '...'Mark3 - they are the best examples to date.

Ported this older example to new struct layout and the separate ButtonMap.cpp style sketch:
onoffbuttonMark3

In ColorButtonsMark3 , I halfway added the onoffbuttonMark3 example as an OOB labeled button #5. Here you can see the "slider" and the "toggle" and "Return" to other page #2. Adding all functionality would have cluttered the loop() code so I did not do that.
 
@vitormhenrique got a good looking ScrollTextArea() function set offered for the ILI9341 display.

Combined with the touch buttons and other on screen 'control' elements it could add up to a powerful and easy to use and update display. Without cursor and color commands cluttering up the user code - and all prints done relative to the editable 'control' structure - rather than hardcoded.

My primary project - forgotten for about 6 months now is 9DOF based using the MPU9250 units made by onehorse. On this larger 2.8" screen the various channels should be more easily displayed - and with multiple screen pages controlled by touch buttons it will be even easier to see any and all of the input channels without crowding the screen. I'm looking to finish fleshing out the button work and make it applicable to that use with scrolling data.
 
When TeensyDuino 1.27b2 comes out it should have usable 'Interrupt pin enabled polling' fully working - the pull I dropped for 1.27a was missing the low touch acceptance resulting in light touches turning off the ongoing polling prematurely. 1.27a works - but requires firm touches and some re-touches until the updated version drops.

Anyone working with this or the buttons seeing anything interesting - let me know

YouTube quick Movie of the buttons in action

The video colors are clear - if messed up at start go back to time 0. You'll note a button Mis-Hit - of course it happened on VIDEO - I hit ROT and it took it as a P_2. I don't often see them on buttons - but if running the PAINT sample sometime Jitter & Jump show dots left behind.
 
Last edited:
This is awesome, after working with displaying the CAN data in the other thread I had been wondering; could I swap to another "page" of data with a button press?
 
I've been neglecting it for other things - not sure how to clean and library'ize it ? But yeah - it is relatively Awesome, thanks for noticing!

If only it were cleaner and clearer how to use it as it is array of structure based data with long ordered lists of parameters to define the 'button. Perhaps a simpler cleaner sample would do. There are a couple more button types to effect and they will call for changes to the struct layout - I made a ToDo list that is now a month waiting.
 
Hi all,

I am having issues getting both of these libraries working, I'm not sure if the issues are linked or not. I have a display (same as https://www.pjrc.com/store/display_ili9341_touch.html) on a veroboard that is working fine with the Adafruit library, but changing over to the ILI9341_t library and I only get a white screen. I've tried with my code and with the ILI9341_t examples and get the same issues. No errors at compilation and for graphicstest the Serial output is as expected. I can see the LED on the SCK pin flashing with transactions too. same issues with 2 different ILI9341 screens, one has touch controller one doesn't so I'm thinking its an SPI issue as the touch controller isn't working either? I have the screens powered from 3V3 with the solder jumper closed.

Similarly the XPT2046 doesn't seem to be working. Touching the screen brings the IRQ pin low as expected but the data read is z=4095, x=0, y=0 regardless.

I've tried changing the clock frequency to no avail. Any help would be greatly appreciated! Thanks.
 
Very odd - doesn't sound like anything I've seen and not seeing info that gives me any ideas. What version of the IDE and TeensyDuino and OS are you using? As you explain it, it should just work. Must be missing something - but not sure what. So if you jump back to Adafruit the display just works on the next compile only changing the header line to uncomment one or the other of these top two lines?
//#include "Adafruit_ILI9341.h"
//#include <ILI9341_t3.h>
#include <XPT2046_Touchscreen.h>

You say you are changing speeds - so it must be an T_3.1 or 3.2 and not an LC? I've used the Adafruit code as I tested that on the LC won't run the ILI9341_t, but the TOUCH does.

Indeed the pin 13 LED is a blinker on SPI. If the T_IRQ is used when not touched no blink when just polling and no screen writes, and then when touched it will blink and will light to the degree you POLL the touch for updates, if you take out the IRQ it will always blink on each POLL.

I assume the 'jumper' you mention is the 'hardware mod' to get the SD to work? When I had my bad display I don't know if it would have worked with Adafruit to say if that display might have been okay on Adafruit so that doesn't help me see how that relates.
 
Hi defragster, thanks for the reply,

Yes it's a 3.2, I'll check the software versions when I get home, and yes switching between the include statements and object declarations is the only change I made,

#include "Adafruit_ILI9341.h" works, but

#include "ILI9341_t3.h" does not


I've tried with and without the interrupt mode both give the same result. I also tried simply reading the interrupt pin to see what it was doing.

By the jumper I mean the solder jumper that bypasses the 3V3 regulator. I'm powering it directly with 3V3.

Many thanks
 
I'm using arduino 1.6.8 and Teensyduino 1.28.

Just to check, is the Adafruit_GFX library automatically included by the ILI9341_t library? With the Adafruit_ILI9341 lib i have to include it myself, but with the ILI9341_t library I get redefinition errors if i have the GFX library included.

Edit: Posted before i actually looked at the source, I see that the relevant GFX functions are defined within the ILI9341_t library
 
Last edited:
The code I dropped above came from my Teensy LC test sketch and it was entered like this - so the LC uses the Adafruit and the T_3.3 uses the ILI9341_t3.h. Current Teensy ILI9341_t3.h it seems was divorced from the Adafruit.

Code:
#if LC
#include "Adafruit_ILI9341.h"
#else
#include <ILI9341_t3.h>
#endif
 
defragster, you are the best!
Your code (screen with butons) worked with the first!
And no need to calibrate the touch screen!
I think i should seriously think to redesign my last project so that i will use teensy 3.2 and your lib.

(i used arduino 1.8.0 and teensyduino 1.34)

Thank you for sharing!!!
 
Last edited:
Just wanted to add an update to my issue incase someone else comes searching... After poking all around with a scope I realised that the CS pin for the LCD was never transitioning... I had somehow managed to route it to a non hardware CS pin. The standard library just uses GPIO writes to CS, so that was working ok... A little green mod wire solved all my issues! Thanks for the hard work folks.
 
Hi,

I have (for a teensy bat detector https://forum.pjrc.com/threads/38988-Bat-detector) connected an ILI9341 TFT with XPT2046 on a teensy3.6. Using the standard test sketches from https://github.com/PaulStoffregen/XPT2046_Touchscreen I can get both the ILI and the XPT to work as planned.

But in the batdetector I am building the default SPI pins are (physically) occupied by the audio-board so I am now using alternative SPI connections (pins 27,28 and 39). The ILI is working as planned with this (DC/CS are still directly connected to pin 20/21).

On the informationpage for the XPT (https://www.pjrc.com/store/display_ili9341_touch.html) it states that the CS for the XPT can be set to any alternate pin.
So I have choosen to use pin 26, this does not seem to work. Anybody with a guess why this is the case ? Or should I line this up to a default CS pin (using a wire) on the audioboard ?

regards
Cor
 
IIRC and based on post #94 - a native CS0 pin are needed to make the optimized ILI9341_t3 code run.

The ILI is running as planned and I know it needs DC/CS from one of the default pins, its the XPT-CS that puzzles me as the documentation states I can use alternate-pins.
 
opps … the touch code does "pinMode(csPin, OUTPUT);" and digitalWrite() on specified csPin. As item #1 in the creation :: XPT2046_Touchscreen(uint8_t cspin, uint8_t tirq=255)

So that should work if the pin is properly indicated, connected and not otherwise 'consumed' in the sketch.
 
I will check my wiring once more with a multimeter

Edit: Just done and I have a direct connection from the pin on my TFT (with the touch CS) and pin26 on Teensy. Will make a temporary wire to pin8 on teensy later today to test
 
Last edited:
Perhaps test with : ...\hardware\teensy\avr\libraries\XPT2046_Touchscreen\examples\ILI9341Test\ILI9341Test.ino

Using your copy of :: ILI9341_t3(uint8_t _CS, uint8_t _DC, uint8_t _RST = 255, uint8_t _MOSI=11, uint8_t _SCLK=13, uint8_t _MISO=12);

Just to see there isn't some pin conflict?
 
Status
Not open for further replies.
Back
Top