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

Thread: ILI9341_t3n and 2x Screens on SPI1 - Flashing

  1. #1

    ILI9341_t3n and 2x Screens on SPI1 - Flashing

    Hey Everyone,

    I have 2x ili9341 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 can't see how to do it.

    Below is my code and as for wiring, I have 2x pullups on the CS pins.

    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();
    }

  2. #2
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    8,889
    Sorry I am not sure how this works? Are there any compiler warnings? Do you have the compiler set to show all errors?

    What I don't understand is:
    Code:
    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)
    That is you are passing an ILI9341_t3n object into the function, not a reference to an existing object nor a pointer... Would understand if maybe it was:
    Code:
    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)
    or:
    Code:
    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)
    Where then you would call it with:
    Code:
    DrawIndicator(&tft_Track,30, 30,75,3,ILI9341_GREEN,"SOLO",true);
    Again I don't know if that is the issue or not.

  3. #3
    Sorry, No they aren't causing any issues.
    It's when I update both screens in the loop it caused the fast flickering.

    Code:
     tft_Track.updateScreen();
     tft_Func.updateScreen();
    This happens with or without any other elements displayed. Is this due to me using 2 screens on the one SPI1 buss?

  4. #4
    Oh and no compiler warnings or errors

  5. #5
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    8,889
    It should not matter at all in this case if they are on the same buss or not..
    As the CS pins should only effect one display at a time. It would be a different answer if you were doing something like updateScreenAsync as that would simply start up DMA and the SPI buss can only be doing one SPI operation at a time. But UpdateScreen is simply starting an SPI transaction, setting the rectangle to full screen and writing all of the pixels to the screen and waiting for that complete.

    Again have no idea on why that should cause flicker.

    However some thoughts:
    a) How are these displays powered? Are they both powered off of the 3.3v of the Teensy? Maybe overloading it and so causing backlight to change?

    b) What Teensy? I assuming a 4.x? As there is not enough memory on any other teensy to support two frame buffers.

  6. #6
    Quote Originally Posted by KurtE View Post
    It should not matter at all in this case if they are on the same buss or not..
    As the CS pins should only effect one display at a time. It would be a different answer if you were doing something like updateScreenAsync as that would simply start up DMA and the SPI buss can only be doing one SPI operation at a time. But UpdateScreen is simply starting an SPI transaction, setting the rectangle to full screen and writing all of the pixels to the screen and waiting for that complete.

    Again have no idea on why that should cause flicker.

    However some thoughts:
    a) How are these displays powered? Are they both powered off of the 3.3v of the Teensy? Maybe overloading it and so causing backlight to change?

    b) What Teensy? I assuming a 4.x? As there is not enough memory on any other teensy to support two frame buffers.
    Thanks Kurt.

    Both are powered by 3.3v on a seperate power supply and the mcu is a 4.1, which has plenty of resources remaining. Does the SPI speed default to Max or is this something that can be changed further?

  7. #7
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    8,889
    What are the backlights hooked up to? SPI speed defaults to: somewhere in the order of 30mhz...

    The defaults can be changed by passing in a desired SPI Speed on the begin method... Actually optionally 2 parameters (the main write speed and secondary read speed)

  8. #8
    Both backlights are connected directly to the external 3.3v. Maybe increasing the spi speed might pay dividends?

  9. #9
    Another thought is I am using 10k pull ups on the CS lines. Could that value be causing a minor delay in switching between the 2 being updated?

  10. #10
    I've not tried to put both screens on separate SPI Busses.

    I have cleaned up the code to make it easier to read and have them on SPI0 and SPI1. As soon as the second screen is added the flicker goes much much worse than the micro flicker I had before. I made a video on the screens on the 2 separate buss.

    Also, is there any documentation on how to use DMA for this library?

    https://youtu.be/VpV74QGjc5E

    and the code used is
    Code:
    #include <Arduino.h>
    #include <SPI.h>
    #include <ILI9341_t3n.h>
    #include <SPIN.h>
    #include <colours.h>
    #include <prefabs.h>
    #include <Control_Surface.h>
    
    #define TFT1_SCLK 13
    #define TFT1_CS 10
    #define TFT1_DC 9
    #define TFT1_MOSI 11
    #define TFT1_MISO 12
    #define TFT1_RST 8
    #define TFT2_SCLK 27
    #define TFT2_CS 38
    #define TFT2_DC 40
    #define TFT2_MOSI 26
    #define TFT2_MISO 39
    #define TFT2_RST 41
    
    ILI9341_t3n tft_Track = ILI9341_t3n(TFT1_CS,TFT1_DC,TFT1_RST,TFT1_MOSI,TFT1_SCLK,TFT1_MISO);
    ILI9341_t3n tft_Func = ILI9341_t3n(TFT2_CS,TFT2_DC,TFT2_RST,TFT2_MOSI,TFT2_SCLK,TFT2_MISO);
    
    void setup()
    {
      tft_Track.begin();
      tft_Func.begin();
      tft_Track.useFrameBuffer(true);
      tft_Func.useFrameBuffer(true);
      tft_Track.fillScreen(BACKGROUND);
      tft_Func.fillScreen(BACKGROUND);
      tft_Track.updateScreen();
      tft_Func.updateScreen();
    }
    
    void loop()
    {
      tft_Track.fillCircle(100,100,20,VU_RED);
      tft_Func.fillCircle(100,100,20,VU_RED);
      tft_Track.updateScreen();
      tft_Func.updateScreen();
    }

  11. #11
    Member KD0RC's Avatar
    Join Date
    May 2019
    Location
    Colorado, USA
    Posts
    79
    Have you tried increasing the SPI clock speed? I did that with an HX8357 display by passing the SPI clock speed in the begin. tft_Track.begin(30000000) to set it to 30MHz for example. You will need to look at the ILI9341_t3n library to verify that you can set the clock this way. Mine works up to 46 MHz, but not reliably. There are frequencies that work and others that don't. Presumably, it is due to the length of the SPI lines, but I don't know that for sure.
    Len

  12. #12
    Quote Originally Posted by KD0RC View Post
    Have you tried increasing the SPI clock speed? I did that with an HX8357 display by passing the SPI clock speed in the begin. tft_Track.begin(30000000) to set it to 30MHz for example. You will need to look at the ILI9341_t3n library to verify that you can set the clock this way. Mine works up to 46 MHz, but not reliably. There are frequencies that work and others that don't. Presumably, it is due to the length of the SPI lines, but I don't know that for sure.
    Len
    Hey Mate,

    I did but it made the flickering worse. I decided to go back to the original setup on 1 SPI Bus and got it working by allocating memory for each buffer manually.

    Thanks

Posting Permissions

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