ESP32 and ILI9341 ISP mode

After trying several options that I found on the web, I chose this one as the better to connect an ESP32 to an ILI9341 TFT display.

ESP32 ILI9341
3V3 VCC
GND GND
D15 CS
D2 RESET
D4 D/C
D23 MOSI
D18 SCK
Not connected MISO
3V3 (***or D19) LED

The code:

/**
 * ILI9341 TFT libraries and resources
 */
const int TFT_CS = 15;
const int TFT_DC = 4;
const int TFT_MOSI = 23;
const int TFT_SLK = 18;
const int TFT_RST = 2;
const int TFT_LED = 19;     

#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_SLK, TFT_RST);

void setup() {
  tft.begin();
  tft.setRotation(3); //Landscape orientation
}

The reason for the two possibilities for the LED pin is the next:

If you connect LED pin directly to 3V3 you will get maximum brightness in your screen. LED pin controls the backlight of your TFT display.

In my case, I didn’t want to have max brightness but I wanted to control the intensity based on ambient light, so I decided to connect LED pin to any of the IO pins of the ESP32 (#19 in the showed example).

The code to control backlight intensity (once you have connected LED to pin D19) is as follows:

.
const int TFT_LED = 19; 
.
/**
 * PWM Constants
 */
const int freq = 5000;
const int tftledChannel = 0;
const int resolution = 8;
.
.
.
void setup() {
.
.
.
  /**
   * TFT DISPLAY
   */
  //Background light PWM
  ledcSetup(tftledChannel, freq, resolution);
  ledcAttachPin(19, tftledChannel);
.
.
}

/**
 * Sets TFT background luminosity (0-255)
 */
void setBGLuminosity(int level){
  ledcWrite(tftledChannel, level);
}

Inserting the code above allows you to set the backlight intensity at any point just invoking setBGLuminosity() function passing a value between 0 and 255.

 

//Examples:
setBGLuminosity(0);   //Switch off screen backlight
setBGLuminosity(128); //Medium intensity (theoretically)
setBGLuminosity(255); //Full intensity

2 thoughts on “ESP32 and ILI9341 ISP mode”

  1. Are you sure that an ESP32 pin can power safely the TFT background led?

    Anyway nice project! Maybe you can use a BME280 I2C sensor (pressure, temperature, humidity) and add a somple weather forecast using Zambretti algorithm. OR download it from the web!

    1. Thanks for the comment!
      No, I am not 100% sure. I tried with a 100Ohm resistor and intensity dropped down more than I expected to do. When I measured the current between the led and GPIO pin (without the resistor) and the result was 2.5mA.
      PWM-ILI9341 measured current
      Maybe internal GPIO impedance is being enough?
      I’ll try with lower value resistors, but the fact is that the prototype has been working for one week and I haven’t detected any component heated.
      Anyway, thanks a lot for your advice.
      About the pressure sensor, look 😀
      Ebay orders screenshot
      I’ve already purchased one week ago some BMP280 for that reason… but it will take some time to arrive from China. 🙁

      I didn’t know about Zambretti algorithm, so thanks a lot for the suggestion.

Leave a Reply to B37u70 Cancel reply

Your email address will not be published. Required fields are marked *