XPT2046 Touchscreen project questions

Status
Not open for further replies.

GeraltMCU

Member
I have a Teensy 3.2 and the 2046 touchscreen with the _t3 library. I've successfully gotten the blink program to run so I'm working on the touchscreen next. I'm not using the Arduino IDE but simply compiling and uploading from Cygwin on Win 7 Pro and that works well (later I'll do an IDE but not now). I'm using a CPP style main from the Teensy core files. I'm also looking at Defragster's XPT2046_Touchscreen github work as an example and have some questions.

1. I'm compiling with SPI so I assume that's what actually talks to the touchscreen unit?

2. I'm seeing some confusing documentation.

A. https://www.pjrc.com/store/display_ili9341_touch.html lists a ILI9341_t3 tft = ILI9341_t3(TFT_CS, TFT_DC, TFT_RST, TFT_MOSI, TFT_SCLK, TFT_MISO); as initializiation but Defragster only has two parameters to his call. The ILI9341_t3 source file does not default any of the parameters. This call takes care of the Display portion (the ILI9341) so if I want to use touch I need to add some defines for the T_pins then - correct? The page is for touch but only talks about the display portion of the unit and not the touch setupo.

B. https://www.pjrc.com/store/display_ili9341_touch.html also lists a standard Teensy and Audio. I have, as far as I know a plain Teensy 3.2 that does not have any Audio. Yet according to the section on the optimized library I need to use the pins for the Teensy 3.x with Audio board. I assume that's because the optimized library requires that. Basically I can use any alternates I want as long as I keep to the SPI guidelines.

C. If I'm using the SPI library shouldn't I be using calls like SPI.begin() instead of Serial.begin() or does the Touchscreen library handle that. In the ILI9341_t3.cpp library source there are some Serial.Prints that are commented out so I assuem they are debugging. Or is this Serial for communicating with the console? I seem to remember one of Defragster's posts discussing it worked with the console but not without.

D. The SPI lists four pins that it uses and the XPT2046 has 14. CC, GND, LED are obvious. I assume a non touch would not have the T_ pins which are for touch screen communication.

3. The Welcome to Teensy 3.2 card (very nice including that. It has been very helpful) has pins like CS in bold and also non-bold. I assume Bold is default with non-bold being alternates. Kudos to whoever thought up the card.

I'm assuming once I hook up the pins and download a simply program such as this I should get a red screen. Is that correct?

Thanks.


#include "WProgram.h"
#include "XPT2046_Touchscreen.h"
#include "ILI9341_t3.h"
#include "font_Arial.h"
#include "SPI.H"


/*
Defines for pins.
*/

#define DC_PIN 20
#define CS_PIN 21
#define RST_PIN 255
#define MOSI_PIN 7
#define SCLK_PIN 14
#define MISO_PIN 12

/*
Interrupt pin
*/

#define TIRQ_PIN 2

#define LEDON true

ILI9341_t3 tft = ILI9341_t3(CS_PIN, DC_PIN,RST_PIN, MOSI_PIN, SCLK_PIN, MISO_PIN);
XPT2046_Touchscreen ts = XPT2046_Touchscreen(CS_PIN,TIRQ_PIN);


extern "C" int main(void)
{
#ifdef USING_MAKEFILE

/*
Variables
*/


/*
Initial setup.
*/
Serial.begin(38400);
tft.begin();
tft.setRotation(1);
tft.fillScreen(ILI9341_RED);
ts.begin();
while (!SERIAL && (millis() <= 10000)); /* Give it time to initalize. */
} /* End main
 
Hi GeraltMCU - not sure which of my samples had abbreviated params on tft creation. If I did it - those pins are default for SPI in the core code. I started wiring from the store page. The Audio board is a separate piece of hardware - without that you can use the standard SPI pins without change.

SPI I/O is handled by the driver/library as needed internally once it is created and ready for use after .begin.

To have the Touch interrupt functionality you need to connect and specify that pin as indicated - on github if not elsewhere.

If you have Serial.begin and compile for USB_Serial then a serial monitor program on the USB port will show the results of Serial.print(), debug or otherwise.

The Touch unit like the display itself is SPI and those pins are common, except for a unique CS (chip select) that is used for SPI to get to 'that' device - as wired on the store page for that touch display. Again the T_IRQ ia an added pin that keeps noise off the SPI bus when no touch is selected and you poll for a touch.

Indeed the Teensy card is a great aide - the BOLD are the default for preferred use and the non-bold are those that can be used when conflicts require moving one or more - as is the acase when using the Audio Board.

Best forum support is when your code conforms to use in the Arduino IDE - puts everyone at a common start. At a glance that code suggests it will do that. Using the IDE gives numerous samples that run out of the box as a starting point.

Also you can get proper forum code formatting by wrapping your code in [C0DE]// CODE HERE - replace the "ZERO's" used here with upper case O[/C0DE]

I have a Teensy 3.2 and the 2046 touchscreen with the _t3 library. I've successfully gotten the blink program to run so I'm working on the touchscreen next. I'm not using the Arduino IDE but simply compiling and uploading from Cygwin on Win 7 Pro and that works well (later I'll do an IDE but not now). I'm using a CPP style main from the Teensy core files. I'm also looking at Defragster's XPT2046_Touchscreen github work as an example and have some questions.
 
I was looking at this page https://github.com/Defragster/XPT2046_Touchscreen/blob/master/examples/ILI9341Test/ILI9341Test.ino. The IL9341_t3.cpp constructor shows all parameters and I didn't see any defaults but no big deal. I'll just specify them all.

Ahh, I thought Serial. was for the console. I did one run with a Serial.println and it did print to a console (I used Putty connected to the com port that was assigned to the Teensy USB).

I see now in the source the begin sets everything up and calls SPI.Begin..

I'll go back and rewire things. I did have it setup per the store page but nothing worked but I see I have some other issues in my code.

I'm sorry - I just can't use the Arduino IDE. I'm just used to better tools. The big thing is it hides too much stuff behind the scenes and that gets in the way of really understanding it what is going on and will come back to bite me. If I'm going to do more than just run the examples and actually do real world projects I need to know what's going and how it all works. It's like GUI vs CLI. I love GUI things like SQL Server's tools because you can do things quickly and easily even if you don't know all the behind the scenes stuff so you can be productive quickly - BUT - if you are doing serious SQL Server work you need to dig into what's behind the GUI and understand what the mouse clicks are doing which means going back to the command line SQL tools or you'll destroy some data real quickly <G>! Arduino's a good IDE for someone who wants to build quick and dirty and not worry about what goes on.

I took that code directly from the Teensy cores/teensy3 directory (not sure who wrote it) so I hope it conforms <G>! I prefer using the full C++ syntax with the main.cpp using the format one would use in a C++ program because one it's what I'm familiar with and second again Arduino hides stuff with it's lack of main. I know it wraps all that up behind the scenes.

Oops. I forgot about the wrapping and I read it in the FAQs a day or two ago.

Thanks for the input. I'll go back, check the wiring, and try again.
 
Just a quick look at the ILI9341_t3.h this pops right out?

Code:
ILI9341_t3(uint8_t _CS, uint8_t _DC, uint8_t _RST = 255, uint8_t _MOSI=11, uint8_t _SCLK=13, uint8_t _MISO=12);

Good luck wiring - I soldered a proto board per the Store page and it worked first time with examples in TeensyDuino and the IDE.

Putty is horrid - do a forum search for TYQT - it has great serial support and much more custom for the Teensy - reset and upload from GUI.

Tools are tools - Arduino works and works for everyone here and still uses a real compiler and toolset under the covers - there are better and worse no doubt - but having a common toolset is critical as that is the basis of Teensy and this forum. Not sure it hides any features or functionality of Teensy or Paul would fix it.
 
What do you use for a soldering iron rig?

Yeah, Putty is terrible even for ssh <G>. That's why I use mputty when I can on windows and PAC on Linux. To be honest I forgot I had TyQt. I've fired it up and it's very nice.

Yeah, tools are tools but some make it easier. I just can't stand the Arduino IDE so I'd use UCIDE or some other anyway but right now the command line and UEStudio editor work fine. My code is the main.cpp from the Teeny cores/teensy3 directory so I hope it's compatible <G>. I prefer the C++ full program format but that's personal preference.
 
I got one of the temp controlled SparkFun units - prior version - and very pleased with it. Also been doing some surface mount stuff and solder paste is great stuff. You can tack it with an iron - I also did some with a $15 embossing heat gun that worked, but it moves a lot of air.
 
Thanks. I'll check that out. I need to get a decent unit for this kind of work. All I have is a 25 watt unit for audio system work.

I think I'll have to go with soldered boards as neither the touch or the color display even light up. They are getting 3.3 volts to them but not even a flicker - they stay dark. It must be the breadboard connections. Now I remember why way back when I went to wire wrapping.
 
My board is ugly - there is a pic of it on the display thread before I moved to the touch thread I started. But it worked - still works - though I think with all the touching something got loose. I did wire wrap under solder some of the pins - others I used larger wire. But wired per the directions on Proto board to sockets and it went well.
 
I took a quick look and didn't see it but it's a test setup - right <G>.

Am I wrong in figuring that even if the control lines are wrong the display should at least turn on and light given a VCC and ground connection? I'm using the 3.3V /250 ma max pin on the Teensy 3 as a power source but there is a 3.3V hole which is for soldering to and I assume gives the same as the pin next to pin 23 on the Teensy 3.2.

I need to get a list of parts I'll need since I'm getting back into this. The only things I have left are some molex pin removers (from the days I had to make molex power cables), some chip pullers, and some wire wrap tools. At one time I had some PCB design software (think mid-late 90's). It think it was called tango or something like that.

I also have just the color display and it doesn' work eithe so I'll have to see what's happening.
 
Yes - test quickly built: ILI9341-restive-touch-miso-not-connected

I got the Purple OSH test board noted on the store page and it works.

The Audio Board has a tutorial hardware set - uses shifted pins. With power and ground it takes 6 wires to get the SPI and LED working - there final sample and that doc shows it - easy. I have that here in front of me . . .
 
Nice board <G>. It works. That's what counts.

I used just the color display and wired it up like the store page but the display won't even light up. I assume even it there are not control wires but it has VCC and ground it should come alive to some color - or am I wrong?

I cut back to a very simple program that should simply make the screen pink with yellow text but I'm not even getting the initial setup running since the screen never turns red but given the screen doesn't seem alive I wouid expect that. I did check all wiring and it is good and tight. I have VCC where it's supposed to be at 3.3V. I haven't connected the LED connection on the displaybut I assume that's an indicator LED or am I wrong there, too?

Code:
/*
Touch - Test for XPT2046 Touchscreen.
*/

#include "WProgram.h"
#include "ILI9341_t3.h"
#include "font_Arial.h"
#include "SPI.H"


/* 
	Defines for pins.
*/

#define TFT_DC		20
#define TFT_CS		21
#define TFT_RST 	255
#define TFT_MOSI	7
#define TFT_SCLK	14
#define TFT_MISO	12

ILI9341_t3 tft = ILI9341_t3(TFT_CS, TFT_DC,TFT_RST, TFT_MOSI, TFT_SCLK, TFT_MISO);


extern "C" int main(void)
{
#ifdef USING_MAKEFILE

	/*
	Variables
	*/


	/*
		Initial setup.
	*/
	Serial.begin(38400);
	tft.begin();
	tft.setRotation(1);
	tft.fillScreen(ILI9341_RED);
	while (!SERIAL && (millis() <= 500));		/* Give it time to initalize. */
	/*
		Now start the loop waiting for input.
	*/
  
	Serial.println("Starting loop.");
	while(1)

	{
		tft.fillScreen(ILI9341_PINK);
		tft.setTextColor(ILI9341_YELLOW);
		tft.setFont(Arial_60);
		tft.setCursor(60,80);
		tft.print("Touch");
					
	} /* End while 1 loop */
	
/*
Here is stuff for Arduino type IDEs
*/

#else
		setup()
		while(1)
		{
			loop();
			yield();
		}
#endif
} // End main
 
Last edited:
{ your code encoding needs end slash: [/CODE] }

If it gets power the backlight comes on bright white. If the controller gets power it will color the LED layer - but that is about invisible without backlight. It takes both together to see color.

You may have a defective or damaged display. I've managed to not damage any - but never bought just one.

If you installed TeensyDuino / Installer to get the T3 libs - you have Arduino IDE - check your wiring and fire up one of the samples.
 
Crumps. I thought I put that in. Arrgh.

I put a resistor on the LED pin - didn't have a 100 so I used another close and now it comes on! Arrgh! At least now I know it works and the problem was me. I was thinking in terms of indicator and forgot many LCDs use the LED for backlighting. Now, on to actually play with it.

I did use the Arduino to to run an actual Ardunio and Teensy examples and it failed there but now I know why.

Thanks.
 
Amazing what happens when it all gets hooked up correctly! Now to start testing out the Flightsim functions and playing with it.

Do you do any PC board design and if so what do you use?
 
Status
Not open for further replies.
Back
Top