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

Thread: Teensy 4.0 and ST7789_t3

  1. #1
    Senior Member
    Join Date
    Dec 2015
    Posts
    184

    Teensy 4.0 and ST7789_t3

    Hi all,

    I'm trying my first ST7789 based LCD (320x240) with a Teensy 4.0 and I'm having a bit of trouble getting it to work. This is a generic LCD, nothing fancy. So far I've been unable to get anything to appear on the display, and mostly I'm wondering if I've chosen the correct pins on the Teensy.

    Here's the start of my code:

    Code:
    #include <Adafruit_GFX.h>    // Core graphics library
    #include <ST7789_t3.h> // Hardware-specific library
    #include <ST7735_t3.h> // Hardware-specific library
    
    #include <SPI.h>
    
    // T4.0
    #define TFT_SCLK 13  
    #define TFT_DATA 11  
    #define TFT_CS   10  
    #define TFT_DC    9  
    #define TFT_RST   0  
    
    ST7789_t3 tft = ST7789_t3(TFT_CS, TFT_DC, TFT_DATA, TFT_SCLK, TFT_RST);
    
    void setup() {
      tft.init(240, 320);
    
      tft.setCursor (0, 0);
      tft.print("Hello World!");
      Serial.println("Hello World!");
    
      while(1);
    }
    
    void loop() {
    }
    I don't have a proper scope here but I believe I have verified that there is activity on the lines. Anything glaring that I've just managed to completely mess up?

    Thank you!

  2. #2
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    9,024
    Might help to see pictures and the like. It might help locate if there looks like a wiring issue.

    Yes those pins should work. Do you have pin 0 hooked up to the reset pin of the device?

    Does the display have a Backlight pin? Is it connected to something? Adafruit usually build in either PU or PD resistors on theirs to make it unnecessary to hook up, but many others just leave them floating, so you may need to hook it up to something like 3.3v.

    Also I normally always do a fillScreen with some color after I start as I am not sure of what the initial state is. Something like:
    Code:
    tft.fillScreen(ST77XX_RED);
    Likewise I am not sure exactly what the default text color is, might be black and maybe you are on a black screen,
    So I might add in something like:
    Code:
    tft.setTextColor(ST77XX_BLACK);
    tft.setTextSize(2);
    I am 99% sure it defaults to size 1, which is sort of small, so in example here I set it 2...

    You can obviously choose other colors.

  3. #3
    Senior Member
    Join Date
    Dec 2015
    Posts
    184
    Hi Kurt!

    Thanks for the confirmation that my pin choice was ok. I do have pin 0 connected to the reset pin, I also tried pin 1 just in case. I wasn't sure if there were limitations on the DC and CS combinations like on the Teensy 3.2.

    The display is a super generic on from AliExpress that I tossed on another order: https://www.aliexpress.com/item/4000832671813.html I have a couple of the 2.0" version. Backlight seems to be tied to power always, it isn't exposed on a pin.

    I did have a fillScreen, but I took it out just in case. Going with red is a brilliant idea by the way, obviously the black I was choosing wouldn't show up if it were working.

    That said, it isn't working yet. My wiring is a bit of a mess, I've used grabber leads to attach the Teensy and the LCD. This did work back when I started with ST7735 LCDs, but maybe the ST7789 is more picky. I'll have to come up with a more permanent temporary attachment for testing.

    I'll keep bashing away at this for now, if anything else pops to mind I'd love to know about it!

    Thanks again!

  4. #4
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    9,024
    A quick FYI: Here is my slightly modified version of your code:
    Code:
    #include <Adafruit_GFX.h>    // Core graphics library
    #include <ST7789_t3.h> // Hardware-specific library
    #include <ST7735_t3.h> // Hardware-specific library
    
    #include <SPI.h>
    
    // T4.0
    #define TFT_SCLK 13  
    #define TFT_DATA 11  
    #define TFT_CS   10  
    #define TFT_DC    9  
    #define TFT_RST   28  
    
    ST7789_t3 tft = ST7789_t3(TFT_CS, TFT_DC, TFT_DATA, TFT_SCLK, TFT_RST);
    
    void setup() {
      tft.init(240, 320);
      tft.fillScreen(ST77XX_RED);
      tft.setTextColor(ST77XX_BLACK);
      tft.setTextSize(2);
      tft.setCursor (0, 0);
      tft.print("Hello World!");
      Serial.println("Hello World!");
    
      while(1);
    }
    
    void loop() {
    }
    And here it is showing on Adafruit display:
    Click image for larger version. 

Name:	IMG_0274.jpg 
Views:	59 
Size:	156.0 KB 
ID:	21511

  5. #5
    Senior Member
    Join Date
    Dec 2015
    Posts
    184
    Thanks for trying it out, I appreciate it. I gave your version a try but still no love here. The only modification I made was to the reset pin definition.

    I'm going to rewire everything tomorrow in the hopes that my wires are just too long. I have some dupont jumpers that are about 4" long that I'll try. We shall see...

    Thanks!

  6. #6
    Senior Member
    Join Date
    Dec 2015
    Posts
    184
    Still plugging away at this. Haven't had time to solder up shorter wires, but I will hopefully do that soon. I did jump back a few steps to double check myself. I went back to a Teensy 3.2, and ran it with an existing ST7735 display. That worked as expected. Then I went to an ST7735 that came in the same order as the ST7789 display. Also worked great. I then jumped to the ST7789, and nothing, just as before. This was all using your code above but modified for the particular display being tested (in the definition and initialization sections) and for T3.2 pins:

    Code:
    // T3.2
    #define TFT_SCLK 14  // SCLK can also use pin 14
    #define TFT_DATA 7  // COPI can also use pin 7
    #define TFT_CS   2  // CS & DC can use pins 2, 6, 9, 10, 15, 20, 21, 22, 23
    #define TFT_DC    6  //  but certain pairs must NOT be used: 2+10, 6+9, 20+23, 21+22
    #define TFT_RST   5  // RST can use any pin
    I'll keep going but wondering if these displays are just all bad.

  7. #7
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    9,024
    You say in the above post: #define TFT_SCLK 14 // SCLK can also use pin 14
    Does it work if you use pin 13 instead of 14? Or are you also using Audio board with this?

    And are you wired to pin 14? The code I believe should automatically handle 14 as it is a valid SPI SCK pin, so it should then internally set the SPI buss to use it

    But your code fragment above says T3.2 are you trying it on that or on T4.

    On T3.2 14 is valid, but on T4.x pin 14 is NOT valid for SPI.

  8. #8
    Senior Member
    Join Date
    Dec 2015
    Posts
    184
    Hi Kurt,

    Yep, I moved to a Teensy 3.2 as I knew I had that exact setup working with an ST7735.

    So interestingly, I grabbed another LCD randomly from the pile, and this one worked. I'm working to characterize what's going on now, you're very quick on the draw! As I suspected, this isn't a problem with your code, I think this is a hardware issue. I'll report back once I know more!

  9. #9
    Senior Member
    Join Date
    Dec 2015
    Posts
    184
    Here's the latest!

    It looks like of the 5 modules I have, only 2 are working. When I started I must have grabbed a bad one, then when I grabbed another to double check, it was also bad. Luckily the 3rd I grabbed was good.

    I have run them now on both the T3.2 and T4.0 and both work using the same jumper wires I had before.

    I'm debating popping the LCD off its physical mount so I can see if it's just a bad soldering job from the flex PCB to the module's PCB.

  10. #10
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    9,024
    I am glad some of them are working.

    Another thing you might try out of curiosity is to change the SPI speed to lower and see if one of the others works or not.
    Look in the file ST7735_t3.h at about line 45 for clock speed.
    I think it is defaulting to 24mhz (or what the teensy chooses that does exceed this).
    there is a line commented out below it at 16mhz. Try uncommenting that one and commenting the previous one and see if some of the others work or not.

  11. #11
    Senior Member
    Join Date
    Dec 2015
    Posts
    184
    Great thought! I gave it a try but no dice. I couldn't get the actual LCD off the board, so I started closely inspecting the module. There appear to be 5 diodes (D1-5, you can see them in this photo: https://ae01.alicdn.com/kf/Hc21a745b...667adf517o.jpg ). On the three that don't work they appear to be different. They definitely don't meter the same as the ones that do work. It's a bit weird, none of the other modules in that listing have those diodes.

    I'll contact the seller. If I ever get the time I might try taking them out and replacing them perhaps.

  12. #12
    Senior Member
    Join Date
    Dec 2015
    Posts
    184
    Just an update. I left one of the working displays for a couple days, and when I powered up my test setup today, it didn't work. I swapped to my other working display and...nothing again. I'm reasonably sure this might just be my test setup, but I don't really have a lot of trust for these displays either.

    I've found there seem to be a lot of 2.4" ILI9341 displays, I'm going to order one domestically and see if it's a bit more reliable before ordering more on my next China order.

  13. #13
    Senior Member
    Join Date
    Dec 2015
    Posts
    184
    Semi-related question - Kurt, am I able to use a different pin for D/C (other than pin 9)? I might need that for I2S audio...

    Thank you!

  14. #14
    Senior Member
    Join Date
    Dec 2015
    Posts
    184
    I'm running out of pins...

    Yes I could go to the Teensy 4.1, or I could use the backside pins on the T4.0, but I'd like to try solving this another way. So, some questions...

    On the ST7735 examples for the Teensy 3.2, it is clear that if I define things correctly I can end up with software only SPI (at a speed cost). Does this apply to the Teensy 4.0 as well? What about the ILI9341 libraries?

    If I choose to go software SPI, is there any advantage to sticking to the standard Data In and Data Out pins? My guess is no since at that point I don't think we'd be engaging the actual hardware peripheral, so they're all just generic GPIO. If this is correct I could shuffle some things around for easier board design.

    If I stick with hardware SPI, I am guessing I can't use Data In as a free pin once the peripheral has initialized, correct? I don't need it for the LCD, but I assume the peripheral holds control of it.

    Thank you!

Posting Permissions

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