Feather ESP32-S2 TFT Demo code

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
adafruitguy
 
Posts: 206
Joined: Sat Jun 07, 2014 7:52 am

Feather ESP32-S2 TFT Demo code

Post by adafruitguy »

The Feather ESP32-S2 TFT ships with a demo running. Is example code available for this demo?
Feather ESP32-S2 TFT out of the box demo
Feather ESP32-S2 TFT out of the box demo
IMG_1613 (2).jpeg (1021.97 KiB) Viewed 301 times

User avatar
legowerewolf
 
Posts: 2
Joined: Wed Jan 19, 2022 5:07 pm

Re: Feather ESP32-S2 TFT Demo code

Post by legowerewolf »

Seconding this. Can't work out how to control the display from CircuitPython.

User avatar
adamhi
 
Posts: 18
Joined: Wed Feb 16, 2011 11:10 pm

Re: Feather ESP32-S2 TFT Demo code

Post by adamhi »

Stumped here as well. I was pretty excited about using this board, but the frustration level is rising.

The display will echo what i'm typing and seeing in the REPL, so i know that it at least works since putting on CircuitPython. I also tried the example code from the related TFT breakout board (Product ID: 4383) to work - no joy. I have updated to CircuitPython 7.2.0 Alpha 1, which supposedly added the support for this board.

I hope something positive and constructive appears here soon.

EDIT: Addendum: Happy Happy Joy Joy

In searching through MORE of the forum, i found post viewtopic.php?f=60&t=187107&p=906439&hi ... er#p906203 .

The solution is there, and summarized here:

Use the example code in the product i mentioned above, and update to CircuitPython 7.2.0 Alpha

Comment out the following lines:

Code: Select all

from adafruit_st7789 import ST7789
. . 
displayio.release_displays()
. . .
spi = board.SPI()
. .
display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs)
display = ST7789(
   display_bus, rotation=270, width=240, height=135, rowstart=40, colstart=53
)
and after the
  • tft_cs = board.D5
    tft_dc = board.D6
add the following line:

Code: Select all

display = board.DISPLAY
--adam

User avatar
legowerewolf
 
Posts: 2
Joined: Wed Jan 19, 2022 5:07 pm

Re: Feather ESP32-S2 TFT Demo code

Post by legowerewolf »

@adamhi thanks!

User avatar
mushburger
 
Posts: 8
Joined: Tue Jan 07, 2014 1:41 pm

Re: Feather ESP32-S2 TFT Demo code

Post by mushburger »

Does anyone have any clues on how to communicate to the TFT display on this board using Arduino code instead of CircuitPython?

User avatar
Brezensalzer
 
Posts: 2
Joined: Thu Feb 03, 2022 2:52 pm

Re: Feather ESP32-S2 TFT Demo code

Post by Brezensalzer »

@mushburger

You could try the TFT_eSPI library, checkout https://github.com/Bodmer/TFT_eSPI
I made a pull request (merged) to get my QtPy ESP32-S2 running with a tft display.
You have to

Code: Select all

#define USE_FSPI_PORT
in User_Setup.h.

User avatar
mushburger
 
Posts: 8
Joined: Tue Jan 07, 2014 1:41 pm

Re: Feather ESP32-S2 TFT Demo code

Post by mushburger »

Thanks @Brezensalzer

I was able to get something working. The critical information I needed ultimately came from the pinout diagram on the Adafruit product write-up... RTFM!!

Below is the code I used to get something working. The secret was to know which pins needed to be set for TFT_CS, TFT_DC, and TFT_RST. Then I just needed to figure out what pins to set high to turn on the I2C and the backlight. Then it was pretty easy to work with.

Code: Select all

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

/*******************   TFT Display   **********************/
#define TFT_CS 7
#define TFT_DC 39
#define TFT_RST 40
#define TFT_I2C_POWER 21
#define TFT_BACKLIGHT 45
Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);

// -----------------------------------------------------------
// -----------------------------------------------------------
// -------------------------PROGRAM---------------------------
// -----------------------------------------------------------
// -----------------------------------------------------------
void setup() 
{
  //**************************
  // Set up the Serial port
  // - Not critical, used for debugging
  //**************************
  Serial.begin(9600);
  for(int x = 0; x < 250; x++){
    if(!Serial){
      delay(10);
      continue;
    }else{
      break;
    }
  }


  //**************************
  // TFT Display
  //************************** 
  pinMode(TFT_I2C_POWER, OUTPUT);
  pinMode(TFT_BACKLIGHT, OUTPUT);
  tft.init(135, 240); // Initialize
  tft.fillScreen(ST77XX_BLACK); // Clear the screen
  tft.setRotation(3);
  digitalWrite(TFT_I2C_POWER, HIGH);
  digitalWrite(TFT_BACKLIGHT, HIGH);
  
  
  // Print some data on the TFT display
  tftPrintTest();
}

void loop()
{

}

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

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(3.1415926, 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.");
}

User avatar
ryan780
 
Posts: 35
Joined: Sat Jul 20, 2019 3:47 pm

Re: Feather ESP32-S2 TFT Demo code

Post by ryan780 »

mushburger wrote:Thanks @Brezensalzer
The secret was to know which pins needed to be set for TFT_CS, TFT_DC, and TFT_RST.
As long as you are using the latest version of the ESP32 library and have selected the ESP32 S2 TFT from the board menu, you don't have to strictly define those pins or the TFT_I2C_POWER or TFT_BACKLITE. They are all defined in the board definition file.

Code: Select all

#define TFT_I2C_POWER  21
#define TFT_CS          7
#define TFT_RST        40
#define TFT_DC         39
#define TFT_BACKLITE   45
You can see it here https://github.com/espressif/arduino-es ... arduino.h.

The one thing your code is missing to get the display to work is the enable command

Code: Select all

tft.enableDisplay (true);
somewhere in the setup. This is the modified version of the ST77XX Graphicstest that I as able to get working with the ESP 32 S2 TFT Feather.

Code: Select all

/**************************************************************************
  This is a library for several Adafruit displays based on ST77* drivers.

  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>


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


float p = 3.1415926;

void setup(void) {
  Serial.begin(115200);
  Serial.print(F("Hello! ST77xx TFT Test"));
  
  pinMode(TFT_I2C_POWER,OUTPUT);
  digitalWrite(TFT_I2C_POWER, HIGH);
  pinMode(TFT_BACKLITE, OUTPUT);
  digitalWrite(TFT_BACKLITE, HIGH);

  tft.init(135, 240);           // Init ST7789 240x135
  tft.setRotation(3);

  Serial.println("Initialized");

  uint16_t time = millis();
  tft.fillScreen(ST77XX_BLACK);
  time = millis() - time;
  tft.enableDisplay(true);
  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);
  uint16_t 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);
  uint16_t 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);
}

User avatar
freddyboomboom
 
Posts: 267
Joined: Wed Feb 16, 2022 7:55 pm

Re: Feather ESP32-S2 TFT Demo code

Post by freddyboomboom »

I don't have one, but I would start at the guide: https://learn.adafruit.com/adafruit-esp ... tft-basics

they have a section on using Arduino, too: https://learn.adafruit.com/adafruit-esp ... ilt-in-tft

User avatar
ryan780
 
Posts: 35
Joined: Sat Jul 20, 2019 3:47 pm

Re: Feather ESP32-S2 TFT Demo code

Post by ryan780 »

But there is no example using the TFT screen. Trust me, I have looked. :-)

User avatar
freddyboomboom
 
Posts: 267
Joined: Wed Feb 16, 2022 7:55 pm

Re: Feather ESP32-S2 TFT Demo code

Post by freddyboomboom »

Well, I linked to the sections titled "TFT Basics" and "Built in TFT".

The code section in the Circuitpython part that displays "Hello World!" on the TFT works on my Funhouse to display on the TFT. So "board.DISPLAY.show" works for me.

Sorry I can't help more.

User avatar
ryan780
 
Posts: 35
Joined: Sat Jul 20, 2019 3:47 pm

Re: Feather ESP32-S2 TFT Demo code

Post by ryan780 »

Again, that's for circuit python. But the example I listed above works. That should answer the question I believe.

Locked
Please be positive and constructive with your questions and comments.

Return to “Feather - Adafruit's lightweight platform”