2.8 TFT Color screen: how to tft.println int values?

Status
Not open for further replies.

rfresh737

Well-known member
I'm moving forward with the next part of my project using the TFT Color screen.

Now I have to display an integer value on the screen. This line worked when I had the Teensy 3.2 on my breadboard, but now with the Teensy 3.6, it prints gibberish on the screen. I've already positioned the cursor.

tft.println(screenX);

Is there something different I have to do with the 3.6?
 
It should work that same . . . was the same code tried on the T_3.2?
Simple sample code and more context and repair would help I suspect. What version of TeensyDuino is in use (if TD_1.34b1 it could be a factor of the toolchain)? Which display library?
 
Well, Paul and KurtE just helped me to get this TFT screen working on my 3.6 in another thread.

Here are my includes:

Code:
#include <XPT2046_Touchscreen.h>
#include "ILI9341_t3.h"
#include "font_Georgia.h"
#include "font_CourierNew.h"

#define CS_PIN  8
#define TFT_DC  9
#define TFT_CS 10

Yes, I was able to println integer variables when I was using the Teensy 3.2.
 
Here is my code:

Code:
#include <XPT2046_Touchscreen.h>
#include "ILI9341_t3.h"
#include "font_Georgia.h"
#include "font_CourierNew.h"

#define CS_PIN  8
#define TFT_DC  9
#define TFT_CS 10

int screenX = 1920;
int screenY = 1080;
int intDoneLeft = 182;
int intDoneTop = 160;
int intDoneWidth = 120;
int intDoneHeight = 60;
int intDoneTextTop = intDoneTop + 16;
int intDoneTextLeft = intDoneLeft + 32;
int intLine1Top = 76;
int intButtonRadius = 5;

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

XPT2046_Touchscreen ts(CS_PIN);
TS_Point p;

int screenWidth = 1920;
int screenHeight = 1080;

void setup()
{
	tft.begin();
	tft.setRotation(1);
	tft.fillScreen(ILI9341_BLACK);

	Serial.begin(9600);
	while (!Serial & millis() <4000)
	{
	}
	Serial.println("ILI9341 Test");
	if (!ts.begin())
	{
		Serial.println("Couldn't start touchscreen controller");
		while (1);
	}
	Serial.println("Touchscreen started");
}

void loop(void)
{
	tft.setRotation(1);
	tft.fillScreen(ILI9341_BLACK);

	tft.setTextColor(ILI9341_YELLOW);
	tft.setCursor(32, 10);
	tft.setFont(CourierNew_18);
	tft.println("Screen Resolution");

	tft.setTextColor(ILI9341_WHITE);
	tft.setCursor(71, intLine1Top);
	tft.setFont(CourierNew_12);
	tft.println("Screen Width:");
	tft.setCursor(86, intLine1Top);
	tft.println(screenX);
	tft.setCursor(61, intLine1Top + 20);
	tft.println("Screen Height:");
	tft.setCursor(86, intLine1Top + 20);
	tft.println(screenY);
	tft.fillRoundRect(intDoneLeft, intDoneTop, intDoneWidth, intDoneHeight, intButtonRadius, ILI9341_GREEN);
	tft.setFont(CourierNew_16);
	tft.setTextColor(ILI9341_BLACK);
	tft.setCursor(intDoneTextLeft + 4, intDoneTextTop + 8);
	tft.println("Done");
	tft.setFont(Georgia_12);
	while (1);
} // end Loop()
 
Last edited:
It's working now! I had one of my variables crossed with another one by mistake.

UPDATE: I may have spoken too soon!

The screen X Y values are printing on the screen -- but -- when I go to change the value and print again, I can still see the previous digits as the new value just over lays the old value. And I'm using the same screen X,Y location.

Is there some kind of screen refresh I need to do?
 
Last edited:
Determine the box area that contains the data and use:

tft.fillRect( xorigin, yorigin, xwidth yheight, ILI9341_BLACK ); // Clear the text area

Then write your new data.
 
The other option is opaque text, but I don't think those changes have been added to this library. Maybe I should merge some of my changes in from ILI9341_t3n into the mainline version...
 
Status
Not open for further replies.
Back
Top