ESP32 – connecting OLED display

Reading time: 2 min.

In the previous article we briefly explained what ESP32 is and what it can be used for. We also learned how to read data from a DS18B20 temperature sensor and display the measurement results on the serial monitor of the Arduino IDE environment, as well as – thanks to a server we’ve created – in a web browser. We also presented how to properly configure the Arduino IDE to work with the ESP32 module. Today we’ll show you how to connect the OLED display and display the values from the temperature sensor.

What we need to complete the project

To create the project we will of course need the ESP32 module itself and an OLED display. We used a 1.3″ OLED screen based on the SH1106 controller. We recommend the kit we created with the ESP32 module where you can find all the required components.

The full list of components * used:

* If link redirects to Category page then the element is optional

Connecting OLED display to ESP32

The display communicates with the module via the I2C interface. We connected it to pins 21 (SDA) and 22 (SCK).

 width=
 width=

Uploading libraries for OLED display

In order to properly operate the display with the SH1106 controller, you need to install the appropriate libraries in the Arduino IDE environment. The required libraries can be found at the links:

Downloaded libraries stand as .zip package, install them in Arduino IDE environment.

 width=

A window will appear where you search for the location of the downloaded packages, then select the .zip library and select the Open button.

Programming the ESP32 module

After properly uploading the libraries for the OLED display we can start programming the ESP32 module. The following code will display the standard “Hello World” on the screen.

The placement of elements on the screen can be configured freely by changing the position of the cursor. To do this just add this line in the code:

display.setCursor(X, Y);

where X is the horizontal position and Y is the vertical position. Start / default value is (0, 0).

Below is a sample code with the position of the displayed caption changed.

Display of temperature sensor data on OLED screen

To connect the display, use the same components and libraries we used in the previous ESP32 – connecting to a DS18B20 temperature sensor article. The diagram shows correct connection of the DS18B20 sensor and OLED display to ESP32 module.

 width=

The following code allows to read data from DS18B20 temperature sensor and to display it on OLED.

The size of the text can be freely modified by changing the values in the line:

display.setTextSize();

Stay tuned for articles related to connecting other modules and sensors together with the ESP32 on Botland Blog.

How useful was this post?

Click on a star to rate it!

Average rating 4.5 / 5. Vote count: 8

No votes so far! Be the first to rate this post.

Share:

Picture of Grzegorz Galuba

Grzegorz Galuba

He doesn’t have time for chit-chat - Grzegorz is always up to date with all of the new products from Botland’s offer. He chooses only the best ones and makes sure they appear on time. His extensive knowledge about technical specification of our products is a priceless support to our whole team. He rides a bike to work and it’s high time everybody followed his example. Oasis of peace.

See more:

Leave a Reply

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

For security, use of Google's reCAPTCHA service is required which is subject to the Google Privacy Policy and Terms of Use.