ESP32 Demoboard: More Applications to Complete the Overview (Part 3)

We close our overview of the prototyping board built around the popular WiFi module with a few more applications. Third instalment.
In the previous two instalments we introduced the demoboard for the famous and very widespread ESP32 SoC from Espressif, which in this case is mounted on an ESP32 board with code YB555. Besides offering some sketches we wrote to introduce you to development with this hardware from an IoT perspective, we described the firmware in detail and created examples that we began presenting in the first and second instalments. Now we continue along this path with the last application examples that use the on-board hardware and the modules that can be connected externally through the dedicated connectors. Specifically, we will use these on-board components and external modules:
UP, DOWN, LEFT, RIGHT and OK buttons;
Servo motor;
0.96″ OLED display;
5V relay (RL1);
Red LED (LD1);
Green LED (LD2).
Let us recall that the heart of the demoboard is the YB555 development and prototyping board based on the ESP32 (ESP-WROOM-32), which integrates 802.11 b/g/n Wi-Fi, dual-mode Bluetooth (classic and BLE) and 25 GPIOs. It supports data rates up to 150 Mbps, has an antenna output power of 20.5 dBm and draws only 5 µA in sleep mode.
LED and button interaction
Let us start with an application in which we use the buttons on the board and show their status on the on-board OLED display (code OLED096C or code OLEDGVSCSD); this example gives an idea of how the buttons can be used and integrated into a real application, getting feedback on the display or triggering specific actions.
The sketch to upload in this case is called OLED_Pulsanti.ino, and once it is running on the ATmega2560 that governs the demoboard, the display shows which of the joystick-style buttons has been pressed, namely UP, DOWN, LEFT, RIGHT and OK (P1, P2, P3, P4, P5). The example code also lets you associate a button press with the on-board LEDs; to be precise, pressing LEFT or RIGHT lights the green LED (LD2), while pressing UP or DOWN turns on the red LED (LD1). If the OK button is pressed, both LEDs light up.
This application and the code that follows, given in Listing 1, can be integrated into others to obtain a button-management module and to link the related inputs to specific actions, which may be not only those described but also the activation of other outputs, not least the relay one.
To use the sketch you must copy the “libraries” folder found in the examples available for download among the files of this issue, under “/Documents”/Arduino”, then open the Arduino IDE and load the example code available in the “OLED_Pulsanti” folder.
Listing 1
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
// The pins for I2C are defined by the Wire-library.
// On an arduino UNO: A4(SDA), A5(SCL)
// On an arduino MEGA 2560: 20(SDA), 21(SCL)
// On an arduino LEONARDO: 2(SDA), 3(SCL), …
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define NUMFLAKES 10 // Number of snowflakes in the animation example
#define LOGO_HEIGHT 16
#define LOGO_WIDTH 16
const int P_UP = 23;
const int P_DOWN = 4;
const int P_LEFT = 16;
const int P_RIGHT = 17;
const int P_OK = 5;
const int LEDV = 26;
const int LEDR = 25;
void setup() {
Serial.begin(9600);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F(“SSD1306 allocation failed”));
for(;;); // Don’t proceed, loop forever
}
// Show initial display buffer contents on the screen —
// the library initializes this with an Adafruit splash screen.
display.display();
delay(2000); // Pause for 2 seconds
// Clear the buffer
display.clearDisplay();
display.setTextSize(2); // Draw 2X-scale text
display.setTextColor(SSD1306_WHITE);
display.setCursor(5, 0);
display.print(“** Test **”);
display.setCursor(20, 30);
display.print(” PUSH “);
// Show the display buffer on the screen. You MUST call display() after
// drawing commands to make them visible on screen!
display.display();
delay(2000);
// display.display() is NOT necessary after every single drawing command,
// unless that’s what you want…rather, you can batch up a bunch of
// drawing operations and then update the screen all at once by calling
// display.display(). These examples demonstrate both approaches…
/*
// Invert and restore display, pausing in-between
display.invertDisplay(true);
delay(1000);
display.invertDisplay(false);
delay(1000);
*/
pinMode(P_UP, INPUT_PULLUP);
pinMode(P_DOWN, INPUT_PULLUP);
pinMode(P_LEFT, INPUT_PULLUP);
pinMode(P_RIGHT, INPUT_PULLUP);
pinMode(P_OK, INPUT_PULLUP);
pinMode(LEDV, OUTPUT);
pinMode(LEDR, OUTPUT);
}
void loop()
{
display.clearDisplay();
display.setTextSize(2); // Draw 2X-scale text
display.setTextColor(SSD1306_WHITE);
switch (Ctrl_Push())
{
case 1:
Serial.println(“Push UP”);
display.setCursor(50, 30);
display.print(“UP”);
digitalWrite(LEDR,HIGH);
break;
case 2:
Serial.println(“Push DOWN”);
display.setCursor(40, 30);
display.print(“DOWN”);
digitalWrite(LEDR,HIGH);
break;
case 3:
Serial.println(“Push LEFT”);
display.setCursor(40, 30);
display.print(“LEFT”);
digitalWrite(LEDV,HIGH);
break;
case 4:
Serial.println(“Push RIGHT”);
display.setCursor(40, 30);
display.print(“RIGHT”);
digitalWrite(LEDV,HIGH);
break;
case 5:
Serial.println(“Push OK”);
display.setCursor(50, 30);
display.print(“OK”);
digitalWrite(LEDR,HIGH);
digitalWrite(LEDV,HIGH);
break;
default:
display.setCursor(40, 30);
display.print(“—-“);
digitalWrite(LEDV,LOW);
digitalWrite(LEDR,LOW);
break;
}
display.display();
delay(500);
}
int Ctrl_Push()
{
int push = 0;
if (digitalRead(P_UP)==LOW) push = 1;
if (digitalRead(P_DOWN)==LOW) push = 2;
if (digitalRead(P_LEFT)==LOW) push = 3;
if (digitalRead(P_RIGHT)==LOW) push = 4;
if (digitalRead(P_OK)==LOW) push = 5;
return push;
}
Servo control
Let us now move on to a second application example that is very interesting because it deals with driving analogue servos (for model making, robotics and so on) through our demoboard; to implement it we use the dedicated servo output, which on the circuit board is the one marked CNU11, with three pins: S (1), 5V (2) and GND (3). This is the standard connection for the 2.54 mm pitch connectors used in servos, such as the one with product code SERVO206, with 1.5 kg torque, 160° rotation and 0.12 s/60° speed at 4.8V.
To drive the servos we wrote the example sketch OLED_Servo.ino, which, when run, sets the demoboard so that the servo connected to connector CNU11 first rotates 180° clockwise and then the same number of degrees anticlockwise; this code therefore performs a functional test of the servos, making their shaft complete a full rotation split into two steps corresponding to the opposite half-turns from the rest position (0 degrees). To use the sketch you must copy the “libraries” folder found in the examples available for download among the files of this issue, under “/Documents”/Arduino”, then open the Arduino IDE and load one of the example codes available in the “OLED_Servo” or “Servo” folders. The complete code for driving the servos is given in Listing 2.
Listing 2
//for Servo
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED displdfsfdfsfdsfdsfdsfdsay height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
// The pins for I2C are defined by the Wire-library.
// On an arduino UNO: A4(SDA), A5(SCL)
// On an arduino MEGA 2560: 20(SDA), 21(SCL)
// On an arduino LEONARDO: 2(SDA), 3(SCL), …
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define NUMFLAKES 10 // Number of snowflakes in the animation example
#define LOGO_HEIGHT 16
#define LOGO_WIDTH 16
//for Servo
static const int servoPin = 18;
Servo servo1;
void setup()
{
Serial.begin(9600);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F(“SSD1306 allocation failed”));
for(;;); // Don’t proceed, loop forever
}
// Show initial display buffer contents on the screen —
// the library initializes this with an Adafruit splash screen.
display.display();
delay(2000); // Pause for 2 seconds
// Clear the buffer
display.clearDisplay();
display.setTextSize(2); // Draw 2X-scale text
display.setTextColor(SSD1306_WHITE);
display.setCursor(5, 0);
display.print(“** Test **”);
display.setCursor(10, 30);
display.print(” Servo “);
// Show the display buffer on the screen. You MUST call display() after
// drawing commands to make them visible on screen!
display.display();
delay(2000);
// display.display() is NOT necessary after every single drawing command,
// unless that’s what you want…rather, you can batch up a bunch of
// drawing operations and then update the screen all at once by calling
// display.display(). These examples demonstrate both approaches…
/*
// Invert and restore display, pausing in-between
display.invertDisplay(true);
delay(1000);
display.invertDisplay(false);
delay(1000);
*/
servo1.attach(servoPin);
}
void loop()
{
for(int posDegrees = 0; posDegrees {
servo1.write(posDegrees);
Serial.println(posDegrees);
delay(20);
}
for(int posDegrees = 180; posDegrees >= 0; posDegrees–)
{
servo1.write(posDegrees);
Serial.println(posDegrees);
delay(20);
}
}
Using the WiFi connection
The ESP32 module that controls the whole demoboard stands out for one feature: it has WiFi connectivity on board, and that is why we chose it: to have built-in connectivity for Internet access and to expose our applications to the network, in a perfect IoT perspective.
As for the WiFi transceiver section, it operates in a frequency range between 2.4 GHz and 2.5 GHz and its main technical characteristics are as follows:
IEEE 802.11 b/g/n HT40 compliance;
baseband and LwIP stack;
Sniffer / Station / SoftAP and Wi-Fi direct mode;
maximum data rate of 150 Mbps@11n HT40, 72 Mbps@11n HT20, 54 Mbps@11g and 11 Mbps@11b;
maximum transmit power 19.5 dBm@11b, 16.5 dBm@11g, 15.5 dBm@11n;
receive sensitivity: -97 dBm.
The transceiver is also set up to support WEP, WPA/WPA2 PSK/Enterprise connection protection modes and encryption with hardware acceleration AES / SHA2 / ECC / RSA-4096. So let’s look at the application example that uses this hardware, which has the device connect to your own WiFi network to run a connectivity test.
Once connected, the IP address assigned to the ESP module will be shown on the display. At the end the module will wait for a connection from a client inside the network, on TCP port 8088. When the connection is established, a message will provide that information and every character typed on the client terminal will be shown on the display, within the display’s capacity. If, once connected, one of the five buttons on the board is pressed, the client will receive the indication of the pressed button on its terminal.
The test sketch is called OLED_WiFi.ino and is located under the examples folder, that is under “/Documents”/Arduino”; open the Arduino IDE and load the sketch, then edit the “apn” and “ssid” variables with your own network parameters, because these will have generic parameters since we cannot know which network the code will be applied to.
In particular, in the example code, which you see in Listing 3, you must edit the following lines:
const char* ssid = “APN NAME”;
const char* password = “APN PASSWORD”;
entering in place of the quoted text APN NAME the name of your access point and in place of APN PASSWORD the password (or passkey) you use to access the WiFi network.
Listing 3
//for WiFi
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
// The pins for I2C are defined by the Wire-library.
// On an arduino UNO: A4(SDA), A5(SCL)
// On an arduino MEGA 2560: 20(SDA), 21(SCL)
// On an arduino LEONARDO: 2(SDA), 3(SCL), …
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define NUMFLAKES 10 // Number of snowflakes in the animation example
#define LOGO_HEIGHT 16
#define LOGO_WIDTH 16
//for WiFi
const char* ssid = “APN NAME”;
const char* password = “APN PASSWORD”;
/* create a server and listen on port 8088 */
WiFiServer server(8088);
const int P_UP = 23;
const int P_DOWN = 4;
const int P_LEFT = 16;
const int P_RIGHT = 17;
const int P_OK = 5;
const int LEDV = 26;
const int LEDR = 25;
void setup() {
Serial.begin(9600);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F(“SSD1306 allocation failed”));
for(;;); // Don’t proceed, loop forever
}
// Show initial display buffer contents on the screen —
// the library initializes this with an Adafruit splash screen.
display.display();
delay(2000); // Pause for 2 seconds
// Clear the buffer
display.clearDisplay();
display.setTextSize(2); // Draw 2X-scale text
display.setTextColor(SSD1306_WHITE);
display.setCursor(5, 0);
display.print(“** Test **”);
display.setCursor(5, 30);
display.print(” WiFi “);
// Show the display buffer on the screen. You MUST call display() after
// drawing commands to make them visible on screen!
display.display();
delay(2000);
// display.display() is NOT necessary after every single drawing command,
// unless that’s what you want…rather, you can batch up a bunch of
// drawing operations and then update the screen all at once by calling
// display.display(). These examples demonstrate both approaches…
/*
// Invert and restore display, pausing in-between
display.invertDisplay(true);
delay(1000);
display.invertDisplay(false);
delay(1000);
*/
pinMode(P_UP,INPUT_PULLUP);
pinMode(P_DOWN,INPUT_PULLUP);
pinMode(P_RIGHT,INPUT_PULLUP);
pinMode(P_LEFT,INPUT_PULLUP);
pinMode(P_OK,INPUT_PULLUP);
Serial.begin(9600);
OLED_Message(“Connecting to “,ssid);
Serial.print(“Connecting to “);
Serial.println(ssid);
/* connecting to WiFi */
WiFi.begin(ssid, password);
/*wait until ESP32 connect to WiFi*/
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(“.”);
}
Serial.println(“”);
Serial.println(“WiFi connected with IP address: “);
String testo = WiFi.localIP().toString();
OLED_Message(“WiFi connected”,testo);
Serial.println(WiFi.localIP());
delay(2000);
/* start Server */
server.begin();
}
void loop()
{
/* listen for client */
WiFiClient client = server.available();
uint8_t data[30];
if (client)
{
OLED_Message(“Client Connected”,””);
Serial.println(“new client”);
display.setCursor(0, 20);
/* check client is connected */
while (client.connected())
{
switch (Ctrl_Push())
{
case 1:
Serial.print(“Push UP”);
client.write(“\nUP”);
break;
case 2:
Serial.println(“Push DOWN”);
client.write(“\nDOWN”);
break;
case 3:
Serial.println(“Push LEFT”);
client.write(“\nLEFT”);
break;
case 4:
Serial.println(“Push RIGHT”);
client.write(“\nRIGHT”);
break;
case 5:
Serial.println(“Push OK”);
client.write(“\nOK”);
break;
default:
break;
}
Attendi_Push();
if (client.available())
{
int len = client.read(data, 30);
if(len {
data[len] = ‘\0’;
}else
{
data[30] = ‘\0’;
}
Serial.print(“client sent: “);
Serial.println((char *)data);
display.print((char *)data);
display.display();
}
}
}
OLED_Message(“Client Disconnected”,””);
}
void OLED_Message(String text_display1,
String text_display2)
{
int lunghezza = 0;
display.clearDisplay();
display.setTextSize(1);
// Draw 2X-scale text
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
lunghezza = text_display1.length();
lunghezza=21-lunghezza;
lunghezza=lunghezza/2;
for (int i=0;i{
display.print(” “);
}
display.print(text_display1);
display.setCursor(0, 20);
length = text_display2.length();
length=21-length;
length=length/2;
for (int i=0;i{
display.print(” “);
}
display.print(text_display2);
display.display();
delay(1500);
}
int Ctrl_Push()
{
int push = 0;
if (digitalRead(P_UP)==LOW) push = 1;
if (digitalRead(P_DOWN)==LOW) push = 2;
if (digitalRead(P_LEFT)==LOW) push = 3;
if (digitalRead(P_RIGHT)==LOW) push = 4;
if (digitalRead(P_OK)==LOW) push = 5;
return push;
}
void Wait_Push()
{
while (( digitalRead(P_UP)==LOW) ||
(digitalRead(P_DOWN)==LOW) ||
(digitalRead(P_LEFT)==LOW) ||
(digitalRead(P_RIGHT)==LOW) ||
(digitalRead(P_OK)==LOW)) delay(10);
}
Scanning the I²C bus
The last example application we propose is actually a utility, since its code lets you query the I²C bus to detect what is connected to it and report on the display or through the Serial Monitor the address of every device attached to it.
As you can see in Listing 4, the code uses the wire.h library, which allows communication with I²C/TWI devices over the two lines SDA (data line) and SCL (Serial Clock), which are both on board and brought out on the expansion connector labelled I2C, which serves devices connected to the bus externally to the board.
Starting with Arduino 1.0, the library has been aligned with the other read/write libraries; for this reason, the original send() and receive() functions have been replaced by read() and write(). Recent versions of the Wire library can use timeouts to prevent a lock-up in the face of certain problems on the bus, but these are not enabled by default in current versions (it is always advisable to enable these timeouts when using the Wire library). So load the latest version of the library.
Listing 4
void setup()
{
Wire.begin();
Serial.begin(9600);
while (!
Serial);
Serial.println(“\nI2C Scanner”);
}
void loop()
{
byte error, address;
int nDevices;
address=0x76;
Serial.println(“Scanning…”);
nDevices = 0;
for(address = 1; address {
// The i2c_scanner uses the return value of
// the Write.endTransmisstion to see if
// a device did acknowledge to the address.
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0)
{
Serial.print(“I2C device found at address 0x”);
if (addressSerial.print(“0”);
Serial.print(address,HEX);
Serial.println(” !”);
nDevices++;
}
else if (error==4)
{
Serial.print(“Unknown error at address 0x”);
if (addressSerial.print(“0”);
Serial.println(address,HEX);
}
}
if (nDevices == 0)
Serial.println(“No I2C devices found\n”);
else
Serial.println(“done\n”);
delay(5000); // wait 5 seconds for next scan
}
Conclusions
Well, with this example of use we end our overview of the ESP32 demoboard, which across three articles has shown you the possibilities for using the hardware, though not all of those possible, both on board and connected through the dedicated connectors. Every example came with a sketch to implement and test it. Now we leave it to you and your inventiveness to implement further applications, which you will test and debug on the demoboard, and then move out of the prototyping phase and build them for good. Happy hacking!
This summary is from Open Electronics, published Nov 14, 2026. NewsFusion links to the original reporting and groups related coverage.




