Greetings everyone
I have an Arduino code made for the TTGO T-Display with ESP32, working perfectly. I made small modifications and it's working on a Display ili9341 2.2 320240, however, as the area of this display is larger, the content shown on the display, logically, doesn't fill the whole area. I've already tried modifying some things like, for example, in tft.setCursor, tft.fillRect, but, there are things that are beyond my little knowledge.
Actually, I would like to use it on an ili9341 2.8 320240 Display, so I ask for your help.
I'm leaving part of the code that I think is enough for those who need it. I also leave the YouTube link for anyone who wants to see it. Link: https://www.youtube.com/watch?v=slYZz61u8RY&t=95s
My early thanks,
Daniel Fernandes
Any kind heart to help me?
Are you using a library for the display?
Post your code on all libraries.
Hi dave-in-nj, first, thanks for the reply.
Sorry, now I have the full code available. I just didn't provide 'Orbitron_Medium_20.h' and 'ani.h' because they are simply fonts.
#include "ani.h"
#include <SPI.h>
#include <TFT_eSPI.h>
#include <ArduinoJson.h>
#include <NTPClient.h>
TFT_eSPI tft = TFT_eSPI();#define TFT_GREY 0x5AEB
#define lightblue 0x01E9
#define darkred 0xA041
#define blue 0x5D9B
#include "Orbitron_Medium_20.h"
#include <WiFi.h>
#include <WiFiUdp.h>
#include <HTTPClient.h>
const int pwmFreq = 5000;
const int pwmResolution = 8;
const int pwmLedChannelTFT = 0;
const char* ssid = "xxxxxxx";
const char* password = "xxxxxxxxxxx";
String town = "xxxxxxx";
String Country = "xx";
const String endpoint = "http://api.openweathermap.org/data/2.5/weather?q=" + town + "," + Country + "&units=metric&APPID=";
const String key = "xxxxx.....";
String payload = "";
String tmp = "" ;
String hum = "" ;
StaticJsonDocument<1000> doc;
// Define o NTP Client para obter o tempo
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP);
// Variáveis para salvar data e hora
String formattedDate;
String dayStamp;
String timeStamp;
int backlight[5] = {10, 30, 60, 120, 220};
byte b = 1;
void setup(void) {
pinMode(0, INPUT_PULLUP);
pinMode(35, INPUT);
tft.init();
tft.setRotation(0); // rotação da tela
tft.fillScreen(TFT_BLACK); // Preenche a tela na cor preta
tft.setTextColor(TFT_WHITE, TFT_BLACK); tft.setTextSize(1);
ledcSetup(pwmLedChannelTFT, pwmFreq, pwmResolution);
//ledcAttachPin(TFT_BL, pwmLedChannelTFT); // TFT_BL é definido na biblioteca TFT_eSPI no arquivo de configuração do usuário TTGO_T_Display.h
ledcWrite(pwmLedChannelTFT, backlight[b]);
Serial.begin(115200);
tft.print("Conectando ");
tft.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(300);
tft.print(".");
}
tft.println("");
tft.println("WiFi conectado.");
tft.println("IP address: ");
tft.println(WiFi.localIP());
delay(3000);
tft.setTextColor(TFT_WHITE, TFT_BLACK); tft.setTextSize(1);
tft.fillScreen(TFT_BLACK);
tft.setSwapBytes(true);
tft.setCursor(2, 232, 1);
tft.println(WiFi.localIP());
tft.setCursor(80, 204, 1);
tft.println("BRILHO:");
tft.setCursor(80, 152, 2);
tft.println("SEG:");
tft.setTextColor(TFT_WHITE, lightblue);
tft.setCursor(4, 152, 2);
tft.println("TEMP:");
tft.setCursor(4, 192, 2);2
tft.println("UMID: ");
tft.setTextColor(TFT_WHITE, TFT_BLACK);
tft.setFreeFont(&Orbitron_Medium_20);
tft.setCursor(6, 82);
tft.println(town);
tft.fillRect(68, 152, 1, 74, TFT_GREY);
for (int i = 0; i < b + 1; i++)
tft.fillRect(78 + (i * 7), 216, 3, 10, blue);
// Inicializa um NTPClient para obter o tempo
timeClient.begin();
// Define o tempo de deslocamento em segundos para ajustar o seu fuso horário, por exemplo:
// GMT +1 = 3600
// GMT +8 = 28800
// GMT -1 = -3600
// GMT 0 = 0
timeClient.setTimeOffset(-10800);
getData();
delay(500);
}
int i = 0;
String tt = "";
int count = 0;
bool inv = 1;
int press1 = 0;
int press2 = 0;
int frame = 0;
String curSeconds = "";
void loop() {
tft.pushImage(0, 88, 135, 65, ani[frame]);
frame++;
if (frame >= 10)
frame = 0;
if (digitalRead(35) == 0) {
if (press2 == 0)
{ press2 = 1;
tft.fillRect(78, 216, 44, 12, TFT_BLACK);
b++;
if (b >= 5)
b = 0;
for (int i = 0; i < b + 1; i++)
tft.fillRect(78 + (i * 7), 216, 3, 10, blue);
ledcWrite(pwmLedChannelTFT, backlight[b]);
}
} else press2 = 0;
if (digitalRead(0) == 0) {
if (press1 == 0)
{ press1 = 1;
inv = !inv;
tft.invertDisplay(inv);
}
} else press1 = 0;
if (count == 0)
getData();
count++;
if (count > 2000)
count = 0;
tft.setFreeFont(&Orbitron_Medium_20);
tft.setCursor(2, 187);
tft.println(tmp.substring(0, 3));
tft.setCursor(2, 227);
tft.println(hum + "%");
tft.setTextColor(TFT_ORANGE, TFT_BLACK);
tft.setTextFont(2);
tft.setCursor(6, 44);
tft.println(dayStamp);
tft.setTextColor(TFT_WHITE, TFT_BLACK);
while (!timeClient.update()) {
timeClient.forceUpdate();
}
// A Data vem com o seguinte formato:
// 2018-05-28T16:00:13Z
// Nós necessitamos extrair data e hora
formattedDate = timeClient.getFormattedDate();
Serial.println(formattedDate);
int splitT = formattedDate.indexOf("T");
dayStamp = formattedDate.substring(0, splitT);
timeStamp = formattedDate.substring(splitT + 1, formattedDate.length() - 1);
if (curSeconds != timeStamp.substring(6, 8)) {
tft.fillRect(78, 170, 48, 28, darkred);
tft.setFreeFont(&Orbitron_Light_24);
tft.setCursor(81, 192);
tft.println(timeStamp.substring(6, 8));
curSeconds = timeStamp.substring(6, 8);
}
tft.setFreeFont(&Orbitron_Light_32);
String current = timeStamp.substring(0, 5);
if (current != tt)
{
tft.fillRect(3, 8, 120, 30, TFT_BLACK);
tft.setCursor(5, 34);
tft.println(timeStamp.substring(0, 5));
tt = timeStamp.substring(0, 5);
}
delay(80);
}
void getData()
{
tft.fillRect(1, 170, 64, 20, TFT_BLACK);
tft.fillRect(1, 210, 64, 20, TFT_BLACK);
if ((WiFi.status() == WL_CONNECTED)) {
HTTPClient http;
http.begin(endpoint + key);
int httpCode = http.GET();
if (httpCode > 0) {
payload = http.getString();
// Serial.println(httpCode);
Serial.println(payload);
}
else {
Serial.println("Error on HTTP request");
}
http.end();
}
char inp[1000];
payload.toCharArray(inp, 1000);
deserializeJson(doc, inp);
String tmp2 = doc["main"]["temp"];
String hum2 = doc["main"]["humidity"];
String town2 = doc["name"];
tmp = tmp2;
hum = hum2;
Serial.println("Temperature" + String(tmp));
Serial.println("Humidity" + hum);
Serial.println(town);
}
Anyone else to help me?
I did not find how to identify your display with this driver.
The github for this library has a discussion page.
Since no one else here has any advise the maybe the library discussion page might be of help.
Are you referring to the display I intend to use with the code modification? If so, it's the 2.8 inch ili9341 SPI Display, which is fully compatible with the TFT_eSPI library. And here, the author is using Display TTGO with the same library (TFT_eSPI). This code works with the ili9341 Display, but because the (intended) display is larger than the display used in the code (TTGO 135240), the characters and image do not occupy the entire display screen (ili9341 240320) ; That's why I want to adapt.
What command do you use to tell the library what size the is?
I didn't understand your question correctly, but the only command in the TFT_eSPI library to determine the screen is in User_Setup > #define ILI9341_DRIVER. And in the sketch, it's in the functions 'tft.setCursor', 'ft.fillRect', 'tft.println'. I don't know if you understand my initial question!
I believe you want to use a specific driver library. On a specific driver chip.
But don't know how to tell the library how to tell the driver chip what resolution you want the chip to use on the display.
I could not find the command in the livrary.
I assume that you think the chip has only one resolution and that you do not need to tell what resolition to use.
Based on the simple fact that no one else has tried to offer suggestions that you have a very specific need.
That is why i suggested that you use the library chat room. To get help from those that wrote the library.
Okay, thanks for your answers; I'll make a few more tries.
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.