Example Code for Arduino-Hello World Display
Last revision 2026/01/19
This blog post guides readers through setting up an Arduino project to display 'Hello World!' using an ESP32 and OLED display module. The post includes detailed hardware and software preparation steps, wiring diagrams, and sample code. It also provides insights into library selection and display configuration to ensure successful implementation of the project, making it an ideal resource for both beginners and experienced users looking to enhance their Arduino skills.
Hardware Preparation
- ESP32-E (or similar) x 1
- 1.51" Transparent OLED Display Module x1
- Dupont Wires
Software Preparation
- Arduino IDE
- Download and install the U8g2 Arduino Library. (About how to install the library?)
Wiring Diagram

Wiring Detail Diagram:


Note: You can refer to the FPC cable color to access the correct position.
Other Preparation Work
- Demos are stored in
U8g2_Arduino-master > DFRobot_Demo > 1.51 inch OLED12864-SSD1309.

- Ensure the correct U8G2 function is enabled in the code.
- select the library
Sample Code
/*!
* @file HelloWorld.ino
* @brief Display Hello World!
* @n U8G2 supports fonts of various sizes. This demo only present one font size to show "Hello World!"
* @n U8G2 Font GitHub link:https://github.com/olikraus/u8g2/wiki/fntlistall
*
* @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
* @licence The MIT License (MIT)
* @author [Ivey]([email protected])
* @maintainer [Fary]([email protected])
* @version V1.0
* @date 2019-10-15
* @url https://github.com/DFRobot/U8g2_Arduino
*/
#include <Arduino.h>
#include <U8g2lib.h>
#include <SPI.h>
/*
* Display hardware IIC interface constructor
*@param rotation:U8G2_R0 Not rotate, horizontally, draw direction from left to right
U8G2_R1 Rotate clockwise 90 degrees, drawing direction from top to bottom
U8G2_R2 Rotate 180 degrees clockwise, drawing in right-to-left directions
U8G2_R3 Rotate clockwise 270 degrees, drawing direction from bottom to top
U8G2_MIRROR Normal display of mirror content (v2.6.x version used above)
Note: U8G2_MIRROR need to be used with setFlipMode().
*@param reset:U8x8_PIN_NONE Indicates that the pin is empty and no reset pin is used
* Display hardware SPI interface constructor
*@param Just connect the CS pin (pins are optional)
*@param Just connect the DC pin (pins are optional)
*
*/
#if defined ARDUINO_SAM_ZERO
#define OLED_DC 7
#define OLED_CS 5
#define OLED_RST 6
/*ESP32 */
#elif defined(ESP32)
#define OLED_DC D2
#define OLED_CS D6
#define OLED_RST D3
/*ESP8266*/
#elif defined(ESP8266)
#define OLED_DC D4
#define OLED_CS D6
#define OLED_RST D5
/*AVR series board*/
#else
#define OLED_DC 2
#define OLED_CS 3
#define OLED_RST 4
#endif
U8G2_SSD1309_128X64_NONAME2_1_4W_HW_SPI u8g2(/* rotation=*/U8G2_R0, /* cs=*/ OLED_CS, /* dc=*/ OLED_DC,/* reset=*/OLED_RST);
void setup(void) {
u8g2.begin();
u8g2.setFontPosTop();
}
void loop(void) {
u8g2.firstPage();
do
{
u8g2.clearBuffer(); // clear the internal memory
u8g2.setFont(u8g2_font_t0_17b_tr ); // choose a suitable font
u8g2.drawStr(0,5,"Hello World!"); // write something to the internal memory
u8g2.sendBuffer(); // transfer internal memory to the display
} while( u8g2.nextPage() );
delay(2000);
}
Result
Result(There are many demo screens in this example. The following are some pictures in the demo screen ):

Was this article helpful?
