I want to add a couple of 18520s to power my T-Display. Where would I connect them to do this?
Any and all comments or suggestions would be greatly appreciated.
WD
I want to add a couple of 18520s to power my T-Display. Where would I connect them to do this?
Any and all comments or suggestions would be greatly appreciated.
WD
@teastain2 I figured it out. With the eSPI library, when you specify text color you have to specify a background color. So by entering the following tft.setTextColor(TFT_GREENYELLOW,TFT_BLACK); the display will display a non blinking text.
@witchdoc Well it looks like I spoke to soon. I converted my thermometer sketch to the tft_espi library and it's doing the same thing that the adafruit library does. Initially it is very clear but within the first second the temperature reading begins to corrupt as does the time display. Not sure why since the test sketch with the espi library was so perfect.
@teastain2 Thanks for the script. I found a solution to the blinking text. I have another display running on another ESP32 and I realized that it wasn't blinking. It is running a GPS program and displaying the time which always looks crisp and clean so I took a look at that script and realized it was using a different display library. TFT_eSPI. Took a bit of tinkering but I got a display that shows the temperature perfectly.```
#include <TFT_eSPI.h> // Hardware-specific library
#include <OneWire.h>
#include <DallasTemperature.h>
TFT_eSPI tft = TFT_eSPI();
// GPIO where the DS18B20 is connected to
const int oneWireBus = 32;
float getTemperature(){
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(oneWireBus);
// Pass our oneWire reference to Dallas Temperature sensor
DallasTemperature sensors(&oneWire);
sensors.begin();
//delay(dT) ;
sensors.requestTemperatures();
float temperatureC = sensors.getTempCByIndex(0);
//float temperatureF = sensors.getTempFByIndex(0);
return(temperatureC);
}
void setup() {
Serial.begin(115200);
//delay(dT) ;
pinMode(TFT_BL, OUTPUT); // TTGO T-Display enable Backlight pin 4
digitalWrite(TFT_BL, HIGH); // T-Display turn on Backlight
tft.init(); // Initialize ST7789 240x135
Serial.println(F("Initialized"));
tft.fillScreen(TFT_BLACK);
}
void loop() {
tft.setRotation(1);
tft.setTextColor(TFT_GREENYELLOW,TFT_BLACK);
tft.setCursor(0, 0);
tft.print("Temperature: ");
tft.setCursor(74, 50);
tft.setTextSize(3);
tft.print(getTemperature());
}
@teastain2 I'd be interested to see how you did it. I've got it running on my T-Display. My multimeter with a thermocouple on it reads 22 degrees. My cheap 3 dollar Chinese thermometer reads 23.4 and my DS18B20 is reading 23.87. At the moment the temperature is flashing on and off as the loop, loops. And I've yet to deal with the time display getting corrupted.
@teastain2 Thanks for that information. How about the DS18B20? Would it work better? Looking now for the datasheet on the DS.
@teastain2 Ok that worked a treat. The temperature is displaying as it should. Now to figure out why it's all over the place. Thermometer on my desk reads 23.5 while my Lilygo is displaying Anywhere from 17 to 20 degrees. And it's changing every loop of the void loop. And I still have to deal with the time display being corrupted.
Gonna look more into millis().
Thanks for the assistance.
WD
As you can see from the following photo I have a problem with text display. When I first upload the sketch or do a reset on my lilygo t-disply the text will display fine...for about 30 seconds. Then the temperature degrades into the little boxes you see in the photo. The date and time will generally be fine for several hours but after a while that too degrades. I am using the TFT_eSPI library.
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7789.h> // Hardware-specific library for ST7789
#include <SPI.h>
#include <WiFi.h>
#include <Wire.h>
#include "time.h"
const char* ssid = "randomtorok-d";
const char* password = "Chipss12";
int counter = 0;
int dT= 5000;
// pinouts from https://github.com/Xinyuan-LilyGO/TTGO-T-Display
#define TFT_MOSI 19
#define TFT_SCLK 18
#define TFT_CS 5
#define TFT_DC 16
#define TFT_RST 23
#define TFT_BL 4
// constructor for data object named tft
Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);
const char* ntpServer = "pool.ntp.org";
const long gmtOffset_sec = -28800;
const int daylightOffset_sec = 3600;
float getTemperature(){
#define ADC_VREF_mV 5000.0 // in millivolt
#define ADC_RESOLUTION 4095.0
#define PIN_LM35 32 // ESP32 pin GPIO36 (ADC0) connected to LM35
// read the ADC value from the temperature sensor
int adcVal = analogRead(PIN_LM35);
//int adcVal = 250;
// convert the ADC value to voltage in millivolt
float milliVolt = adcVal * (ADC_VREF_mV / ADC_RESOLUTION);
// convert the voltage to the temperature in °C
float tempC = milliVolt / 10;
return tempC;
}
void setup(void) {
Serial.begin(115200);
delay(dT) ;
Serial.println();
Serial.print("Connecting to network: ");
Serial.println(ssid);
WiFi.disconnect(true); //disconnect form wifi to set new wifi connection
WiFi.begin(ssid, password); //connect to wifi
while (WiFi.status() != WL_CONNECTED) {
delay(dT);
Serial.print(".");
counter++;
if (counter >= 60) { //after 30 seconds timeout - reset board (on unsucessful connection)
ESP.restart();
}
// Init and get the time
configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address set: ");
Serial.println(WiFi.localIP()); //print LAN IP
Serial.print(F("Hello! ST77xx TFT Test"));
pinMode(TFT_BL, OUTPUT); // TTGO T-Display enable Backlight pin 4
digitalWrite(TFT_BL, HIGH); // T-Display turn on Backlight
tft.init(135, 240); // Initialize ST7789 240x135
Serial.println(F("Initialized"));
tft.fillScreen(ST77XX_BLACK);
}
void loop() {
if (WiFi.status() == WL_CONNECTED) { //if we are connected to eduroam network
counter = 0; //reset counter
} else if (WiFi.status() != WL_CONNECTED) { //if we lost connection, retry
WiFi.begin(ssid);
}
while (WiFi.status() != WL_CONNECTED) { //during lost connection, print dots
delay(dT);
Serial.print(".");
counter++;
if (counter >= 60) { //30 seconds timeout - reset board
ESP.restart();
}
}
struct tm timeinfo;
if(!getLocalTime(&timeinfo)){
Serial.println("Failed to obtain time");
return;
}
Serial.println(getTemperature());
tft.setRotation(3);
tft.setTextSize(2);
tft.setTextColor(ST77XX_YELLOW);
tft.setTextWrap(true);
tft.setCursor(0, 0);
tft.print("IP: ");
tft.setCursor(40, 0);
tft.print(WiFi.localIP());
tft.setCursor(0, 25);
tft.print("Date/Time: ");
tft.setCursor(0, 50);
tft.print(&timeinfo, "%b %d, %Y %H:%M");
tft.setCursor(0, 75);
tft.print("Temperature: ");
tft.setCursor(74, 100);
tft.setTextSize(3);
tft.print(getTemperature());
}
Here's hoping that someone might have a solution to this issue. All and any comments or suggestions are greatly appreciated.