I'm trying to convert a project that I had using a Arduino Mega to a ESP32. I have a remote system in my greenhouse with a BME280 that was sending the values to the Mega via NTF24L01's and displayed on a TFT screen
I am new to ESP32's and also just started using the TFT_eSPI library to update the TFT. Currently I'm just trying to redraw the labels on the screen, not reading or displaying the BME values. I have the labels in a function block "drawGreenhouse1()". I call the function from setup. When I run it the screen blinks on and off. I believe it's doing a "tft.fillScreen(TFT_BLACK);" then my labels. If I comment out the function call and put the label logic in setup it works fine, shows the labels and it's not blinking.
I put a Serial.print("Start SetUp") at the beginning of setup, then uncommented the call to the function and commented out the draw labels in setup. What I see is that setup keeps restarting so I assume for some reason when I call the function it is resetting the ESP32.
I don't know why? Is that what's happening, it's resetting the ESP32 or is it something else?
Here is my sketch
// Changed controller to ESP32
#include <SPI.h>
#include <TFT_eSPI.h> // Hardware-specific library
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
//==== Defining Variables
unsigned char text;
//char text[6] = "";
String inTemp, inHum, outTemp = "", outHum;
extern uint8_t SmallFont[];
extern uint8_t BigFont[];
extern uint8_t SevenSegNumFont[];
int x, y;
int currentPage = 0; //, selectedUnit;
int selectedUnit = 0;
char grnHouseTemp[20] = " "; // Greenhouse Temperature number
char grnHouseHum[20] = " "; // Greenhouse Humidity number
long int start_time = millis();
long int read_time = 4800; // time between reading Greenhouse data
int grnHouseRead = 0; // bit that system is reading Greenhouse status
float grnHouse_Temp = 0; // Greenhouse temp
float grnHouse_Hum = 0; // Greenhouse humdity
float grnHouse_Press = 0; // Greenhouse pressure
boolean newData = false;
// temporary array for use when parsing
const byte numChars = 64;
char receivedChars[numChars];
char tempChars[numChars];
// For Greenhouse
char temp_str1[25];
char humd_str1[25];
char prss_str1[25];
char Hour_strl[25];
char Min_strl[25];
char Batt_strl[25];
// Incoming data
struct incomingData {
float In_Temp;
float In_Prss;
float In_Humd;
int In_Hour;
int In_Min;
float Batt_Lvl;
}myincomingDataStructure;
// data from Greenhouse
struct dataStruct1 {
float H1_Temp;
float H1_Prss;
float H1_Humd;
float H1_Batt;
}myDataStructure1;
long int touchTime = 0; // time sceen was last touched
long int scrnSavTime = 60000; // Screen saver display time
int scrnSavOn = 0; //In screen saver mode
const int backLite = 53;
void setup() {
Serial.begin(9600);
Serial.println("Start Setup");
// TFT setup
tft.init();
tft.fillScreen(TFT_BLACK); //clears screen, sets to Black
tft.setRotation(3); // rotates screen 180' for landscape mode
currentPage = 0; // Indicates that we are at Home Screen
selectedUnit = 0; // Indicates the selected unit for the first example, cms or inches
// Serial.println(drawHomeScreen()); // Draws the Home Screen
drawGreenhouse1(); // Draws the Greenhouse 1 Status screen
// Draw labels from Setup
/*
tft.fillScreen(TFT_BLACK);
// Back to Home button
tft.fillRoundRect(30, 20, 50, 30, 10, TFT_BLUE);
tft.drawRoundRect(30, 20, 50, 30, 10, TFT_WHITE);
tft.setCursor(40, 27);
tft.setTextColor(TFT_WHITE);
tft.setTextSize(2);
tft.print("<-");
tft.setCursor(100, 30);
tft.setTextColor(TFT_WHITE);
tft.setTextSize(1);
tft.print("Back to Main Menu");
// Prints the title on the screen
tft.setCursor(80, 70);
tft.setTextColor(TFT_WHITE);
tft.setTextSize(3);
tft.print("Greenhouse Status");
// Draws the red line under the title
tft.drawFastHLine(90, 100, 320, TFT_RED);
// Label - Temperature
tft.fillRect(20, 120, 90, 40, TFT_CYAN);
tft.drawRect(20, 120, 90, 40, TFT_WHITE);
// tft.fillRect(0, 0, 90, 40, TFT_CYAN);
// tft.drawRect(5, 3, 90, 40, TFT_WHITE);
tft.setCursor(32, 130);
tft.setTextColor(TFT_BLACK);
tft.setTextSize(2);
tft.print("Temp = ");
//tft.drawCentreString("Temp = ",120, 70, 4);
// Label Humidity #
tft.fillRect(20, 190, 90, 40, TFT_CYAN);
tft.drawRect(20, 190, 90, 40, TFT_WHITE);
tft.setCursor(35, 200);
tft.setTextColor(TFT_BLACK);
tft.setTextSize(2);
tft.print("Hum = ");
// Label Pressure
tft.fillRect(240, 120, 100, 40, TFT_CYAN);
tft.drawRect(240, 120, 100, 40, TFT_WHITE);
tft.setCursor(250, 130);
tft.setTextColor(TFT_BLACK);
tft.setTextSize(2);
tft.print("Press = ");
// Label Update Time
tft.fillRect(240, 190, 100, 40, TFT_CYAN);
tft.drawRect(240, 190, 100, 40, TFT_WHITE);
tft.setCursor(250, 200);
tft.setTextColor(TFT_BLACK);
tft.setTextSize(2);
tft.print("Time = ");
// Label Battery Llevel
tft.fillRect(20, 260, 135, 40, TFT_CYAN);
tft.drawRect(20, 260, 135, 40, TFT_WHITE);
tft.setCursor(35, 270);
tft.setTextColor(TFT_BLACK);
tft.setTextSize(2);
tft.print("Battery = ");
*/
touchTime = millis(); // start touch time
} // end void setup
void loop() {
} // end void loop
// drawHomeScreen - Menu page
unsigned long drawHomeScreen() {
// Draws Home Screen
tft.fillScreen(TFT_BLACK); //clears screen, sets to Black
// Prints the title on the screen
tft.setCursor(80, 70);
tft.setTextColor(TFT_WHITE);
tft.setTextSize(3);
tft.print("Greenhouse Monitor");
// Draws the red line under the title
tft.drawFastHLine(60, 100, 350, TFT_RED);
// Button - Greenhouse page
tft.fillRoundRect(140, 150, 210, 40, 25, TFT_BLUE);
tft.drawRoundRect(140, 150, 210, 40, 25, TFT_WHITE);
tft.setCursor(170, 160);
tft.setTextColor(TFT_WHITE);
tft.setTextSize(2);
tft.print("Greenhouse");
} // end void drawHomeScreen
unsigned long drawGreenhouse1() {
// Draws Report Setup screen
Serial.println("In drawGreenhouse1");
// Sets the background color of the screen to black
tft.fillScreen(TFT_BLACK);
// Back to Home button
tft.fillRoundRect(30, 20, 50, 30, 10, TFT_BLUE);
tft.drawRoundRect(30, 20, 50, 30, 10, TFT_WHITE);
tft.setCursor(40, 27);
tft.setTextColor(TFT_WHITE);
tft.setTextSize(2);
tft.print("<-");
tft.setCursor(100, 30);
tft.setTextColor(TFT_WHITE);
tft.setTextSize(1);
tft.print("Back to Main Menu");
// Prints the title on the screen
tft.setCursor(80, 70);
tft.setTextColor(TFT_WHITE);
tft.setTextSize(3);
tft.print("Greenhouse Status");
// Draws the red line under the title
tft.drawFastHLine(90, 100, 320, TFT_RED);
// Label - Temperature
tft.fillRect(20, 120, 90, 40, TFT_CYAN);
tft.drawRect(20, 120, 90, 40, TFT_WHITE);
// tft.fillRect(0, 0, 90, 40, TFT_CYAN);
// tft.drawRect(5, 3, 90, 40, TFT_WHITE);
tft.setCursor(32, 130);
tft.setTextColor(TFT_BLACK);
tft.setTextSize(2);
tft.print("Temp = ");
//tft.drawCentreString("Temp = ",120, 70, 4);
// Label Humidity #
tft.fillRect(20, 190, 90, 40, TFT_CYAN);
tft.drawRect(20, 190, 90, 40, TFT_WHITE);
tft.setCursor(35, 200);
tft.setTextColor(TFT_BLACK);
tft.setTextSize(2);
tft.print("Hum = ");
// Label Pressure
tft.fillRect(240, 120, 100, 40, TFT_CYAN);
tft.drawRect(240, 120, 100, 40, TFT_WHITE);
tft.setCursor(250, 130);
tft.setTextColor(TFT_BLACK);
tft.setTextSize(2);
tft.print("Press = ");
// Label Update Time
tft.fillRect(240, 190, 100, 40, TFT_CYAN);
tft.drawRect(240, 190, 100, 40, TFT_WHITE);
tft.setCursor(250, 200);
tft.setTextColor(TFT_BLACK);
tft.setTextSize(2);
tft.print("Time = ");
// Label Battery Llevel
tft.fillRect(20, 260, 135, 40, TFT_CYAN);
tft.drawRect(20, 260, 135, 40, TFT_WHITE);
tft.setCursor(35, 270);
tft.setTextColor(TFT_BLACK);
tft.setTextSize(2);
tft.print("Battery = ");
} // end of drawGreenhouse1
Thanks for any comments or suggestions
John