This is an old revision of the document!
Table of Contents
Laboratory on the Internet of Things - Advanced IoT Hardware - on-site
Laboratory guide for IoT AIH students on ESP32 graphical display programming:
- ESP32 WROVER DEVKIT module - that includes (among others) dot-matrix LCD TFT display
- M5 Stack CORE Ink DEVKIT Module - treat contains (among others) dot-matrix e-paper (e-ink) display
Hardware
* ESP32 WROVER DEVKIT with LCD TFT module * ESP32 PICO D4 M5 Stack with e-Paper (e-Ink) module
Below we present hardware details on those two modules:
ESP32 WROVER DEVKIT
This board is double-sided; on one side, you will find an LCD screen (so-called back) on the other side (front) there are GPIOs connectors you connect sensors and actuators to, TF (microSD) card slot with SPI reader and an RGB LED (among others).
Please note you can directly observe only the back side of the module via the VREL node's camera.
ESP32 provides a number of GPIOs to the developers, but some of them are hard-bound to their features as connected on the development board.
The following list presents GPIOs used with the integrated hardware:
| No | Feature | ESP32 GPIO Pin | Notes |
|---|---|---|---|
| 1 | JTAG | GPIO12-15 | |
| 2 | Camera | GPIO0, GPIO4-5, GPIO18-19, GPIO21-23, GPIO25-27, GPIO34-36, GPIO39 | If you do not use the camera, feel free to use those GPIOs unless they're not shared with another feature. |
| 3 | RGB LED | GPIO0, GPIO2, GPIO4 | |
| 4 | MicroSD card reader | GPIO2, GPIO4, GPIO12-15, GPIO21 | |
| 5 | LCD | GPIO5, GPIO18-19, GPIO21-23, GPIO25 |
Built-in integrated LCD (TFT) display
The built-in display is ILI9341 TFT display, 320×240 pixels (240×320 actually), RGB, 262k colours. Although it is possible to program it raw, we will use a ready software library to control it. This TFT display uses 16-bit per pixel memory organisation, frequently referenced as 565 (RGB, R-5-bits, G-6-bits, B-5-bits).
Configuring VREL - platformio.ini
Correct configuration is necessary to build and deploy your code.
For ESP32 WROVER DEVKIT, a good starting point is the following content for the platformio.ini file:
[env:d1_mini] platform = espressif32 board = esp-wrover-kit framework = arduino lib_ldf_mode = deep+ lib_deps = adafruit/Adafruit GFX Library Wire espressif/WROVER KIT LCD @ ^1.0.3
It is also necessary to configure the serial port name that is used for uploading your firmware and monitoring. In the case of this microcontroller, it is the same port, so the platformio.ini file should be modified with the following (assuming the serial port is, i.e. COM3):
... upload_port = COM3 monitor_port = COM3 ...
Practice: handling LCD display
Write Hello World on the LCD screen.
Using an LCD and a camera, you can observe it through, are your only interface to the devkit. Therefore, please get familiar with handling LCD screens and give it a short practice, as presented below.
Type the textual “Hello World” on the screen. Then, you're welcome to decorate it, change colours, size, orientation, etc.
To use LCD, you must include libraries. The beginning of your .cpp source code file should then look more-less following way:
... #include <Arduino.h> #include <SPI.h> #include <Adafruit_GFX.h> #include <WROVER_KIT_LCD.h> ...
Then define a controller class that manages your LCD:
... WROVER_KIT_LCD tft; ...
Remember to initiate the LCD controller class:
... tft.begin(); ...
Some useful functions to handle LCD operations are presented below (but not limited to):
... tft.fillScreen(WROVER_BLACK); //Clear screen tft.setCursor(0, 0); //Set upper left corner tft.setTextColor(WROVER_WHITE); //Set text colour tft.setTextSize(2); //Set font size tft.println("Hello World!"); // Print the text ...
M5 Stack ESP32 Core Ink DEVKIT
This M5 Stack module is an integrated ESP32 microcontroller (PICO D4 version, full specification) is on the manufacturer's page. This module, even if compact in size, also contains expansion ports, an internal battery powering RTC (BM8563) when no external power is present, 3 physical buttons: reset, power and programmable, a green LED and a passive buzzer.
ESP32 provides a number of GPIOs to the developers, but some of them are hard-bound to their features as connected on the development board.
| No | Feature | ESP32 GPIO Pin | Notes |
|---|---|---|---|
| 1 | EPaper (e-Ink) SPI display controller | GPIO4, GPIO0, GPIO15, GPIO9, GPIO18, GPIO23 | In order: EPaper BUSY, ePaper RST, EPaper DC, EPaper CS, EPaper SCLK, EPaper MOSI |
| 2 | Multifunction button, a physical button, led and buzzer | GPIO37, GPIO38, GPIO39, GPIO5, GPIO10, GPIO2, GPIO12 | In order: Left (up) multifunction, Button press, Right (down) multifunction, Physical button, LED, Buzzer, Power control MOS |
| 4 | Internal I2C for BM8563 (RTC) | GPIO21, GPIO22 | SDA, SCL, module I2C address is 0x51) |
| 5 | External port (I2C) | GPIO32, GPIO33 | software-defined M-BUS |
| 6 | ESP32 Serial (via USB to serial chip, CP2104) | GPIO1, GPIO3 | RXD, TXD |
Built-in integrated e-Paper display
The e-Paper (e-Ink) display is a bi-coloured, 200×200 pixels with an SPI interface module GDEW0154M09. It has an integrated SPI controller.
Configuring VREL - platformio.ini
Correct configuration is necessary to build and deploy your code.
For M5 Stack Core Ink Development Kit, a good starting point is the following content for the platformio.ini file:
[env:m5stack-core-esp32] platform = espressif32 board = m5stack-core-esp32 framework = arduino lib_deps = m5stack/M5Core-Ink@^0.0.7
Practice: handling e-Paper display
Write Hello World on the e-Paper screen.
A special note on PWM in ESP32
PWM is frequently used to control analogue-style, efficient voltage on the GPIO pin. Instead of using a resistance driver, PWM uses pulses to change adequate power delivered to the actuator. It applies to motors but also to LEDs, bulbs, heaters, and indirectly to the servos (but that works actually another way, see lectures).
The classical analogWrite method known as Arduino (Uno, Mega) and ESP8266 do not work here.
ESP32 has sixteen (0 to 15) PWM channels (controllers) that can be freely bound to any of the regular GPIOs.
Moreover, ESP32 can use various “resolutions” of the PWM: from 8-bit (0..255) to 15bit (0..32767), while regular Arduino uses only 8-bit one.
To use PWM in ESP32, one must perform the following steps:
- Configure GPIO pin as
OUTPUT - Initiate PWM controller with fixing PWM frequency and resolution
- Bind the controller to the GPIO pin
- Write to the controller (not to the PIN!) providing a duty cycle related to the resolution selected above - every call persistently sets the PWM duty cycle until there is the next call to the function setting duty cycle.
Laboratory scenarios
In general, you will program using the Arduino framework.
As presented during the lecture, you will also use FreeRTOS functions to handle multicore parallel programming to perform tasks, as demonstrated during the lecture.
... vTaskDelete(NULL); ...
as a last line of your function implementing the task.
Task 1
Evaluate single-core performance for integer computation. Perform two experiments: with task bound to the APP core and separately to the PRO core. First, observe if there is a difference in measurements. Then, propose an algorithm that can generate a complexity of integer computation observable and measurable. Perform at least 10 measurements for each experiment. Consider using parts of code for the Dhrystone benchmark https://en.wikipedia.org/wiki/Dhrystone.
Task 2
Evaluate multicore performance for integer computation. Perform single-core computation, running at least 4 times (any even number works here) your algorithm. Then execute in parallel (2×2). Observe if there is a difference in measurements. Propose an algorithm that can generate a complexity of integer computation observable and measurable. Perform at least 20 measurements for each experiment (10 serial + 10 parallel). Consider using parts of code for the Dhrystone benchmark https://en.wikipedia.org/wiki/Dhrystone.
Task 3
Evaluate single-core performance for floating-point computation. Perform two experiments: with task bound to the APP core and separately to the PRO core. First, observe if there is a difference in measurements. Then, propose an algorithm that can generate a complex-enough floating points computation that is observable and measurable. Perform at least 10 measurements for each experiment. Consider using FP parts of code for Whetstone benchmark https://en.wikipedia.org/wiki/Whetstone_(benchmark).
Task 4
Evaluate multicore performance for floating-point computation. First, perform single-core computation, running your algorithm at least 4 times (any even number works here) your algorithm. Then execute in parallel (i.e. 2×2). Finally, propose an algorithm that can generate a complex-enough floating-point computation that is observable and measurable. Perform at least 20 measurements for each experiment (10 serial + 10 parallel). Consider using FP parts of code for Whetstone benchmark https://en.wikipedia.org/wiki/Whetstone_(benchmark).
Report
Include algorithm definition and measurements, along with statistical analysis of the results (at least average and standard deviation) and a summary.
