ad space

Getting Started with a 1.3-Inch OLED Display and Arduino Uno

OLED displays are widely used in electronics projects due to their high contrast, wide viewing angles, and low power consumption. This guide will walk you through the process of testing a 1.3-inch OLED display (SH1106, 128x64) with an Arduino Uno. By the end, you'll be able to display text on the OLED and build a foundation for more complex projects.


Components Required

  • Arduino (Uno, Mega, Nano, etc.)
  • 1.3-inch OLED Display (SH1106, 128x64)
  • Connecting wires
  • Breadboard (optional)

Step 1: Connecting the OLED Display to Arduino Mega

Most OLED displays use the I2C communication protocol, requiring only four connections:

OLED PinArduino Mega Pin
VCC5V
GNDGND
SCLPin 21 (SCL)
SDAPin 20 (SDA)

Here's the circuit diagram for the wiring:

 

1.3-Inch OLED Display and Arduino Uno


Step 2: Installing Necessary Libraries

To enable communication between the Arduino and the OLED, you'll need the following libraries:

a. Adafruit SH1106 Library

The SH1106 library is used because some older OLED modules, like the one in this guide, do not work with the SSD1306 library. Using the SSD1306 driver may result in a blank or garbled screen.

  • Download the SH1106 library from GitHub.
  • Install the library in the Arduino IDE:
    1. Open Arduino IDE.
    2. Go to Sketch > Include Library > Add .ZIP Library.
    3. Locate the downloaded SH1106 ZIP file and click Open.

Verify the library installation by checking Sketch > Examples > Adafruit_SH1106-master.


b. Adafruit GFX Library

The GFX library provides graphics functions for the OLED display.

  • To install:
    1. Open Arduino IDE.
    2. Go to Sketch > Include Library > Manage Libraries.
    3. Search for Adafruit GFX Library and click Install.

Step 3: Writing and Uploading the Test Code

Here’s a sample code to display "Hello, World!" on the OLED:

-------------------------------------------

Explanation of the Code:

  1. Library Inclusions: Adds required libraries for the OLED.
  2. Initialization: Sets up the OLED with the I2C address 0x3C.
  3. Text Configuration: Specifies text size, color, and position.
  4. Display Update: Outputs "Hello, World!" on the OLED screen.

Step 4: Uploading the Code to Arduino Mega

  1. Connect the Arduino Mega to your computer using a USB cable.
  2. Open the Arduino IDE and paste the above code into a new sketch.
  3. Select the correct board and port from the Tools menu:
    • Board: "Arduino Uno".
    • Port: The COM port associated with your Arduino.
  4. Click the Upload button.

Step 5: Observing the Output

After uploading the code, you should see "Hello, World!" displayed on the OLED screen, confirming that the display is functioning correctly.


Troubleshooting Tips

  • Check Connections: Ensure wires are securely connected to the correct pins.
  • Address Issues: If the display doesn’t work, run an I2C scanner sketch to identify the correct I2C address.
  • Reinstall Libraries: If errors persist, reinstall the SH1106 and GFX libraries.

Conclusion

This guide demonstrates how to test a 1.3-inch OLED display with an Arduino Uno. Once your setup is functional, you can expand it to display graphics, sensor data, or other dynamic content. For more inspiration, check out our LCD Display of Temperature and Humidity Tutorial, where a 16x2 LCD is used for sensor data display.

Post a Comment

Previous Post Next Post