Skip to content

tft reinit after deep sleep #19

@biccius

Description

@biccius

Hi

This is meant to be an attempt of improvement on the display drawing speed after the ESP32 wakes up from deep sleep. In all the sources I've seen, the display call tft.init() at every wake of the microcontroller.
This include a hardware or software reset that blank the screen for some milliseconds.

The ST7735 display has sleep and shutdown commands, preserving the contents of the on-screen buffer in memory.

My purpose is to try to:

  • fill the screen with a color A
  • send the esp32 to deep sleep
  • wake up with button press the esp32 and redraw the display with color A
  • then change in progression colors to B, C , etc..

Here's the code i'm working on:

#include <pcf8563.h>
#include <TFT_eSPI.h>            // Graphics and font library for ST7735 driver chip
#include <SPI.h>
#include <WiFi.h>
#include <Wire.h>
#include "sensor.h"
#include "esp_adc_cal.h"


#define TP_PIN_PIN          33
#define TP_PWR_PIN 			25

TFT_eSPI tft = TFT_eSPI();       // Invoke library, pins defined in User_Setup.h
RTC_DATA_ATTR int boots = 0;


void setupTFT()
{
  tft.init();
  tft.setRotation(1);
  tft.setSwapBytes(true);
}


int color = 0x5555;



void Wake()
{
    SPI.begin(TFT_SCLK, TFT_MISO, TFT_MOSI, -1);
    pinMode(TFT_CS, OUTPUT);
    pinMode(TFT_DC, OUTPUT);
    pinMode(TFT_BL, OUTPUT);
	tft.writecommand(ST7735_DISPON);
	tft.writecommand(ST7735_SLPOUT);
}

void Sleep()
{
  tft.writecommand(ST7735_SLPIN);
  tft.writecommand(ST7735_DISPOFF);
  delay(200);

  digitalWrite(GPIO_NUM_26, HIGH);  // keep GPIO_26 high state after deep sleep reset
  gpio_hold_en(GPIO_NUM_26);		// display is preserved
  gpio_deep_sleep_hold_en();

  esp_sleep_enable_ext1_wakeup(GPIO_SEL_33, ESP_EXT1_WAKEUP_ANY_HIGH);
  esp_deep_sleep_start();
}


void setup(void)
{
	  pinMode(TP_PIN_PIN, INPUT);
	  pinMode(TP_PWR_PIN, PULLUP);
	   //! Must be set to pull-up output mode in order to wake up in deep sleep mode
	   digitalWrite(TP_PWR_PIN, HIGH);

	  Serial.begin(115200);

	  if(boots == 0) //Run this only the first time
	  {
		  Serial.println("first boot");
		  setupTFT();
		  tft.fillScreen(color);
		  color+=0x1000;
	  	  boots ++;
	  }
	  else
	  {
		  Serial.println("wake");
		  Wake();
		  tft.setRotation(1);
		  tft.setSwapBytes(1);
		  while (1)
		  {
			  Serial.println("changing color");
			  tft.fillScreen(color);
			  color+=0x1000;
			  delay(1000);
		  }
	  }//if boots
}




void loop()
{
	delay(5000);
	Serial.println("sleep");
	Sleep();
}

Can't understand why after the wake up the display is not working as expected

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions