Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 9 of 9

Thread: ILI9341_T3 question

  1. #1
    Junior Member KG5NII's Avatar
    Join Date
    Aug 2019
    Location
    Texas
    Posts
    14

    ILI9341_T3 question

    I have an old precision voltage reference project that used an Arduino Nano + ILI9341 touch screen. Yeah its slooooow , and now I am porting this project over to the Teensy 3.2. No really big issues, except for one particular annoying difference between the Adafruit ILI9341 library implementation and the T3 one. Under the original code when doing something like this:

    Code:
    tft.setCursor(x,y);
    tft.print("A Bit Of Text"); 
    tft.print("                ");
    tft.setCursor(x,y);
    tft.print("Some Different Text");
    Printing text over existing text blanked out the existing text and overwrote it as expected. However, using the T3 code, the character cell at a particular cursor location doesn't appear to be blanked out prior to writing the new character to the same location resulting in that particular position being garbled. I now have to do more esoteric things such as resorting to fillRect() using the display's current background color to erase any previously displayed text before issuing any subsequent tft.print()'s at the same location. Doing this is not the end of the world but is a real pain in the butt that I'd rather not have to resort to doing if I don't have to. Perhaps this behavior is there as a speed improvement? I don't know except I'd thought I would ask how you guys are handling this. I really, really, really don't want to use fillRect() for "DEL" or "Backspace" buttons on my touch keypad if there is a simpler way that I am missing.

    Cheers,
    KG5NII

  2. #2
    Senior Member
    Join Date
    Nov 2017
    Location
    Belgium
    Posts
    164
    You need to explicitly set the text background color. If not, printing text will behave as you described(transparent background).

    Code:
    tft.setTextColor(ILI9341_WHITE); //white text with transparent background
    
    tft.setTextColor(ILI9341_WHITE, ILI9341_BLACK); //white text with black background

  3. #3
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    5,731
    Yep - as @neurofun mentioned you have the option to either output transparent or opaque depending on if you set the background color or not...

    Also as you have not shown complete code, we can only guess that you are using default font. If you do a setFont to some other font, I don't believe that ili9341_t3 has support for Opaque output for those fonts. I do have that support in ili9341_t3n...

    Now if you were using T3.5, or T3.6 or T4 with ili9341_t3n, you could turn on frame buffer support, and then write a whole new screen and then say update me now...

    Again don't know your app, so suggestions on how to do text output, can vary.

    When I do output of text, like status messages and the like, that change I will often do things like:

    Code:
    tft.setCursor(x_field, y_field);
    tft.setTextColor(ILI9341_WHITE, ILI9341_BLACK);
    tft.print("xxx");
    tft.getCursor(&x, &y);
    tft.fillRect(x, y_startOfField, x_field_end-x, field_height, ILI9341_BLACK);  // blank out rest of field...
    Again you need to fill in what these fields are. If I wish to go as fast as possible, instead of blanking the whole rest of logical field, I might instead remember how far the previous text extended. That is the x from the previous call go get Cursor, and then you only need to blank from your current X to the previous x (if previous x > x)...

  4. #4
    Junior Member KG5NII's Avatar
    Join Date
    Aug 2019
    Location
    Texas
    Posts
    14
    Quote Originally Posted by neurofun View Post
    You need to explicitly set the text background color. If not, printing text will behave as you described(transparent background).

    Code:
    tft.setTextColor(ILI9341_WHITE); //white text with transparent background
    
    tft.setTextColor(ILI9341_WHITE, ILI9341_BLACK); //white text with black background
    Thank you for your reply.
    Yeah. That is what I thought. However, that doesn't seem to work. I was already doing that:

    Code:
    // DEL key pressed.  Remove last char from txtBuf and print txtBuf to update the value field on TFT
    txtBuf[curChar] = 0;
    if(txtBuf > 0) {
        curChar--;
        txtBuf[curChar] = ' ';      // space
    }
    Serial.print("txtBuf: ");Serial.println(txtBuf);
    tft.setFont(Arial_24_Bold);
    tft.setCursor(TEXT_X + 2, TEXT_Y+10);
    tft.setTextColor(ILI9341_MAGENTA, ILI9341_BLACK);        
    tft.print(txtBuf); 
    tft.setFont(Arial_16_Bold);
    That doesn't seem to work. So the text still has a transparent background. Now I'm wondering if it has something to do with the font. Will try a different one to see the effect.


    Cheers,
    KG5NII

  5. #5
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    5,731
    As I mentioned ILI9341_t3 does not support Opaque text drawing when you set a font, such as: tft.setFont(Arial_24_Bold);

    However as I mentioned: ili9341_t3n does...
    https://github.com/KurtE/ILI9341_t3n

    Which still requires my SPIN library https://github.com/KurtE/SPIN

    The issue of doing opaque fonts, is the character rectangle includes all of the space up to starting the next character... So it may draw a bigger area than you may want...
    So that is one of the reasons it also supports dlip rectangles, so you can tell the code to not draw below where you want that field to be...

  6. #6
    Junior Member KG5NII's Avatar
    Join Date
    Aug 2019
    Location
    Texas
    Posts
    14
    Quote Originally Posted by KurtE View Post
    As I mentioned ILI9341_t3 does not support Opaque text drawing when you set a font, such as: tft.setFont(Arial_24_Bold);

    However as I mentioned: ili9341_t3n does...
    Kurt,

    First: I appreciate you and your efforts, especially in the ILI9341 arena. Thank you.
    Second: Thank you for your reply.
    Third: Having tried out the _t3n code, I've concluded that since the UI in my project is about 99% complete, moving the project over to the new _t3n codebase is more trouble than what it is worth in that it resulted in more issues than it solved. No shocking revelation there and I suspected as much based on your comments. If I was starting the UI from scratch, it would have made more more sense to use the _t3n code. Guess a few fillRect() calls using the background color as the fill color is what I will do. No worries. I've more issues with touchscreen events bleeding over from one screen to the next than I do anything else, but that's another story...

    Cheers,
    KG5NII

  7. #7
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    5,731
    Good luck.

    When you mention switching to different library and causing more trouble than it is worth... Would be interesting to know what the issue may be.

    That is in theory the code base should be compatible with the _T3 library. I originally did this version as a testing mechanism for T3.6 beta to allow it to run on all of the SPI busses, then I merged in some Pull Requests for _t3 that never made it in, like the ability to set an offset and clip rectangle... Then FrankB created a version that had a frame buffer, that looked interesting so... More recently some others like @mjs513 added some more drawing primitives, and recently I added support to allow you to use the ADAFruit GFX library fonts as well (to be more compatible with Adafruit)... Although I also extended it to allow for Opaque text output...

    But again at the base of it all, it should be compatible with ili9341_t3 library. If you ran into some compatibility issues, it would be good to know, and hopefully we can get the code to work in a similar way...

    But again good luck and hope you project comes out well.

    Kurt

  8. #8
    Junior Member KG5NII's Avatar
    Join Date
    Aug 2019
    Location
    Texas
    Posts
    14
    Quote Originally Posted by KurtE View Post
    When you mention switching to different library and causing more trouble than it is worth... Would be interesting to know what the issue may be.
    Kurt,
    My application utilizes a numeric keypad along with a decimal point, a DEL and a SET button which all use the Adafruit_GFX_Button helper class. All of this is on a touchscreen of course. The UI was pretty much finished except for fixing the code for the DEL button, which you know, erases the last entered number and updates the value display. The DEL button routine eventually calls tft.fillRect(TEXT_X + 2, TEXT_Y + 10, TEXT_W-10, TEXT_H-20,ILI9341_BLACK); before doing the tft.print(textfield), so this solved the Opaque text drawing issue when trying to use Arial_24_Bold font. Otherwise the UI code is pretty much complete.

    The T3N code besides a few issues with the font naming of the header files (to be expected), the biggest issue (if you want to call it that) was the parameter changes in Adafruit_GFX_Button initButton(). Apparently, the code in the T3N tree now wants textSizeX, and textSizeY instead of a single textsize parameter. No worries. Took a look at the T3N header file and noticed the functions getTextSizeX() and getTextSizeY() and figured I'd just pass these functions to initButton(), but quickly found out those functions have not been implemented yet. So wasn't sure just how or where to get the values initButton() expected. I did plug in some numbers to get the code to compile, but couldn't get the text to fit inside the buttons. So it was at this point I determined I had reached the point of diminishing returns and just implemented a simple fillRect in the DEL key part of the code prior to updating the display with the new voltage. No worries.

    To be more specific about the original code in T3, making note of K_TEXTSIZE:



    Code:
    {
     tft.setRotation(1);
     tft.fillScreen(ILI9341_BLACK);
    
    #define K_X  80
    #define K_Y  90
    #define K_W 60
    #define K_H  30
    #define K_SPACING_X  20
    #define K_SPACING_Y  12
    #define K_TEXTSIZE  2
    
    
    #define SET_X  220
    #define SET_Y  38
    #define SET_W 60
    #define SET_H  30
    
    #define DP   9            
    #define DEL 11
    #define SET 12
    
    
    char keyLabel[13][5] = {"1", "2", "3",
                                       "4", "5", "6",
                                       "7", "8", "9",
                                       ".", "0", "DEL",
                                       "SET "};
    
    
    uint16_t keyColor = ILI9341_BLUE;
    Adafruit_GFX_Button numKey[13];
    tft.setFont(Arial_16_Bold);
      
      for (uint8_t row = 0; row < 4; row++) {
        for (uint8_t col = 0; col < 3; col++) {
          numKey[col + row * 3].initButton( &tft,
                                            K_X + col * (K_W + K_SPACING_X),
                                            K_Y + row * (K_H + K_SPACING_Y),
                                            K_W,
                                            K_H,
                                            ILI9341_YELLOW,
                                            keyColor,
                                            ILI9341_WHITE,
                                            keyLabel[col + row * 3],
                                            K_TEXTSIZE);
    
          numKey[col + row * 3].drawButton();
        }
      }
    
      numKey[SET].initButton( &tft,
                             SET_X,
                             SET_Y,
                             SET_W,
                             SET_H,
                             ILI9341_YELLOW,
                             ILI9341_DARKGREEN,
                             ILI9341_WHITE,
                             keyLabel[SET],
                             K_TEXTSIZE);
    
      numKey[SET].drawButton();
      tft.drawRect(TEXT_X, TEXT_Y, TEXT_W, TEXT_H, ILI9341_WHITE);
    }
    


    The above code should be complete enough to run on your own kit, of course after adding the proper tft configuration ETC. Of course, the code just draws the buttons, I didn't bother to include the code that processes them. To be honest, I really not sure what role K_TEXTSIZE plays in the above code using Arial_Bold font. I have not really experimented much beyond trying different values that finally worked. As far as the T3N code goes, I would have put more effort in getting it working right had I known about it prior to the project, but I was so far along with my projects UI at this point with the generic T3 code that it just didn't make sense to go off on a tangent for something as simple as getting the DEL key to update the display correctly.

    Now with all of that having been said, this doesn't mean that once my project is fully up and running on the Teensy 3.2 (I've still got the HW changes to do), I'd be more than happy to get the T3N code working on it. But like I said, I want to get the projects UI completely finished, then do the HW so I can start designing the new PCB.


    So I hope my reasons for saying what I did and why make more sense now.

    Cheers,
    KG5NII

  9. #9
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    5,731
    Thanks @KG5NII - understand.

    Compatibility is an interesting thing.

    Yes - we did play around with the buttons, as to make them to be compatible with the more current Adafruit GFX code, which originally the ili9341_t3 code was compatible... And now that GFX allows the user to specify a different text size value for X and Y, which way do you go?

    We now allow the ILI9341_t3n library to compile if the GFX library is included and we ran into issues. One of the reasons I did that was with working with @mjs513 and others to allow this, as we we have been playing around with the st7735/89_t3 library to make it more compatible with the ILI9341_t3(t3n) library and up till now they were using the Adafruit code for part of it, so trying to make it easier to be able to have code that works with the multiple different displays.

    Again thanks for the input and good luck with your project.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •