Laser Tag C03 – OLED display

Love Jesus, Love Code

This tutorial will take approximately 30 mins.

One of the most popular displays for electronics projects is the one on the right-hand side. It typically requires the creator to connect around 10 pins to operate. This not only consumes a significant number of pins on the development board but often leads to difficulties in making accurate connections. Additionally, this display is limited to showing only 2 lines of 16 characters.

In contrast, the OLED display on the left-hand side has become one of my preferred options. With a resolution of 128 x 64 pixels, it can display graphics as well as 7 lines of text, each with a length of approximately 20 characters, and is only marginly more expensive.

Another benefit of the OLED display is its I²C interface. This requires less wiring and utilises serial communication through a data line (SDA) and a clock line (SCL). The older 2 x 16 display comes in two versions, one of which has an I²C controller attached, simplifying the wiring. However, the 0.96-inch OLED display is far superior and will be the one we use.

Connect the OLED display to the ESP32

The ESP32 features two I2C bus interfaces that can be connected to any pins. However, it is advisable to use the default pins to minimise the risk of conflicts within the system. The default I2C pins on the ESP32 are GPIO 21 for SDA and GPIO 22 for SCL.

Connect the OLED display as illustrated in the circuit below. Please note that some OLED displays may have pins arranged in a different order, so be sure to check the pin labels on your specific OLED display.

Connect D21 to SDA (data line) and D22 to SCK (clock line), and connect the power

Install Libraries

Install the following Libraries:

  • Adafruit SSD1306 by Adafruit
  • Adafruit GFX Library by Adafruit

Open Example Software

You will remember from previous tutorials that example programs are excellent for learning how to implement various features or components.

Change the OLED display address to 0x3C

Test that your OLED display works

Create a new version of LaserTag

  • If you make a mistake in your coding, it’s advisable to keep different versions of your code.
  • Open your previous code, LaserTag_0.1.ino, and save it as LaserTag_0.2_OLED.
  • The addition of “OLED” at the end serves as a reminder that we included OLED support in version 0.2 of our software.

Create an OLED tab and add code

In this tab, we will include a setup function named setupOLED() and another function for updating the screen with content, which we will call displayUpdate().

The code above will display the IP address and the host name on the screen, which will assist in identifying the device on the network.

Add OLED libraries and variables to main tab

Run the program and it should look like the image below:

Christian Content

There are various displays that can be used on the laser taggers. At the beginning of the tutorial, we encountered a larger 16 x 2 LCD display alongside a significantly smaller 0.96-inch OLED monochrome display. Despite its size, the small screen can be quite powerful. Without witnessing both screens in action, one might assume that the larger display would be superior.

Jesus taught us, “The kingdom of heaven is like a mustard seed, which a man took and planted in his field. Though it is the smallest of all seeds, yet when it grows, it is the largest of garden plants and becomes a tree” (Matthew 13:31-32). Similarly, the tiny OLED display demonstrates that what seems small and insignificant can have a substantial impact.

It is easy to underestimate the significance of God’s kingdom. However, what began in Jerusalem 2,000 years ago has spread to the ends of the earth, just as prophesied in Acts 1:8: “But you will receive power when the Holy Spirit has come upon you, and you will be my witnesses in Jerusalem and in all Judea and Samaria, and to the end of the earth.”

Another advantage of the OLED display over the LCD display is its contrast. In the OLED display, each pixel is an LED light, producing messages with a high level of contrast and clarity. In contrast, the LCD display relies on a backlight; the main display does not emit light but instead blocks it, creating the pixels and letters.

Just as each pixel in the OLED generates its own light, Christians are called to be “the light of the world” (Matthew 5:14). We do not merely reflect God’s light; through the Holy Spirit, we become sources of light ourselves, enabling others to see our good deeds and glorify our Father in heaven.

The stark black and white contrast of OLED displays powerfully illustrates the clear distinction between light and darkness found in scripture. As it says in Ephesians 5:8-11: “For at one time you were darkness, but now you are light in the Lord. Walk as children of light (for the fruit of light is found in all that is good and right and true), and try to discern what is pleasing to the Lord. Take no part in the unfruitful works of darkness, but instead expose them.” In this way, Christians are meant to stand out distinctly from those around them.

Consider what it might mean to be a light in the darkness.

Leave a Reply