ESP32 OTA status on TFT display

If you have your ESP32 connected to a display, wouldn’t it be nice to see the status of an OTA update in real time on this display?

I thought it is a nice little add on to my application. And as it is working fine within my ESP32 weather station, I share here as a stand alone code, which makes it easier to understand and integrate into your own application.

In this example I will use a 1.44″ TFT display from Elecrow. This display is equipped with a ILI9163 display driver IC. Bodmer’s TFT_eSPI library works fine on the ESP32 with the ILI9163. Depending on your display you might choose another library. In any way you need to adapt all calls to write to the display to your specific display and library.

The hardware connection is quite simple.

I am using the VSPI bus of the ESP32 to send commands and data to the display. The communication to ILI9163 is only from the ESP32 to the display, there is no data returning to the ESP32. So all we need to connect is the MOSI pin. In the above schematic you can see that I use the MISO pin as A0/CD line which is used to indicates to the display if the bytes sent are a command or data.

And here the software:

We need to include some libraries for the TFT display, the WiFi connection and for OTA.

Then we need some variables and declarations. compileDate is the date and time the app was compiled, otaStatus will be used during the OTA update to remember the progress. tft is the pointer to the display class. activateOTA() is the declaration of the function where I put all the OTA initialization code.

In setup() we setup the Serial connection, initialize the display and connect to the WiFi network. Of course SSID and PASSWD needs to be replaced with the credentials of your WiFi network. After the connection to the WiFi was successful activateOTA is called to initialize and activate the OTA function.

The main loop is only waiting for the OTA to start.

And here is the main part of the software.

To make it easy to select the right device for an OTA update I give each module a name that is put together from the module type and his MAC address. This name is computed inside the application be reading out the MAC address and then use sprintf to create the module name. This name is then used when we initialize the OTA functionality

ArduinoOTA has several callback functions that will be called at different status during the OTA update.

  • onStart is called when the update starts
  • onEnd is called after the update has finished
  • onError is called if an error occurred during the update
  • onProgress is called frequently while the updated application is transfered to the ESP32

We use this four callbacks to display information on the TFT display.

Within the onStart callback we clear the display and write the static text “OTA Progress”.

While the update is ongoing, onProgress is called frequently. The call is made with two parameters, the current progress and the total bytes expected. Out of these two parameters we calculate the progress as percentage and display it.

If the OTA update finished successful, onEnd is called. The ESP32 would reset immediately after returning from this call. So to give the user the chance to see the success message a small delay is added before continuing.

If anything went wrong during the update, onError is called. Here we use the provided error code to display the reason of the failure on the display.

After defining the callbacks, we can call ArduinoOTA to activate the OTA functionality. And I added some more service text for the mDNS service to identify the module.

And here how the whole OTA update process is shown on the display:

For convenient copying I put the whole code together below.

Or you can just pull the whole PlatformIO/Visual Studio Code project from my Github repo.





  • Nikola

    Can you tell me what edit you do in library to make connection with display?
    Thank you!


Leave a Reply

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

Free Link Directory