ESP32 5inch display

I am using an ESP32 5inch display for an application. The application requires communication using MQTT.

When I add PUBSUB library to a working display the MQTT client intermittently disconnects and takes a long time to connect. When I comment out the lcd->begin(); function from the code MQTT works properly.

Can someone help with this problem


/*********

  Rui Santos

  Complete project details at https://randomnerdtutorials.com  

*********/


#include <WiFi.h>

#include <PubSubClient.h>

#include <Wire.h>

#include <Adafruit_BME280.h>

#include <Adafruit_Sensor.h>

#include <Arduino_GFX_Library.h>


/*******************************************************************************

 * Screen Driver Configuration

*******************************************************************************/

Arduino_ESP32RGBPanel *bus = new Arduino_ESP32RGBPanel(

    GFX_NOT_DEFINED /* CS */, GFX_NOT_DEFINED /* SCK */, GFX_NOT_DEFINED /* SDA */,

    40 /* DE */, 41 /* VSYNC */, 39 /* HSYNC */, 0 /* PCLK */,

    45 /* R0 */, 48 /* R1 */, 47 /* R2 */, 21 /* R3 */, 14 /* R4 */,

    5 /* G0 */, 6 /* G1 */, 7 /* G2 */, 15 /* G3 */, 16 /* G4 */, 4 /* G5 */,

    8 /* B0 */, 3 /* B1 */, 46 /* B2 */, 9 /* B3 */, 1 /* B4 */

    );

Arduino_RPi_DPI_RGBPanel *lcd = new Arduino_RPi_DPI_RGBPanel(

    bus,

    800 /* width */, 0 /* hsync_polarity */, 210 /* hsync_front_porch */, 4 /* hsync_pulse_width */, 43 /* hsync_back_porch */,

    480 /* height */, 0 /* vsync_polarity */, 22 /* vsync_front_porch */, 4 /* vsync_pulse_width */, 12 /* vsync_back_porch */,

    1 /* pclk_active_neg */, 16000000 /* prefer_speed */, true /* auto_flush */);

/*******************************************************************************

 * Screen Driver Configuration  end

*******************************************************************************/




// Replace the next variables with your SSID/Password combination

const char* ssid = "**";

const char* password = "***";


// Add your MQTT Broker IP address, example:

//const char* mqtt_server = "192.168.1.144";

const char* mqtt_server = "192.168.2.22";


WiFiClient espClient;

PubSubClient client(espClient);

long lastMsg = 0;

char msg[50];

int value = 0;

unsigned long startMillis;  //some global variables available anywhere in the program

unsigned long currentMillis;


void setup() {

  Serial.begin(115200);

    //lcd->begin();           // Init Display

    delay(200);

  setup_wifi();

    client.setBufferSize(512);

  client.setServer(mqtt_server, 1883);

  client.setCallback(callback);

}


void setup_wifi() {

  delay(10);

  // We start by connecting to a WiFi network

  Serial.println();

  Serial.print("Connecting to ");

  Serial.println(ssid);


  WiFi.begin(ssid, password);


  while (WiFi.status() != WL_CONNECTED) {

    delay(500);

    Serial.print(".");

  }


  Serial.println("");

  Serial.println("WiFi connected");

  Serial.println("IP address: ");

  Serial.println(WiFi.localIP());

}


void callback(char* topic, byte* message, unsigned int length) {

    Serial.print("Message length: ");

    Serial.print(length);

  Serial.print("  Message arrived on topic: ");

  Serial.print(topic);

  Serial.print(". Message: ");

  String messageTemp;


  for (int i = 0; i < length; i++) {

    Serial.print((char)message[i]);

    messageTemp += (char)message[i];

  }

  Serial.println();


}


void reconnect() {

  // Loop until we're reconnected

  while (!client.connected()) {

    Serial.print("Attempting MQTT connection...");

    // Attempt to connect

        startMillis = millis();

    if (client.connect("ESP8266Client")) {

      Serial.println("connected");

      // Subscribe

        currentMillis = millis();

        Serial.println(currentMillis-startMillis);


      client.subscribe("#");

    } else {

      Serial.print("failed, rc=");

      Serial.print(client.state());

      Serial.println(" try again in 5 seconds");

      // Wait 5 seconds before retrying

      delay(5000);

    }

  }

}

void loop()

{

  if (!client.connected()) {

    reconnect();

  }

  client.loop();

  delay(50);


}

Comments

  • Hello Marktecwiz, You can try the method in here https://randomnerdtutorials.com/esp32-mqtt-publish-dht11-dht22-arduino/ . You need to replace #include <PubSubClient.h> with the following two libraries.


  • Thank you Sun for you quick response.

    Can you give me a quick explanation as to why I need the to use the RTOS library?

  • Sunny

    I tried the above and get the same problem.

    I used this example

    it worked better then the first code I posted which answered my question on why use the RTOS library.

    Then I added:

    *******************************************************************************
     * Screen Driver Configuration 
    *******************************************************************************/
    Arduino_ESP32RGBPanel *bus = new Arduino_ESP32RGBPanel(
        GFX_NOT_DEFINED /* CS */, GFX_NOT_DEFINED /* SCK */, GFX_NOT_DEFINED /* SDA */,
        40 /* DE */, 41 /* VSYNC */, 39 /* HSYNC */, 0 /* PCLK */,
        45 /* R0 */, 48 /* R1 */, 47 /* R2 */, 21 /* R3 */, 14 /* R4 */,
        5 /* G0 */, 6 /* G1 */, 7 /* G2 */, 15 /* G3 */, 16 /* G4 */, 4 /* G5 */,
        8 /* B0 */, 3 /* B1 */, 46 /* B2 */, 9 /* B3 */, 1 /* B4 */
        );
    Arduino_RPi_DPI_RGBPanel *lcd = new Arduino_RPi_DPI_RGBPanel(
        bus,
        800 /* width */, 0 /* hsync_polarity */, 210 /* hsync_front_porch */, 4 /* hsync_pulse_width */, 43 /* hsync_back_porch */,
        480 /* height */, 0 /* vsync_polarity */, 22 /* vsync_front_porch */, 4 /* vsync_pulse_width */, 12 /* vsync_back_porch */,
        1 /* pclk_active_neg */, 16000000 /* prefer_speed */, true /* auto_flush */);
    /*******************************************************************************
     * Screen Driver Configuration  end
    *******************************************************************************/
    

    (this comes from the 5 inch display setup code)

    Then if I add

      lcd->begin();           // Init Display
    

    at any place in the set up function

    1 - mqtt takes a long time to connect

    2 - when it does it will disconnect randomly and then take a long time to connect again.

    Removing the begin line will allow the mqtt to work properly and robustly

    This is the same problem PubSub exhibits

  • Sun

    I changed the frame rate from 16mhz to 8 and mqtt worked - but the display flickered

    I found that 12 mhz worked and 14 mhz does not work,

    When I first boot up the display it flickers a little then seems to stop or at least is not noticiable.

    Even at 16mhz there is some flicker on start up then it "goes away".

    Can you comment?

  • Sun

    So the screen is flickering slightly at 12mhz frame rate.

    I am going to try to run the MQTT on the second core but I do not have experience in doing that.

    Any reference will be apreciated

    Mark

  • I found a post regarding the flicker

    Because the voltage value of VCOM 3.3V is not enough. Inputting 3.8V to VCOM can solve this flickering problem.

  • Re: Flicker

    From Elecrow
    Hello Mark,

    Because the performance of ESP32-S3-WROOM-1-N4R8 is insufficient, the screen flickers when it displays gray.
    The 7-inch screen can reduce flicker by modifying the vcom, but because the relevant circuits of the 5-inch screen are integrated on the screen, it cannot be optimized by modifying the PCB.
    If it's convenient, you can send us the code to debug and see if we can reduce the flickering phenomenon.

    **I removed all the grey and I found a function of mine that was writing to the display very ofte.
    Now the 5 inch display does not flicker at all.
    **

Sign In or Register to comment.