Bodmer / TFT_eSPI

Arduino and PlatformIO IDE compatible TFT library optimised for the Raspberry Pi Pico (RP2040), STM32, ESP8266 and ESP32 that supports different driver chips
Other
3.76k stars 1.08k forks source link

TTOG - T ESP32 Rotate Display #422

Closed medpixman closed 5 years ago

medpixman commented 5 years ago

This is a fantastic and comprehensive library! Thank-you so very much for all of your hard work!

Is there a command wiki? For example, how do I rotate the text display from Portrait to Landscape? Using this tft.setRotation(1)? What values are accepted?

I'm using LILYGO® TTGO T-Display ESP32 CP2104 WiFi bluetooth Module 1.14 Inch LCD Development Board For Arduino from Banggood:

ESPRESSIF-ESP32 240MHz Xtensa® dual-core 32-bit LX6 microprocessor IPS ST7789V 1.14 Inch

--

Thanks

Bodmer commented 5 years ago

Have a look at this tutorial. The Adafruit_GFX library has the same basic functions.

A command summary is on my TO DO list. I hope to find time to write a guide in October when I have some free time.

medpixman commented 5 years ago

Thank-you SO MUCH for responding, and so quickly too!

I really appreciated it!

On Wed, Sep 4, 2019 at 9:59 AM Bodmer notifications@github.com wrote:

Have a look at this tutorial https://learn.adafruit.com/adafruit-gfx-graphics-library/rotating-the-display . The Adafruit_GFX library has the same basic functions.

A command summary is on my TO DO list. I hope to find time to write a guide in October when I have some free time.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Bodmer/TFT_eSPI/issues/422?email_source=notifications&email_token=AAX33BXJMXM5JBMKVF2ZJS3QH65M3A5CNFSM4ITMBVYKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD53VD7Y#issuecomment-527913471, or mute the thread https://github.com/notifications/unsubscribe-auth/AAX33BQO475XIORDUIWSC2DQH65M3ANCNFSM4ITMBVYA .

--

James G. Smirniotopoulos, MD Chief Editor, MedPix®

Special Volunteer, National Library of Medicine, NIHWebsite: https://medpix.nlm.nih.gov/home https://medpix.nlm.nih.gov/homeFormer Professor and Chair of Radiology (retired)Uniformed Services University of the Health Sciences

Google Voice 530 MEDPIX1 (530) 633-7491 [No Solicitations] YouTube Channel - http://www.youtube.com/user/TheMedpixman http://www.youtube.com/user/TheMedpixman

"Science and the pursuit of knowledge have no country, no religion, and no political affiliation" - Richard Feynman

*"Living Rich in Spirit, with Family and Friends, is more important than any material wealth." - *Δημήτριος Σμυρνιωτοπουλος

"Success is not measured by who gets credit. ... Success is measured by what gets done."

"Do not plan to Destroy, What you are not also able to Create" - Pierre LaFontaine

"If you never venture beyond what you know ... You've spawned your own limitations."

- Sumner Redstone

“A man travels the world in search of what he needs and returns home to find it.”

"All science is either physics or stamp collecting." - Ernest Rutherford 1871–1937

"Curiosity, the overwhelming desire to know, is not characteristic of dead matter." - Isaac Asimov 1920-1992

KianYeo commented 5 years ago

Hi medpixman,

I noticed that I have the similar setup as you. I am using the ESP32 with a ST7789V (1.54"). However I am not getting the library to work. There is nothing displaying on the screen.

May I ask if you are using hardware SPI (MOSI - GPIO23 and SCLK - GPIO18) or you can assign any pins for your SPI? Also, how are you connecting your DC, CS and RST pin?

Thanks in advance!

This is a fantastic and comprehensive library! Thank-you so very much for all of your hard work!

Is there a command wiki? For example, how do I rotate the text display from Portrait to Landscape? Using this tft.setRotation(1)? What values are accepted?

I'm using LILYGO® TTGO T-Display ESP32 CP2104 WiFi bluetooth Module 2" (240 x320) Inch LCD Development Board For Arduino from Banggood:

ESPRESSIF-ESP32 240MHz Xtensa® dual-core 32-bit LX6 microprocessor IPS ST7789V 1.14 Inch

--

Thanks

medpixman commented 5 years ago

I'm using this ESP32 240MHz Xtensa® dual-core 32-bit LX6 microprocessor with IPS ST7789V 1.14 Inch from BangGood: https://www.banggood.com/LILYGO-TTGO-T-Display-ESP32-CP2104-WiFi-bluetooth-Module-1_14-Inch-LCD-Development-Board-For-Arduino-p-1522925.html?rmmds=myorder&cur_warehouse=USA

Here the pinout from their website: [image: image.png] I'm using this sketch:

/*

This is a fantastic and comprehensive library! Thank-you so very much for all of your hard work!

Is there a command wiki? For example, how do I rotate the text display from Portrait to Landscape? Using this tft.setRotation(1)? What values are accepted?

I'm using LILYGO® TTGO T-Display ESP32 CP2104 WiFi bluetooth Module 1.14 Inch LCD Development Board For Arduino from Banggood:

ESPRESSIF-ESP32 240MHz Xtensa® dual-core 32-bit LX6 microprocessor IPS ST7789V 1.14 Inch

*/

include

include

include "WiFi.h"

include

include

include "esp_adc_cal.h"

include "bmp.h"

ifndef TFT_DISPOFF

define TFT_DISPOFF 0x28

endif

ifndef TFT_SLPIN

define TFT_SLPIN 0x10

endif

define TFT_MOSI 19

define TFT_SCLK 18

define TFT_CS 5

define TFT_DC 16

define TFT_RST 23

define TFT_BL 4 // Display backlight control pin

define ADC_EN 14

define ADC_PIN 34

define BUTTON_1 35

define BUTTON_2 0

TFT_eSPI tft = TFT_eSPI(135, 240); // Invoke custom library Button2 btn1(BUTTON_1); Button2 btn2(BUTTON_2);

char buff[512]; int vref = 1100; int btnCick = false;

//! Long time delay, it is recommended to use shallow sleep, which can effectively reduce the current consumption void espDelay(int ms) { esp_sleep_enable_timer_wakeup(ms * 1000); esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON); esp_light_sleep_start(); }

void showVoltage() { static uint64_t timeStamp = 0; if (millis() - timeStamp > 1000) { timeStamp = millis(); uint16_t v = analogRead(ADC_PIN); float battery_voltage = ((float)v / 4095.0) 2.0 3.3 * (vref / 1000.0); String voltage = "Voltage:" + String(battery_voltage) + "V";// Concatenate Text Serial.println(voltage); tft.fillScreen(TFT_BLACK); tft.setTextDatum(MC_DATUM); tft.drawString(voltage, tft.width() / 2, tft.height() / 2 ); } }

void button_init() { btn1.setLongClickHandler([](Button2 & b) { btnCick = false; int r = digitalRead(TFT_BL); tft.fillScreen(TFT_BLACK); tft.setTextColor(TFT_GREEN, TFT_BLACK); tft.setTextDatum(MC_DATUM); tft.drawString("Press again to wake up", tft.width() / 2, tft.height() / 2 ); espDelay(6000); digitalWrite(TFT_BL, !r);

tft.writecommand(TFT_DISPOFF);
tft.writecommand(TFT_SLPIN);
esp_sleep_enable_ext1_wakeup(GPIO_SEL_35, ESP_EXT1_WAKEUP_ALL_LOW);
esp_deep_sleep_start();

}); btn1.setPressedHandler([](Button2 & b) { Serial.println("Detect Voltage.."); btnCick = true; });

btn2.setPressedHandler([](Button2 & b) { btnCick = false; Serial.println("btn press wifi scan"); wifi_scan(); }); }

void button_loop() { btn1.loop(); btn2.loop(); }

void wifi_scan() { tft.setTextColor(TFT_GREEN, TFT_BLACK);// Green Text on Black Background tft.fillScreen(TFT_BLACK); // Clear Screen tft.setTextDatum(MC_DATUM); tft.setRotation(1); tft.setTextSize(2);

tft.drawString("Scanning Network", tft.width() / 2, tft.height() / 2);// Center Text delay (500);

WiFi.mode(WIFI_STA); WiFi.disconnect(); delay(100);

int16_t n = WiFi.scanNetworks(); tft.fillScreen(TFT_BLACK); if (n == 0) { tft.drawString("No Networks Found", tft.width() / 2, tft.height() / 2);// CENTER TEXT } else { String networks = String(n) + " - Networks Found";// Concatenate Text tft.drawString(networks, tft.width() / 2, tft.height() / 2);// CENTER TEXT delay(1000); tft.fillScreen(TFT_BLACK);// Clear Screen

tft.setTextSize(2);
tft.setTextDatum(TL_DATUM);
tft.setCursor(0, 0);

for (int i = 0; i < n; ++i) {

  sprintf(buff,
          "[%d]:%s(%d)",
          i + 1,
          WiFi.SSID(i).c_str(),
          WiFi.RSSI(i)
         );
  tft.println(buff);

  tft.print("CHAN:");
  tft.print(WiFi.channel(i));
  tft.print("(");
  String encryptionTypeDescription =

translateEncryptionType(WiFi.encryptionType(i)); tft.print(encryptionTypeDescription); tft.println(")");

  //      Serial.printf("[".WiFi.channel(i))."]";
  delay(10);
}

} WiFi.mode(WIFI_OFF); }

String translateEncryptionType(wifi_auth_mode_t encryptionType) { switch (encryptionType) { case (0): return "Open"; case (1): return "WEP"; case (2): return "WPA_PSK"; case (3): return "WPA2_PSK"; case (4): return "WPA_WPA2_PSK"; case (5): return "WPA2_ENTERPRISE"; } }

void setup() { Serial.begin(115200); Serial.println("Start"); tft.init(); tft.setRotation(1); tft.fillScreen(TFT_BLACK); tft.setTextSize(2); tft.setTextColor(TFT_WHITE); tft.setCursor(0, 0); tft.setTextDatum(MC_DATUM); tft.setTextSize(1);

//! The backlight has been initialized in the TFT_eSPI library // if (TFT_BL > 0) { // pinMode(TFT_BL, OUTPUT); // digitalWrite(TFT_BL, HIGH); // }

tft.setSwapBytes(true); tft.pushImage(0, 0, 240, 135, ttgo); espDelay(5000);

tft.setRotation(0); int i = 5; while (i--) { tft.fillScreen(TFT_RED); espDelay(500); tft.fillScreen(TFT_BLUE); espDelay(500); tft.fillScreen(TFT_GREEN); espDelay(500); }

button_init();

esp_adc_cal_characteristics_t adc_chars; esp_adc_cal_value_t val_type = esp_adc_cal_characterize((adc_unit_t)ADC_UNIT_1, (adc_atten_t)ADC1_CHANNEL_6, (adc_bits_width_t)ADC_WIDTH_BIT_12, 1100, &adc_chars); //Check type of calibration value used to characterize ADC if (val_type == ESP_ADC_CAL_VAL_EFUSE_VREF) { Serial.printf("eFuse Vref:%u mV", adc_chars.vref); vref = adc_chars.vref; } else if (val_type == ESP_ADC_CAL_VAL_EFUSE_TP) { Serial.printf("Two Point --> coeff_a:%umV coeff_b:%umV\n", adc_chars.coeff_a, adc_chars.coeff_b); } else { Serial.println("Default Vref: 1100mV"); } }

void loop() { if (btnCick) { showVoltage(); } button_loop(); }

I got more information from these links: https :// github.com/Xinyuan-LilyGO/TTGO-T-Display/blob/master/schematic/ESP32-TFT(6-26).pdf

github.com/Xinyuan-LilyGO/TTGO-T-Display github.com/Bodmer/TFT_eSPI

I hope this helps

On Sat, Sep 7, 2019 at 9:59 PM KianYeo notifications@github.com wrote:

Hi medpixman,

I noticed that I have the similar setup as you. I am using the ESP32 with a ST7789V (1.54"). However I am not getting the library to work. There is nothing displaying on the screen.

May I ask if you are using hardware SPI (MOSI - GPIO23 and SCLK - GPIO18) or you can assign any pins for your SPI? Also, how are you connecting your DC, CS and RST pin?

Thanks in advance!

This is a fantastic and comprehensive library! Thank-you so very much for all of your hard work!

Is there a command wiki? For example, how do I rotate the text display from Portrait to Landscape? Using this tft.setRotation(1)? What values are accepted?

I'm using LILYGO® TTGO T-Display ESP32 CP2104 WiFi bluetooth Module 1.14 Inch LCD Development Board For Arduino from Banggood:

ESPRESSIF-ESP32 240MHz Xtensa® dual-core 32-bit LX6 microprocessor IPS ST7789V 1.14 Inch

--

Thanks

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Bodmer/TFT_eSPI/issues/422?email_source=notifications&email_token=AAX33BSLO34ETN2O4XLWLS3QIRMBVA5CNFSM4ITMBVYKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6FF5HA#issuecomment-529161884, or mute the thread https://github.com/notifications/unsubscribe-auth/AAX33BSBQD456M5NBZ3PKBLQIRMBVANCNFSM4ITMBVYA .

--

James G. Smirniotopoulos, MD Chief Editor, MedPix®

Special Volunteer, National Library of Medicine, NIHWebsite: https://medpix.nlm.nih.gov/home https://medpix.nlm.nih.gov/homeFormer Professor and Chair of Radiology (retired)Uniformed Services University of the Health Sciences

Google Voice 530 MEDPIX1 (530) 633-7491 [No Solicitations] YouTube Channel - http://www.youtube.com/user/TheMedpixman http://www.youtube.com/user/TheMedpixman

"Science and the pursuit of knowledge have no country, no religion, and no political affiliation" - Richard Feynman

*"Living Rich in Spirit, with Family and Friends, is more important than any material wealth." - *Δημήτριος Σμυρνιωτοπουλος

"Success is not measured by who gets credit. ... Success is measured by what gets done."

"Do not plan to Destroy, What you are not also able to Create" - Pierre LaFontaine

"If you never venture beyond what you know ... You've spawned your own limitations."

- Sumner Redstone

“A man travels the world in search of what he needs and returns home to find it.”

"All science is either physics or stamp collecting." - Ernest Rutherford 1871–1937

"Curiosity, the overwhelming desire to know, is not characteristic of dead matter." - Isaac Asimov 1920-1992

KianYeo commented 5 years ago

Thanks @medpixman . It was really helpful!