096 Inch 4pin Blue Yellow Iic I2c Oled Display Module
OLED I2C Display Arduino Tutorial
Created on: 17 October 2017
How to connect and program the Geekcreit 0.96 inch 4 pin white I2C OLED module with Arduino. OLED display based on a SSD1306 OLED driver IC.
In this tutorial a 0.96 inch monochrome OLED display from Geekcreit is connected or interfaced to an Arduino. Libraries are then installed and some example programs run which show how to use the display in an Arduino sketch.
The display connects to Arduino using only four wires – two for power and two for data, making the wiring very simple. The data connection is I2C (I²C, IIC or Inter-Integrated Circuit). This interface is sometimes called TWI (Two Wire Interface).
At the very lowest level, the Arduino Wire library is used to communicate with the display. Libraries are available that make it easy to start using the display right away to display text and graphics. These libraries are installed in this tutorial.
How to Connect the Geekcreit 0.96 Inch I2C OLED Display to Arduino
The first and most important thing to note is that some of the displays may have the GND and VCC power pins swapped around. Check your display to make sure that it is the same as the image below. If the pins are swapped, make sure to change the connections to the Arduino – OLED VCC connects to 5V on the Arduino, OLED GND to GND on the Arduino.
Caution! Make sure that you connect the power pins correctly. Some modules have GND and VCC swapped around. Don't blow up your display!
Also make sure that your display is 5V compatible as this one is.
Arduino Uno OLED Wiring
The image below shows how to connect the Geekcreit 0.96 inch OLED I2C display to Arduino. Pin connections are as follows for wiring the OLED display to an Arduino Uno.
- OLED GND – Arduino GND
- OLED VCC – Arduino 5V
- OLED SCL – Arduino Uno A5
- OLED SDA – Arduino Uno A4
Arduino MEGA 2560 OLED Wiring
Pin connections for wiring an Arduino MEGA 2560 to the OLED display are as follows.
- OLED GND – Arduino GND
- OLED VCC – Arduino 5V
- OLED SCL – Arduino MEGA 2560 pin 21
- OLED SDA – Arduino MEGA 2560 pin 20
Arduino OLED I²C Libraries for SSD1306 and Graphics Functions
Two Arduino libraries must be installed to start using the display. The SSD1306 driver library is used to initialize the display and provide low level display functions. The GFX library provides graphics functions for displaying text, drawing lines and circles, etc. Both these libraries are available from Adafruit.
Install the SSD1306 Driver Library
Download the Adafruit_SSD1306 library which is saved to your computer in a file called Adafruit_SSD1306-master.zip.
Copy the Adafruit_SSD1306-master folder from the downloaded zipped file into the Arduino libraries folder. This folder is usually found at Documents → Arduino → libraries on Windows systems. On Linux it is usually found at home folder → Arduino → libraries.
Finally in the Arduino library folder, rename the Adafruit_SSD1306-master folder to Adafruit_SSD1306.
Install the GFX Library
Download the Adafruit_GFX library which is saved to your computer in a file called Adafruit-GFX-Library-master.zip.
Copy the Adafruit-GFX-Library-master folder from the downloaded zipped file to the Arduino library folder as done for the SSD1306 driver above.
In the Arduino library folder rename the Adafruit-GFX-Library-master folder to Adafruit_GFX.
Verifying the Library Installation
After installing the libraries, your Arduino library folder should look as follows.
The contents of the two library folders should look as follows, with the SSD1306 driver library folder on the left and GFX library on the right.
Finding the OLED Libraries in Arduino
If the Arduino IDE was open during the library installation, close it first and then restart it.
In the Arduino IDE, find the libraries under the Sketch → Include Library menu from the top menu bar. When the mouse cursor is hovered above the Include Library menu item, the new libraries can be found on the pop-out menu. In Windows the libraries appeared under "Contributed libraries" near the top of the pop-out menu on my system. On my Linux computer the libraries appeared under the "Recommended libraries" section of the pop-out menu near the bottom.
Modifying the SSD1306 Driver
The SSD1306 driver isn't set up for the Geekcreit OLED display by default. The display size must be changed in the driver before it can be used. If it is not changed, an error message will appear when attempting to verify the example sketch (see the section below) in the Arduino IDE:
#error ("Height incorrect, please fix Adafruit_SSD1306.h!");
Open the Adafruit_SSD1306 folder that was just installed in the Arduino libraries folder. Find Adafruit_SSD1306.h and open it in a text editor. Scroll down the file to find the section with the header SSD1306 Displays or search for for this term in the text editor to find it quickly. Comment out #define SSD1306_128_32 and uncomment #define SSD1306_128_64 so that the code in this section looks as follows.
/*========================================================================= SSD1306 Displays ----------------------------------------------------------------------- The driver is used in multiple displays (128x64, 128x32, etc.). Select the appropriate display below to create an appropriately sized framebuffer, etc. SSD1306_128_64 128x64 pixel display SSD1306_128_32 128x32 pixel display SSD1306_96_16 -----------------------------------------------------------------------*/ #define SSD1306_128_64 // #define SSD1306_128_32 // #define SSD1306_96_16 /*=========================================================================*/
Save the file after making the changes.
Running the Adafruit Example Sketch
If the libraries for the display were installed correctly, example programs for the display will be found in the Arduino IDE under File → Examples → Adafruit SSD1306 – open the ssd1306_128x64_i2c sketch under this menu.
The I²C address must be changed in this sketch in order for it to work with the Geekcreit display. Change the address from 0x3D to 0x3C as shown in the code below. This address is not 0x78 or 0x7A as printed on the back of the OLED board.
void setup() { Serial.begin(9600); // by default, we'll generate the high voltage from the 3.3v line internally! (neat!) //display.begin(SSD1306_SWITCHCAPVCC, 0x3D); // initialize with the I2C addr 0x3D (for the 128x64) display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // changed this to 0x3C to make it work // init done
As shown above, the address was changed to 0x3C in display.begin(). The original line of code is shown above it and is commented out.
After making the changes, the sketch can be uploaded to the Arduino. When building the sketch for an Arduino Uno the IDE will display a low memory warning message, but the sketch will still run.
If the changes to the driver and example sketch were made correctly and the OLED display is wired to the Arduino correctly, the sketch should start running. The example program starts by showing the Adafruit logo, it then turns on a single pixel. Various graphics and text functions are then displayed.
You can help the Starting Electronics website by making a donation:
Any donation is much appreciated and used to pay the running costs of this website. Click the button below to make a donation.
Quick Start Programming Tips
This section of the tutorial shows how to quickly start using the I2C OLED display with the Adafruit libraries. A quick start Arduino template sketch, text display demo and various graphics functions follow.
Arduino Sketch Template File
The template file below can be used to quickly start new OLED projects. It includes the necessary header files and initialization code for the display. Copy the code and use it as a basis for starting new OLED display projects.
/*------------------------------------------------------------------------------------- * Template file for 4-pin I2C OLED display, e.g. from Geekcreit * using Adafruit SSD1306 driver and GFX libraries. * Tutorial: * https://startingelectronics.org/tutorials/arduino/modules/OLED-128x64-I2C-display/ *-------------------------------------------------------------------------------------*/ #include <Wire.h> #include <Adafruit_SSD1306.h> #include <Adafruit_GFX.h> // OLED display TWI address #define OLED_ADDR 0x3C // reset pin not used on 4-pin OLED module Adafruit_SSD1306 display(-1); // -1 = no reset pin // 128 x 64 pixel display #if (SSD1306_LCDHEIGHT != 64) #error("Height incorrect, please fix Adafruit_SSD1306.h!");
0 Response to "096 Inch 4pin Blue Yellow Iic I2c Oled Display Module"
Post a Comment