New adafruit GFX 1.4.x libs doesn't work for me

Status
Not open for further replies.

gimpo

Well-known member
Hi everybody,

my Teensy 3.2 was working like a charm if using the "old" libs by adafruit with an 1.54" TFT display:

GFX version = 1.3.6
ST77xx version = 1.2.7

(See my simple test sketch below.)

Today, I've decided to update to latest version by using the Tool > Manage libraries command of the Arduino IDE.
Was a bad idea, all my sketches doesn't work anymore and the display stays black. No life signal... :(

If I revert back (to the 1.3.6 for the GFX lib only), then all works fine again. So the problem is not in the ST77xx libs.
To summarize:

GFXST77xxWorks?
1.3.61.2.8yes
1.4.01.2.8no
1.4.11.2.8no
1.4.21.2.8no

Maybe something has changed in the display initialization? The pins are arranged differently?
I checked the source code of the libs, but I cannot find any significant difference...

What I'm missing?
Any idea?
:confused:


----------------------------------------------------------------
Here below my test code.
It simply initialize the display and then:

1. draws a rectangle and some text at two corners to show the max width and height of the screen,
2. pause a little,
3. loops forever in drawing some colored squares along the diagonals of the screen.

Code:
#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_ST7789.h> // Hardware-specific library
#include <Adafruit_ST77xx.h> // just for colo defs
#include <SPI.h>

#define TFT_RST    2   // chip reset
#define TFT_DC     3   // tells the display if you're sending data (D) or commands (C)   --> A0 or WR pin on TFT
#define TFT_MOSI   11  // Data out    (SPI standard)
#define TFT_SCLK   13  // Clock out   (SPI standard)
#define TFT_CS     15  // chip select (SPI standard)
int x, y;
bool toogle;

Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);

void setup(void) {
  pinMode(23, OUTPUT);
  pinMode(22, OUTPUT);
  pinMode(21, OUTPUT);
  digitalWrite(23, HIGH);
  digitalWrite(22, HIGH);
  digitalWrite(21, LOW);

  tft.init(240, 240);
  tft.setRotation(2); 
  tft.fillScreen(ST77XX_BLACK);

  // up left
  tft.fillRect(0, 0, 10, 10, ST77XX_BLUE);
  tft.setCursor(12, 12);
  tft.println("UP-LEFT");
  delay(500);

  // bottom right
  tft.fillRect(tft.width() - 10, tft.height() - 10, 10, 10, ST77XX_RED);
  tft.setCursor(tft.width() - 82, tft.height() - 20);
  tft.println("BOTTOM-RIGHT");
  delay(500);

  // area frame
  tft.drawRect(0, 0, tft.width(), tft.height(), ST77XX_GREEN);
  delay(3000);
}

void loop()
{
  tft.fillScreen(ST77XX_BLACK);
  x = 0;
  y = 0;
  toogle = true;
  for (int i = 0; i < 20; i++)
  {
    tft.fillRect(x, y, 50, 50, toogle ? ST77XX_BLUE : ST77XX_YELLOW);
    tft.fillRect(190 - x, y, 50, 50, toogle ? ST77XX_RED : ST77XX_ORANGE);
    x += 10;
    y += 10;
    toogle = toogle == true ? false : true;
  }
  delay(1000);
}
 
Last edited:
Here the datasheet.
 

Attachments

  • 1.54-Shenzhen-high-quality-np.pdf
    317.6 KB · Views: 198
The sketch "graphictest.ino" doesn't work properly:

1. the black background color is turned to white
2. the screen is translated down for around 3/4 of the screen height, and translated left for around 1/4 of the screen width

I'm using the lib versions working with my own sketch:
GFX version = 1.3.6
ST77xx version = 1.2.8

Hold a moment, I will try a different example...
 
Same result as above with "speedtest.ino".

I have also upgraded to GFX lib versione 1.4.7 (yes, another recent upgrade) and restarted the IDE. Again the same problem as above.
All I see of working area of the program is just a small rectangle in the lower-left corner of the screen.
:(
 
@Paul - Wondering at times if Teensyduino should pick up the more recent versions of the Adafruit_GFX, and related libraries? And/or somehow check to see if the user has later versions installed.

I did notice that there is a lot of changes in the Adafruit_gfx library between the 1.3.6 and the current stuff. They moved a lot of stuff into Adafruit_spitft (.h .cpp) files and I know that they have changed several libraries to make use of these changes.

Looked like the 1.2.7 version of the ST7735 had an init bug fixed... That looked like they turned on/off CS pin. Wonder if too fast on Teensy?
 
My test sketch (the one at the top of this thread) doesn't work even with with the latest 1.4.7 adafruit GFX version.
As before, I had to downgrade the lib back to version 1.3.6 to make it working again.
 
As many TFT, mine also keep in graphic memory the contents of the previous running program.
When the sketch started again correctly, I saw the previous contents of the screen for a fraction of second. They was exactly what I would expect if the screen would not go to black.
Seems like the program is executed correctly with the new GFX 1.4.x libs, but the result is (somehow) not shown on the screen.
 
Nice!
Keep us informed.

If you want, I could send you a cheap 1.54" 240x240 TFT with all the wiring ready to plug and test.
 
I'm testing the latest GFX now, with plans to include it in the next 1.46 beta.

I also picked up the Adafruit ST7789 display. Going to wire it up to a Teensy soon. No plans to buy or test the bare display from Aliexpress vendors.

Great! Any thoughts or plans to separate the Teensy bits to separate files so we can avoid the issue in the future? Ideally the latest Adafruit version would be included in the release and some way to get the versions with the Teensy speedups under a different name.
 
I tested Adafruit's 1.54 inch ST7789 display. It works fine with Teensy 3.2, when used with the latest Adafruit libs.

For this test, I deleted the old copies of Adafruit_GFX and Adafruit_ST7735 which Teensyduino installs into Arduino's hardware/teensy/avr/libraries folder. Then I copied the latest versions of those 2 libs from Adafruit's github repositories.

I ran the graphicstest example. I had to edit 2 lines, to use the Adafruit_ST7789 constructor, and the tft.init() for the 240 pixel display. Here's a complete copy of the exact code I ran.

Code:
/***************************************************
  This is a library for the Adafruit 1.8" SPI display.

This library works with the Adafruit 1.8" TFT Breakout w/SD card
  ----> http://www.adafruit.com/products/358
The 1.8" TFT shield
  ----> https://www.adafruit.com/product/802
The 1.44" TFT breakout
  ----> https://www.adafruit.com/product/2088
as well as Adafruit raw 1.8" TFT display
  ----> http://www.adafruit.com/products/618

  Check out the links above for our tutorials and wiring diagrams
  These displays use SPI to communicate, 4 or 5 pins are required to
  interface (RST is optional)
  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.
  MIT license, all text above must be included in any redistribution
 ****************************************************/

#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library for ST7735
#include <Adafruit_ST7789.h> // Hardware-specific library for ST7789
#include <SPI.h>


// For the breakout, you can use any 2 or 3 pins
// These pins will also work for the 1.8" TFT shield
#define TFT_CS     10
#define TFT_RST    9  // you can also connect this to the Arduino reset
                       // in which case, set this #define pin to -1!
#define TFT_DC     8

// Option 1 (recommended): must use the hardware SPI pins
// (for UNO thats sclk = 13 and sid = 11) and pin 10 must be
// an output. This is much faster - also required if you want
// to use the microSD card (see the image drawing example)

// For 1.44" and 1.8" TFT with ST7735 use
//Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS,  TFT_DC, TFT_RST);

// For 1.54" TFT with ST7789
Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS,  TFT_DC, TFT_RST);

// Option 2: use any pins but a little slower!
//#define TFT_SCLK 13   // set these to be whatever pins you like!
//#define TFT_MOSI 11   // set these to be whatever pins you like!
//Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);


float p = 3.1415926;

void setup(void) {
  Serial.begin(9600);
  Serial.print("Hello! ST77xx TFT Test");

  // Use this initializer if you're using a 1.8" TFT
  //tft.initR(INITR_BLACKTAB);   // initialize a ST7735S chip, black tab

  // Use this initializer (uncomment) if you're using a 1.44" TFT
  //tft.initR(INITR_144GREENTAB);   // initialize a ST7735S chip, black tab

  // Use this initializer (uncomment) if you're using a 0.96" 180x60 TFT
  //tft.initR(INITR_MINI160x80);   // initialize a ST7735S chip, mini display

  // Use this initializer (uncomment) if you're using a 1.54" 240x240 TFT
  tft.init(240, 240);   // initialize a ST7789 chip, 240x240 pixels

  Serial.println("Initialized");

  uint16_t time = millis();
  tft.fillScreen(ST77XX_BLACK);
  time = millis() - time;

  Serial.println(time, DEC);
  delay(500);

  // large block of text
  tft.fillScreen(ST77XX_BLACK);
  testdrawtext("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur adipiscing ante sed nibh tincidunt feugiat. Maecenas enim massa, fringilla sed malesuada et, malesuada sit amet turpis. Sed porttitor neque ut ante pretium vitae malesuada nunc bibendum. Nullam aliquet ultrices massa eu hendrerit. Ut sed nisi lorem. In vestibulum purus a tortor imperdiet posuere. ", ST77XX_WHITE);
  delay(1000);

  // tft print function!
  tftPrintTest();
  delay(4000);

  // a single pixel
  tft.drawPixel(tft.width()/2, tft.height()/2, ST77XX_GREEN);
  delay(500);

  // line draw test
  testlines(ST77XX_YELLOW);
  delay(500);

  // optimized lines
  testfastlines(ST77XX_RED, ST77XX_BLUE);
  delay(500);

  testdrawrects(ST77XX_GREEN);
  delay(500);

  testfillrects(ST77XX_YELLOW, ST77XX_MAGENTA);
  delay(500);

  tft.fillScreen(ST77XX_BLACK);
  testfillcircles(10, ST77XX_BLUE);
  testdrawcircles(10, ST77XX_WHITE);
  delay(500);

  testroundrects();
  delay(500);

  testtriangles();
  delay(500);

  mediabuttons();
  delay(500);

  Serial.println("done");
  delay(1000);
}

void loop() {
  tft.invertDisplay(true);
  delay(500);
  tft.invertDisplay(false);
  delay(500);
}
void testlines(uint16_t color) {
  tft.fillScreen(ST77XX_BLACK);
  for (int16_t x=0; x < tft.width(); x+=6) {
    tft.drawLine(0, 0, x, tft.height()-1, color);
    delay(0);
  }
  for (int16_t y=0; y < tft.height(); y+=6) {
    tft.drawLine(0, 0, tft.width()-1, y, color);
    delay(0);
  }

  tft.fillScreen(ST77XX_BLACK);
  for (int16_t x=0; x < tft.width(); x+=6) {
    tft.drawLine(tft.width()-1, 0, x, tft.height()-1, color);
    delay(0);
  }
  for (int16_t y=0; y < tft.height(); y+=6) {
    tft.drawLine(tft.width()-1, 0, 0, y, color);
    delay(0);
  }

  tft.fillScreen(ST77XX_BLACK);
  for (int16_t x=0; x < tft.width(); x+=6) {
    tft.drawLine(0, tft.height()-1, x, 0, color);
    delay(0);
  }
  for (int16_t y=0; y < tft.height(); y+=6) {
    tft.drawLine(0, tft.height()-1, tft.width()-1, y, color);
    delay(0);
  }

  tft.fillScreen(ST77XX_BLACK);
  for (int16_t x=0; x < tft.width(); x+=6) {
    tft.drawLine(tft.width()-1, tft.height()-1, x, 0, color);
    delay(0);
  }
  for (int16_t y=0; y < tft.height(); y+=6) {
    tft.drawLine(tft.width()-1, tft.height()-1, 0, y, color);
    delay(0);
  }
}

void testdrawtext(char *text, uint16_t color) {
  tft.setCursor(0, 0);
  tft.setTextColor(color);
  tft.setTextWrap(true);
  tft.print(text);
}

void testfastlines(uint16_t color1, uint16_t color2) {
  tft.fillScreen(ST77XX_BLACK);
  for (int16_t y=0; y < tft.height(); y+=5) {
    tft.drawFastHLine(0, y, tft.width(), color1);
  }
  for (int16_t x=0; x < tft.width(); x+=5) {
    tft.drawFastVLine(x, 0, tft.height(), color2);
  }
}

void testdrawrects(uint16_t color) {
  tft.fillScreen(ST77XX_BLACK);
  for (int16_t x=0; x < tft.width(); x+=6) {
    tft.drawRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color);
  }
}

void testfillrects(uint16_t color1, uint16_t color2) {
  tft.fillScreen(ST77XX_BLACK);
  for (int16_t x=tft.width()-1; x > 6; x-=6) {
    tft.fillRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color1);
    tft.drawRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color2);
  }
}

void testfillcircles(uint8_t radius, uint16_t color) {
  for (int16_t x=radius; x < tft.width(); x+=radius*2) {
    for (int16_t y=radius; y < tft.height(); y+=radius*2) {
      tft.fillCircle(x, y, radius, color);
    }
  }
}

void testdrawcircles(uint8_t radius, uint16_t color) {
  for (int16_t x=0; x < tft.width()+radius; x+=radius*2) {
    for (int16_t y=0; y < tft.height()+radius; y+=radius*2) {
      tft.drawCircle(x, y, radius, color);
    }
  }
}

void testtriangles() {
  tft.fillScreen(ST77XX_BLACK);
  int color = 0xF800;
  int t;
  int w = tft.width()/2;
  int x = tft.height()-1;
  int y = 0;
  int z = tft.width();
  for(t = 0 ; t <= 15; t++) {
    tft.drawTriangle(w, y, y, x, z, x, color);
    x-=4;
    y+=4;
    z-=4;
    color+=100;
  }
}

void testroundrects() {
  tft.fillScreen(ST77XX_BLACK);
  int color = 100;
  int i;
  int t;
  for(t = 0 ; t <= 4; t+=1) {
    int x = 0;
    int y = 0;
    int w = tft.width()-2;
    int h = tft.height()-2;
    for(i = 0 ; i <= 16; i+=1) {
      tft.drawRoundRect(x, y, w, h, 5, color);
      x+=2;
      y+=3;
      w-=4;
      h-=6;
      color+=1100;
    }
    color+=100;
  }
}

void tftPrintTest() {
  tft.setTextWrap(false);
  tft.fillScreen(ST77XX_BLACK);
  tft.setCursor(0, 30);
  tft.setTextColor(ST77XX_RED);
  tft.setTextSize(1);
  tft.println("Hello World!");
  tft.setTextColor(ST77XX_YELLOW);
  tft.setTextSize(2);
  tft.println("Hello World!");
  tft.setTextColor(ST77XX_GREEN);
  tft.setTextSize(3);
  tft.println("Hello World!");
  tft.setTextColor(ST77XX_BLUE);
  tft.setTextSize(4);
  tft.print(1234.567);
  delay(1500);
  tft.setCursor(0, 0);
  tft.fillScreen(ST77XX_BLACK);
  tft.setTextColor(ST77XX_WHITE);
  tft.setTextSize(0);
  tft.println("Hello World!");
  tft.setTextSize(1);
  tft.setTextColor(ST77XX_GREEN);
  tft.print(p, 6);
  tft.println(" Want pi?");
  tft.println(" ");
  tft.print(8675309, HEX); // print 8,675,309 out in HEX!
  tft.println(" Print HEX!");
  tft.println(" ");
  tft.setTextColor(ST77XX_WHITE);
  tft.println("Sketch has been");
  tft.println("running for: ");
  tft.setTextColor(ST77XX_MAGENTA);
  tft.print(millis() / 1000);
  tft.setTextColor(ST77XX_WHITE);
  tft.print(" seconds.");
}

void mediabuttons() {
  // play
  tft.fillScreen(ST77XX_BLACK);
  tft.fillRoundRect(25, 10, 78, 60, 8, ST77XX_WHITE);
  tft.fillTriangle(42, 20, 42, 60, 90, 40, ST77XX_RED);
  delay(500);
  // pause
  tft.fillRoundRect(25, 90, 78, 60, 8, ST77XX_WHITE);
  tft.fillRoundRect(39, 98, 20, 45, 5, ST77XX_GREEN);
  tft.fillRoundRect(69, 98, 20, 45, 5, ST77XX_GREEN);
  delay(500);
  // play color
  tft.fillTriangle(42, 20, 42, 60, 90, 40, ST77XX_BLUE);
  delay(50);
  // pause color
  tft.fillRoundRect(39, 98, 20, 45, 5, ST77XX_RED);
  tft.fillRoundRect(69, 98, 20, 45, 5, ST77XX_RED);
  // play color
  tft.fillTriangle(42, 20, 42, 60, 90, 40, ST77XX_GREEN);
}

As you can see from these photos, it's working perfectly.

DSC_0388_web.jpg

DSC_0391_web.jpg

I connected the wires as Adafruit recommends in their example code, to pins 8-13. Here's a photo of the bottom side, so you can see how I connected the pins.

DSC_0401_web.jpg
 
Any thoughts or plans to separate the Teensy bits to separate files so we can avoid the issue in the future? Ideally the latest Adafruit version would be included in the release and some way to get the versions with the Teensy speedups under a different name.

Yes, looks like we already had ST7735_t3. I'm deleting Adafruit_ST7735, Adafruit_ILI9340 and Adafruit_ILI9341 from the Teensyduino installer. I'm considering deleting Adafruit_RA8875 too, but first need to check whether we have any special fixes that aren't in Adafruit's code yet.

I've updated Adafruit_GFX.

Long-term, hopefully this will make using Adafruit's libs easier - not keeping old copies around. But if the installer no longer has a copy of the library, it doesn't know how to delete that old lib from your Arduino install. So people who's already installed older versions and upgrade will have the old libs in their hardware/teensy/avr/libraries folder. Not idea, but long term as new installs are done, these old copies of Adafruits libs will go away.
 
I think it's confusing the way the pins are labeled on this display. I've been trying to connect this display with Teensy 3.6 but haven't had any luck. I'm sure I am mixing up the pin names (I'm a noob). I've been up since 3am so will try again tomorrow. A good night's sleep can make a huge difference. Thank you, Paul, for doing all the work that you do!
 
I think it's confusing the way the pins are labeled on this display.

Agreed. The 2 letter names on the top side, and the abbreviated names on the bottom near the SD socket confused me too. I had to refer to Adafruit's page a few times while wiring this up.

But in the end, it follows the convention of most of Adafruit's products, where the pins wire up "directly" to Arduino Uno. Since we follow Uno's pinout conventions on Teensy 3.x, the same wiring works on Teensy... the first pin past the power goes to 13 on Teensy, then the next to pine 12, then pin 11, then 10, 9, and 8.
 
Revisitng this topic. Installed 1.46beta10. Deleted Adafruit_GFX and Adafruit_ST7735 from hardware/teensy/avr/libraries folder. Installed the latest Adafruit GFX lib (1.4.8) and S&7735 and ST7789 libraries (1.2.8). Ran Paul's code from #15

Result is a blank screen.
 
Difficult to see from this camera angle, but are the 4 wires to pins 9-12 shifted over by 1 place, so they're actually on pins 8-11 ??

EDIT: oh, I see now that the SO pin has no wire at all. I believe the display should work without that wire, but maybe add it just in case?

Also... and I know this is a longshot... check those 5 wires with an ohm meter. Many people have had troubles where one of those wires was bad. Frank recently had this on the T4 beta test with connecting an audio board. Really frustrating when a wire is bad.
 
Hi Paul - I really appreciate your help

So I tore it down, checked the jumpers for continuity and intermittents, added the SO line. No change - black display

I reinstalled 1.46beta10. Loaded the graphicstest example from the teensy directory, changed the defines of RST to 9 and DC to 8 and ran it. It runs but the offset into the graphics buffer is wrong (or right for the ST7735 but wrong for the ST7789). This is the issue that brought me to this thread. I understand that it is not the right driver but I think it shows the that the wiring and module are OK

IMG_4866.jpg
 
Ughhh - retesting here and I also get the black screen issue. :(

Earlier I tested with version 1.2.4. Looks like something broke starting with version 1.2.6. I'm putting this library back on my list of issues to investigate.

Just to be realistic, I probably won't be able to dig into what went wrong for at least a couple weeks. In the meantime, I recommend using the library manager to uninstall 1.2.8 and install version 1.2.5. I tested just now and 1.2.5 seems to be working fine.

Here's how the buttons render at the end of "graphictest" with 1.2.5.

DSC_0427_web.jpg
 
Status
Not open for further replies.
Back
Top