Playing around with yet another version of ILI9341_t3 library (ILI9341_t3n)

Yes you can run multiple displays on the same SPI buss, with certain limitations. That is if you setup the display to do Async updates (DMA), only one can do it at a time. Also not sure if I have it setup to reconfigure the DMA if you try to switch them between updates.
 
In the header you could use something like this to define the two screens:

Code:
#define TFT_RST  8
#define TFT_DC   9
#define TFT_CS  10

#define TFT_RST2 21 
#define TFT_DC2  20
#define TFT_CS2  15

ILI9341_t3 tft = ILI9341_t3(TFT_CS, TFT_DC, TFT_RST);
ILI9341_t3 tft2 = ILI9341_t3(TFT_CS2, TFT_DC2, TFT_RST2);

In the setup:

Code:
  tft.begin();
  tft.setTextColor(BLACK);
  tft.setRotation(3); 
  tft.fillScreen(ILI9341_GREEN);
  tft.setTextSize(1);
  tft.setCursor(320-80,0);
  tft.print("First TFT"); 

  tft2.begin();
  tft2.setTextColor(BLACK);
  tft2.setRotation(3);
  tft2.fillScreen(ILI9341_RED);
  tft2.setTextSize(1);
  tft2.setCursor(320-80,0);
  tft2.print("Second TFT");
 
Note they can share the same DC pin. The RST pin can sort of be shared or not, but if shared probably don't specify it in the second instance you do the begin on...
Also before you do the begin you need to either have PU resistors on the CS pins or make sure both cs pins are high (you can cheat on the first one you do the begin on...

That is
Code:
  pinMode(TFT_CS2, OUTPUT);
  digitalWrite(TFT_CS2, HIGH); 

  tft.begin();
  tft.setTextColor(BLACK);
  tft.setRotation(3); 
  tft.fillScreen(ILI9341_GREEN);
  tft.setTextSize(1);
  tft.setCursor(320-80,0);
  tft.print("First TFT"); 

  tft2.begin();
  tft2.setTextColor(BLACK);
  tft2.setRotation(3);
  tft2.fillScreen(ILI9341_RED);
  tft2.setTextSize(1);
  tft2.setCursor(320-80,0);
  tft2.print("Second TFT");
 
THX KurtE.

These screens are very fussy about the use of the Reset pin; to avoid headaches I suggest connecting to a separate RESET and DC pin on the second screen.

So far none of the ILI9341-SPIs with red PCBs have responded without using the RESET pin.
 
Thanks Guys! I'll do an experiment with the 2 tomorrow.

Is there anything you can suggest I read on DMA's and frame buffers? a little bit lost with that side of things.
 
Hey Everyone,

I have 2x screens running on SPI1 and it seems to be all well. My only issue so far is using the frame buffer. When I update both screens in the loop I end up with flashing. Is there something I'm missing or a better way to do this?

Secondly, Is there a way to Anti Alias fonts? I've seen there were a few posts on it, but I cant see how to do it.

Code:
#include <Arduino.h>
#include <SPI.h>
#include <ILI9341_t3n.h>
#include <SPIN.h>
#include <fonts/font_Raleway-Medium.h>
#include <colours.h>

#define TFT_SCLK 27
#define TFT_DC 40
#define TFT_MOSI 26
#define TFT_MISO 39
#define TFT1_RST 33
#define TFT1_CS 0
#define TFT2_RST 34
#define TFT2_CS 38

ILI9341_t3n tft_Track = ILI9341_t3n(TFT1_CS, TFT_DC, TFT1_RST, TFT_MOSI, TFT_SCLK, TFT_MISO);
ILI9341_t3n tft_Func = ILI9341_t3n(TFT2_CS, TFT_DC, TFT2_RST, TFT_MOSI, TFT_SCLK, TFT_MISO);

void setup()
{
  tft_Track.useFrameBuffer(true);
  tft_Track.begin();
  tft_Track.fillScreen(BACKGROUND);

  tft_Func.useFrameBuffer(true);
  tft_Func.begin();
  tft_Func.fillScreen(BACKGROUND);
}
void DrawIndicator(ILI9341_t3n ScreenRef,uint16_t Y, uint16_t X, uint16_t Width,uint16_t Border, uint16_t IndColour,const char *TEXT,bool Active)
{
  int OuterWidth = Width;
  int OuterHeight = Width / 2;
  int InnerWidth = OuterWidth - (Border*2);
  int InnerHeight = (OuterHeight - (Border*2));
  int IndHeight = (InnerHeight-6);
  int IndWidth = (IndHeight/3);
  uint16_t ActColour = BUTTON_ST;
  if (Active == true){
    ActColour = IndColour;
  }
  ScreenRef.fillRect(X, Y, OuterWidth, OuterHeight, BUTTON_ST);
  ScreenRef.fillRect(X + Border, Y + Border, InnerWidth, InnerHeight, BUTTON_BG);
  ScreenRef.fillRect(X + Border, Y + Border, InnerWidth, 2, BUTTON_HL);
  ScreenRef.fillRect(X + (OuterWidth-Border-IndWidth-2), Y + Border + 4, IndWidth, IndHeight,ActColour);
  ScreenRef.setTextColor(ILI9341_WHITE);
  ScreenRef.setFont(RalewayMedium_12);
  ScreenRef.setCursor(X+5,Y+(InnerHeight/2)-2.0);
  ScreenRef.print(TEXT);
}

void loop()
{
  DrawIndicator(tft_Track,30, 30,75,3,ILI9341_GREEN,"SOLO",true);
  DrawIndicator(tft_Func,30, 30,75,3,ILI9341_RED,"MUTE",true);
  tft_Track.updateScreen();
  tft_Func.updateScreen();
}
 
There are a few open Issues on the library, associated with drawing fonts, especially with where text is centered.

The issue is really shown up when you for example simply draw "-" as the character definition shows up stuff. An earlier post on the issue shows like the sketch:
Code:
#include <ILI9341_t3n.h>
#include "ili9341_t3n_font_Arial.h"

//****************************************************************************
// Settings and objects
//****************************************************************************

#define TFT_DC  9
#define TFT_CS 7
#define TFT_RST 8
#define TFT_SCK 13
#define TFT_MISO 12
#define TFT_MOSI 11
#define TOUCH_CS  6

ILI9341_t3n tft = ILI9341_t3n(TFT_CS, TFT_DC, TFT_RST, TFT_MOSI, TFT_SCK, TFT_MISO);

void drawTextWithBoundingRect(uint16_t x, uint16_t y, const char *str) {
  int16_t x1, y1, w, h;
  tft.setCursor(x, y);
  tft.getTextBounds(str, x, y, &x1, &y1, &w, &h);
  tft.print(str);
  tft.drawRect(x1, y1, w, h, ILI9341_RED);
}
void drawCenteredText(uint16_t x, uint16_t y, uint16_t w, uint16_t h,
                      const char *str) {
  tft.fillRect(x, y, w, h, ILI9341_YELLOW);
  tft.setTextColor(ILI9341_RED, ILI9341_YELLOW);
  tft.setCursor(x + w / 2, y + h / 2, true);
  //  tft.setClipRect(x, y, w, h);
  tft.print(str);
  //  tft.setClipRect();
}

void setup()
{
  Serial.begin(9600);
  delay(3000);
  while (!Serial && millis() < 5000) ;
  Serial.println("Teensy 3.2 TFT Clock Program");

  #pragma region DISPLAY INITIALIZATION
  Serial.println("Initializing TFT display");

  tft.begin();
  tft.fillScreen(ILI9341_BLACK);
  tft.setTextColor(ILI9341_YELLOW);
  tft.setTextSize(2);
  tft.setRotation(1);

  tft.setFont(Arial_40);

  drawTextWithBoundingRect(20, 20, "-");
  drawTextWithBoundingRect(60, 20, "+");
  drawTextWithBoundingRect(100, 20, "X");
  drawTextWithBoundingRect(140, 20, "Next");

  drawCenteredText(20, 100, 35, 50, "-");
  drawCenteredText(60, 100, 35, 50,  "+");
  drawCenteredText(100, 100, 35, 50,  "X");
  drawCenteredText(140, 100, 130, 50,  "Next");
}


void loop(void)
{
}

The first - where I would draw the bounding rectangle was wrong: The code has changed since then, but initially the Top characters with rectangles were drawn like the ones in this picture.
IMG_1344.jpg

The code associated with the picture is up in the issue: https://github.com/KurtE/ILI9341_t3n/issues/38

I have a fix for the bounding text, which appears to work, but then run into still some issue with the centering of text as you can see in the next image:
IMG_1345.jpg

Still - is not getting up to appropriate spot, also with the opaque text output, you can see how it extends beyond the actual rectangle...
So I thought I would see about turning on the clip rectangle, which uncovers another issue :eek:
IMG_1346.jpg

Like the clipping rectangle intercepts with the actual text...

Looks like some more tweaks needed and that implies probably in several libraries!
 
Pushed up changes to ILI9341_t3n for the first two issues. And changed test code to not give me the third for now...

Probably need to try on some other displays as well.

Next will try ILI9488_t... as plugs in to same setup...
 
Was beginning to play with the example that you posted. Will have to down load the changes

Just tested the changes to ILI9341_T3n and looks like they worked. Also ran font test 4 with an added - sign to center text and it looked fine as well.
 
Last edited:
I just did PR to you on ILI9488_t3 (tried ILI9341_t3, but we did not add it to that library)...
Code:
#include <ILI9488_t3.h>
#include "ILI9488_t3_font_Arial.h"

//****************************************************************************
// Settings and objects
//****************************************************************************

#define TFT_DC  9
#define TFT_CS 7
#define TFT_RST 8
#define TFT_SCK 13
#define TFT_MISO 12
#define TFT_MOSI 11
#define TOUCH_CS  6

ILI9488_t3 tft = ILI9488_t3(TFT_CS, TFT_DC, TFT_RST, TFT_MOSI, TFT_SCK, TFT_MISO);

void drawTextWithBoundingRect(uint16_t x, uint16_t y, const char *str) {
  int16_t x1, y1, w, h;
  tft.setCursor(x, y);
  tft.getTextBounds(str, x, y, &x1, &y1, &w, &h);
  tft.print(str);
  tft.drawRect(x1, y1, w, h, ILI9488_RED);
}
void drawCenteredText(uint16_t x, uint16_t y, uint16_t w, uint16_t h,
                      const char *str) {
  tft.fillRect(x, y, w, h, ILI9488_YELLOW);
  tft.setTextColor(ILI9488_RED, ILI9488_YELLOW);
  tft.setCursor(x + w / 2, y + h / 2, true);
    tft.setClipRect(x, y, w, h);
  tft.print(str);
    tft.setClipRect();
}

void setup()
{
  Serial.begin(9600);
  delay(3000);
  while (!Serial && millis() < 5000) ;
  Serial.println("Teensy 3.2 TFT Clock Program");

  #pragma region DISPLAY INITIALIZATION
  Serial.println("Initializing TFT display");

  tft.begin();
  tft.fillScreen(ILI9488_BLACK);
  tft.setTextColor(ILI9488_YELLOW);
  tft.setTextSize(2);
  tft.setRotation(1);

  tft.setFont(Arial_40);

  drawTextWithBoundingRect(20, 20, "-");
  drawTextWithBoundingRect(60, 20, "+");
  drawTextWithBoundingRect(100, 20, "X");
  drawTextWithBoundingRect(140, 20, "Next");

  drawCenteredText(20, 100, 35, 50, "-");
  drawCenteredText(60, 100, 35, 50,  "+");
  drawCenteredText(100, 100, 40, 50,  "X");
  drawCenteredText(150, 100, 130, 50,  "Next");
}


void loop(void)
{
}
 
@KurtE
Just merged the PR probably as you were typing the post.

EDIT: Just tested and it worked as you said.

How about I do the HX8357 and the ST7735? First coffee and then the changes.
 
I have fix for ST7735/89... Pushed a PR

Will let you do the HX8357... Not sure where in my pile of displays I have that one, with a cracked screen
 
I have fix for ST7735/89... Pushed a PR

Will let you do the HX8357... Not sure where in my pile of displays I have that one, with a cracked screen

Cool. Just made to changes to ST7735 and HX8357 and was testing the changes for the HX8357. Test for HX8357 worked so going to push up the change for that display as well.
 
Darn it - forgot about the RA8875 guess we will have to the do the RA8876 - that one is on me.


UPDATE: Just fixed it in @wwatson's RA8876 library and issued a PR.
 
Last edited:
Darn it - forgot about the RA8875 guess we will have to the do the RA8876 - that one is on me.


UPDATE: Just fixed it in @wwatson's RA8876 library and issued a PR.

Yep ;) - Note I uploaded the changes without fixing secondary issue. looks like that text output is not being constrained by clip rectangle.

I have not fully investigated yet. Figured it is a secondary issue, that I don't think any of these changes impacted.
 
Yep, As mentioned found an interesting display bug that we replicated in several places including the RA...

Speaking of RA... Even after that fix still issue:
Code:
#include <Adafruit_GFX.h>

#include <SPI.h>
#include <RA8875.h>

#include "font_Arial.h"
//****************************************************************************
// Settings and objects
//****************************************************************************

#define RA8875_CS 9
#define RA8875_RST 8
RA8875 tft = RA8875(RA8875_CS, RA8875_RST);

void drawTextWithBoundingRect(uint16_t x, uint16_t y, const char *str) {
  int16_t x1, y1;
  uint16_t  w, h;
  tft.setCursor(x, y);
  tft.getTextBounds(str, x, y, &x1, &y1, &w, &h);
  tft.print(str);
  tft.drawRect(x1, y1, w, h, RA8875_RED);
}
void drawCenteredText(uint16_t x, uint16_t y, uint16_t w, uint16_t h,
                      const char *str) {
  tft.fillRect(x, y, w, h, RA8875_YELLOW);
  tft.setTextColor(RA8875_RED, RA8875_YELLOW);
  tft.setCursor(x + w / 2, y + h / 2, true);
    tft.setClipRect(x, y, w, h);
  tft.print(str);
    tft.setClipRect();
}

void setup()
{
  Serial.begin(9600);
  delay(3000);
  while (!Serial && millis() < 5000) ;
  Serial.println("Teensy 3.2 TFT Clock Program");

  Serial.println("Initializing TFT display");

  //  begin display: Choose from: RA8875_480x272, RA8875_800x480, RA8875_800x480ALT, Adafruit_480x272, Adafruit_800x480
  tft.begin(Adafruit_800x480, 16, 15000000);

  tft.fillWindow(RA8875_BLACK);
  tft.setTextColor(RA8875_YELLOW);
  tft.setTextSize(2);
  tft.setRotation(1);

  tft.setFont(Arial_40);

  drawTextWithBoundingRect(20, 20, "-");
  drawTextWithBoundingRect(60, 20, "+");
  drawTextWithBoundingRect(100, 20, "X");
  drawTextWithBoundingRect(140, 20, "Next");

  drawCenteredText(20, 100, 35, 50, "-");
  drawCenteredText(60, 100, 35, 50,  "+");
  drawCenteredText(100, 100, 40, 50,  "X");
  drawCenteredText(150, 100, 130, 50,  "Next");
}


void loop(void)
{
}

Not clipping the text as you can see:
IMG_1347.jpg

May take a quick look, but would like to get back to Volume labels and formatting.
 
Hello,

I'm glad I found this thread and ILI9341_t3n library because I'd like to get a small 2.8 TFT to work with Teensy LC as fast as possible.
What I realized scrolling through the posts, is that this will be much harder to me, as I first thought. :)

I hooked up a test on a breadboard, it works as expected. My goal is to continuously update the display, showing circles with changing XY coordinates (and maybe print some data next to the circle). The circles represent objects, their number can be up to 5-10. The objects data will be updated approx. every 50ms in one package, so the display update should be well below this.

I wrote a very basic attempt, just moving one circle around the display. But this already takes 14ms to refresh and it is only one object.
This is where I realized I really need some help about this.

Code:
#include "SPI.h"
#include "ILI9341_t3n.h"
// *************** Change to your Pin numbers ***************
#define TFT_DC  9
#define TFT_CS 10
#define TFT_RST 8
#define TFT_SCK 13
#define TFT_MISO 12
#define TFT_MOSI 11
#define TOUCH_CS  6

ILI9341_t3n tft = ILI9341_t3n(TFT_CS, TFT_DC, TFT_RST, TFT_MOSI, TFT_SCK, TFT_MISO);
#define DEBUG_PIN 0

unsigned int displayWidth = 0u;
unsigned int displayHeight = 0u;
unsigned int middleWidth = 0u;
unsigned int bottomLine = 0u;
unsigned long testMicros = 0ul;
unsigned long millisTimer = 0ul;

void setup()
{
  while (!Serial && millis() < 5000) ; // wait for Arduino Serial Monitor
  Serial.begin(9600);
  delay(500);
  Serial.println("ILI9341 Test!");
  pinMode(DEBUG_PIN, OUTPUT);
  tft.begin();
#ifdef  SPI0_DISP2
  Serial.println("Reset pin 10 to output");
  //  pinMode(10, INPUT_PULLUP);
#endif
  Serial.println("After TFT Begin");
  tft.fillScreen(ILI9341_BLACK);
  Serial.println(CORE_PIN10_CONFIG, HEX);
  Serial.println(ILI9341_SPICLOCK);
  tft.setTextColor(ILI9341_YELLOW);

  tft.setTextSize(1);
  tft.setRotation(1);

  displayWidth = tft.width(),
  middleWidth = displayWidth / 2;
  displayHeight = tft.height();
  bottomLine = displayHeight - 10;
  
  tft.setCursor(middleWidth, bottomLine);
  tft.setTextColor(ILI9341_YELLOW);
  tft.print("R");

  millisTimer = millis();
}


void loop(void)
{
  if ( (millis() - millisTimer) >= 33ul)
  {
    static unsigned int var = 0u;
    char objectData[32];
    testMicros = micros();
    //tft.fillScreen(ILI9341_BLACK);
    tft.drawLine(0, bottomLine - 92, middleWidth, bottomLine, ILI9341_YELLOW);
    tft.drawLine(middleWidth, bottomLine, displayWidth, bottomLine - 92, ILI9341_YELLOW);

    tft.setTextColor(ILI9341_BLACK);
    tft.setCursor(var + 5, 200 + 5);
    sprintf(objectData, "%d, %d", var + 5, 200 + 5);
    tft.print(objectData);
    //tft.print(var+5);tft.print(", ");tft.print(120+5);
    tft.fillCircle(var, 200, 2, ILI9341_BLACK);
    var += 5u;
    if (var > 280u)
    {
      var = 0u;
    }
    tft.fillCircle(var, 200, 2, ILI9341_CYAN);
    tft.setCursor(var + 5, 200 + 5);
    tft.setTextColor(ILI9341_CYAN);
    sprintf(objectData, "%d, %d", var + 5, 200 + 5);
    tft.print(objectData);
    //tft.print(var+5);tft.print(", ");tft.print(120+5);

    Serial.println(micros() - testMicros);
    millisTimer = millis();
    //testFastLines(ILI9341_RED, ILI9341_BLUE);
  }
}


I read about the DMA method used in this library which speeds up things, is DMA mode used by default or should I enable it?
The code is in a very early stage (no arrays for multiple object data, etc.), but I get the feeling that I'm already on a wrong track.
How could I make this display refresh fast? Is Teensy LC enough for this or do I need an advanced board?

Few thoughts about the display method:
- the objects can cross the diagonal lines, so they has to be redrawn (probably a constant rectangle in the middle will has to be also drawn), the line positions are not intended to change
- I used small radius circle for the object, because as the test shows, bigger circle contain more pixels resulting higher display time (?)
- instead of full fill screen, only the previous pixels are "erased" by overwrite them with black pixels

Any help is appreciated.

Thanks in advance, amazed
 
Finally I changed to T4.0 and got some good results.

I managed to enable useFrameBuffer (tft.useFrameBuffer(true) call returns with true), but I can't compile into the sketch the
Code:
tft.updateChangedAreasOnly(true);
I get an error:

"C:\...\ILI9341_t3n-master\src/ILI9341_t3n.h:995:8: error: 'void ILI9341_t3n::updateChangedAreasOnly(bool)' is protected
void updateChangedAreasOnly(bool updateChangedOnly) {
^
Teensy_TFT:55: error: within this context
tft.updateChangedAreasOnly(true);"

But this is one thing, because even if I change the default value to true in the header file
Code:
bool _updateChangedAreasOnly = true; // current default off,
The whole screen is updated after calling tft.updateScreen(); and I have flickering screen and slow refresh rate.

Anybody has an idea what's going on?

The whole sketch:
Code:
#include "SPI.h"
#include "ILI9341_t3n.h"
#include "constants.h"
#include "variables.h"

ILI9341_t3n tft = ILI9341_t3n(TFT_CS, TFT_DC, TFT_RST, TFT_MOSI, TFT_SCK, TFT_MISO);

void setup()
{
  Serial.begin(57600);
  delay(500);

  initDisplay();
  if ( tft.useFrameBuffer(true) ) Serial.println("Frame buffer is enabled!");
  millisTimer = millis();
}


void loop(void)
{
  if ( (oneTimeRefresh == true) ||
       ((runningRefresh == true) &&
       ((millis() - millisTimer) >= 40ul)) )
  {
    oneTimeRefresh = false;
    testMicros = micros();

    /*first clear previously displayed objects*/
    clearDisplayedObjects();

    /*update values, this is just another for cycle at this point*/
    getObjectData();

    /*finally draw the FOV lines and update the display with new objects*/
    drawFovLines();    
    updateObjectDisplay();

    //tft.updateChangedAreasOnly(true);
    tft.updateScreen();
    millisTimer = millis();
  }

  readTerminalInput();

}

void clearDisplayedObjects()
{
  char textToDisplay[32];

  tft.setTextSize(1);

  for (byte i = 0; i < MAX_OBJECT_NUMBER; i++)
  {
    if (objectData[i].trackStatus == OBJECT_TRACKED)
    {
      tft.fillCircle(xPos_px[i], yPos_px[i], CIRCLE_SIZE, ILI9341_BLACK);
      sprintf(textToDisplay, "%.1f, %.1f", objectData[i].xPos, objectData[i].yPos);
      tft.setCursor(xPos_px[i] + OBJECT_TEXT_OFFSET, yPos_px[i] + OBJECT_TEXT_OFFSET);
      tft.setTextColor(ILI9341_BLACK, ILI9341_BLACK);
      tft.print(textToDisplay);
    }
  }
}

void getObjectData()
{
  for (byte i = 0; i < MAX_OBJECT_NUMBER; i++)
  {
    objectData[i].trackStatus = (byte)random(OBJECT_NOT_TRACKED, OBJECT_TRACKED + 1);
    objectData[i].xPos = (float)((float)random(AREA_LEFT_M * 10, AREA_RIGHT_M * 10) / 10.0f);
    objectData[i].yPos = (float)((float)random(AREA_CLOSER_M * 10, AREA_FARTHER_M * 10) / 10.0f);
    //objectData[i].objectSpeed = (float)((float)random(20,400)/10.0f)
    //objectData[i].trackStatus = OBJECT_TRACKED;
  }
}

void drawFovLines()
{
  tft.drawLine(0, displayHeight - 94, middleWidth, displayHeight - 2, ILI9341_YELLOW);
  tft.drawLine(middleWidth, displayHeight - 2, displayWidth, displayHeight - 94, ILI9341_YELLOW);
  tft.drawFastVLine(areaLeftVLine, areaFartherHLine, areaCloserHLine - areaFartherHLine, ILI9341_CYAN);
  tft.drawFastVLine(areaRightVLine, areaFartherHLine, areaCloserHLine - areaFartherHLine, ILI9341_CYAN);
  tft.drawFastHLine(areaLeftVLine, areaCloserHLine, areaRightVLine - areaLeftVLine, ILI9341_CYAN);
  tft.drawFastHLine(areaLeftVLine, areaFartherHLine, areaRightVLine - areaLeftVLine, ILI9341_CYAN);
}

void updateObjectDisplay()
{
  byte objectCounter = 0;
  char textToDisplay[32];

  tft.setTextSize(1);

  for (byte i = 0; i < MAX_OBJECT_NUMBER; i++)
  {
    if (objectData[i].trackStatus == OBJECT_TRACKED)
    {
      xPos_px[i] = middleWidth + (int16_t)(objectData[i].xPos * (float)METER_TO_PIXEL_FACTOR_X_AXIS);
      yPos_px[i] = displayHeight - (int16_t)(objectData[i].yPos * (float)METER_TO_PIXEL_FACTOR_Y_AXIS);
      tft.fillCircle(xPos_px[i], yPos_px[i], CIRCLE_SIZE, ILI9341_CYAN);
      sprintf(textToDisplay, "%.1f, %.1f", objectData[i].xPos, objectData[i].yPos);
      tft.setCursor(xPos_px[i] + OBJECT_TEXT_OFFSET, yPos_px[i] + OBJECT_TEXT_OFFSET);
      tft.setTextColor(ILI9341_CYAN, ILI9341_BLACK);
      tft.print(textToDisplay);
      objectCounter += 1;
    }
  }

  /*print additional information text*/
  /*objectCounter*/
  sprintf(textToDisplay, "%2d  ", objectCounter);
  tft.setCursor(xPos_oC_text, yPos_oC_text);
  tft.setTextColor(ILI9341_YELLOW, ILI9341_BLACK);
  tft.print(textToDisplay);

  /*approx. refresh time*/
  sprintf(textToDisplay, "%2dms ", ((int)((micros() - testMicros) / 1000u)) );
  tft.setTextColor(ILI9341_NAVY, ILI9341_BLACK);
  tft.setCursor(displayWidth - 25, bottomLine);
  tft.print(textToDisplay);
}


void readTerminalInput()
{
  if (Serial.available())
  {
    char rc = Serial.read();
    if (rc == 's')
    {
      runningRefresh = !runningRefresh;
    }
    else if (rc == 'o')
    {
      oneTimeRefresh = true;
    }
  }
}

void initDisplay()
{
  tft.begin();
  tft.fillScreen(ILI9341_BLACK);

  tft.setRotation(1);
  displayWidth = tft.width(),
  middleWidth = (int16_t)(displayWidth / 2);
  displayHeight = tft.height();
  bottomLine = displayHeight - 10;
  
  Serial.println(CORE_PIN10_CONFIG, HEX);
  Serial.println(ILI9341_SPICLOCK);

  for (byte i = 0; i < MAX_OBJECT_NUMBER; i++)
  {
    objectData[i].trackStatus = OBJECT_NOT_TRACKED;
    objectData[i].xPos = 0.0f;
    objectData[i].yPos = 0.0f;
    objectData[i].objectSpeed = 0.0f;
    xPos_px[i] = 0;
    yPos_px[i] = 0;
  }

  areaLeftVLine = middleWidth + (int16_t)(AREA_LEFT_M * (float)METER_TO_PIXEL_FACTOR_X_AXIS);
  areaRightVLine = middleWidth + (int16_t)(AREA_RIGHT_M * (float)METER_TO_PIXEL_FACTOR_X_AXIS);
  areaCloserHLine = displayHeight - (int16_t)(AREA_CLOSER_M * (float)METER_TO_PIXEL_FACTOR_Y_AXIS);
  areaFartherHLine = displayHeight - (int16_t)(AREA_FARTHER_M * (float)METER_TO_PIXEL_FACTOR_Y_AXIS);

  tft.setCursor(5, bottomLine);
  tft.setTextColor(ILI9341_YELLOW, ILI9341_BLACK);
  tft.print("objectCounter: ");
  tft.getCursor(&xPos_oC_text, &yPos_oC_text);
}
 
@amazed - try syncing up to my library again. I just moved that method out of protected: and into public:
 
@KurtE: thanks for the quick respond. Yes, it helped. It compiles now.

But it still refreshes the whole screen. The time spent with tft.drawLine, tft.fillCircle and tft.print executions are considerably lower (10ms versus 1-2ms), but the time to execute tft.updateScreen() is around 43ms and the screen flickers.
 
Hi Guys,

I have a bit of a weird one here on a teensy4.1, maybe someone can help.

I'm using PlatformIO and have tried lib_deps = kurte/ILI9341_t3n @ 0.0.0-alpha+sha.f1bfb81825 and lib_deps = https://github.com/KurtE/ILI9341_t3n

I have:
Code:
#define TFT_DC 9
#define TFT_CS 10
ILI9341_t3n tft = ILI9341_t3n(TFT_CS, TFT_DC);

At the start of setup() I turn the led on.

If I build with just that code the teensy starts up fine, led on and com port available.

If I include at any point in the code tft.begin(); then the teensy doesn't start up, the led is not lit, the serial port is not available and it requires the button to be pressed to flash it.

Including other calls such as tft.fillScreen(ILI9341_BLACK); and it starts up fine (as long as there is no call to begin()), it only seems to be the begin() that is causing this.

Has anyone got any ideas or maybe some ideas of how I can track down what is going on here?

Many thanks

Andy

Code:
#include <Arduino.h>
#include <ILI9341_t3n.h>

#define TFT_DC 9
#define TFT_CS 10
ILI9341_t3n tft = ILI9341_t3n(TFT_CS, TFT_DC);

void setup() 
{
  pinMode(13, OUTPUT); // LED pin
  digitalWrite(13, 1);

  Serial.begin(115200); 

  Serial.printf("Started\n");
  tft.begin(); // Remove this and it starts fine
}

void loop() 
{
  Serial.printf("running\n");
}
 
Last edited:
OK, got the issue but I'm not sure why it is causing a problem.

Building with -o0 or -og causes the issue.

Building with -os, -01, -02, -03 everything is fine.

Anyone any ideas?
 
Back
Top