members
Basics: Project 057a White 0.96" I2C / SPI OLED display module
of Lex C. in UNO
Basics: Project 057a
Project name: White 0.96" I2C / SPI OLED display module
Tags: Arduino Uno, Arduino, 0.96" I2C, White OLED display module, 128x64, 128x32, GMS096A, Adafruit Monochrome OLED, SPI OLED, SSD1306
Attachments: library1, library2, library3, OLEDtextsketch128x64, testsketch128x64I2C, testsketch128x32I2C, testsketch128x64SPI, testsketch128x32SPI, U8glibexamplessketch
In this project, you needed these parts (Dear visitors. You can support our project buy clicking on the links of parts and buying them or donate us to keep this website alive. Thank you):
1.Arduino Uno R3 (you can also use the other version of Arduino)
2. 0.96" I2C OLED display module 1 pc
3.Arduino IDE ( you can download it from here )
4.Jumper cables F-M
General
We will learn how to connect 0.96" I2C OLED display module to Arduino board and use it.
Understanding the 0.96" I2C OLED display module
OLED (Organic Light-Emitting Diode) is a self light-emitting technology composed of a thin, multi-layered organic film placed between an anode and cathode. In contrast to LCD technology, OLED does not require a backlight. OLED possesses high application potential for virtually all types of displays and is regarded as the ultimate technology for the next generation of flat-panel displays.
OLEDs basic structure consists of organic materials positioned between the cathode and the anode, which is composed of electric conductive transparent Indium Tin Oxide (ITO). The organic materials compose a multi-layered thin film, which includes the Hole Transporting Layer (HTL), Emission Layer (EML) and the Electron Transporting Layer (ETL). By applying the appropriate electric voltage, holes and electrons are injected into the EML from the anode and the cathode, respectively. The holes and electrons combine inside the EML to form excitons, after which electro luminescence occurs. The transfer material, emission layer material and choice of electrode are the key factors that determine the quality of OLED components.
These displays are small, only about 1" diameter, but very readable due to the high contrast of an OLED display. This display is made of 128x64 individual white OLED pixels, each one is turned on or off by the controller chip. Because the display makes its own light, no backlight is required. This reduces the power required to run the OLED and is why the display has such high contrast and crisp.
It can be used with either an SPI or I2C interface (depends on the maker) - selectable by soldering two jumpers on the back. The design is completely 5V-ready, with an onboard regulator and built in boost converter. It's easier than ever to connect directly to your 3V or 5V microcontroller without needing any kind of level shifter!
The driver chip, SSD1306 can communicate in multiple ways including I2C (I²C, IIC or Inter-Integrated Circuit), SPI and 8-bit parallel. However, only the 128x64 display has all these interfaces available.
Features:
- Diagonal Screen Size:0.96"
- Number of Pixels:128 x 64
- Color Depth:White
- Dimension:27.8 x27.3x 4.3 mm
- Working Voltage: 3.3~ 5V DC
- Power: 0.06W Max
- Viewing Angle: >160 Degree
- Driver IC:SSD1306
- Brightness ( cd/m2):150 (Typ) @ 5V
- Interface: I2C
- Adafruit board/chip uses I2C 7-bit address between 0x3C-0x3D, selectable with jumpers
You can find the SSD1306 datasheet here.
Signals and connections of the 0.96" I2C OLED display module
The nice thing about the 128x64 OLEDs is that they can be used with I2C (+ a reset line) or SPI. SPI is generally faster than I2C but uses more pins. It's also easier for some microcontrollers to use SPI.
Make sure that you connect the power pins correctly. Some modules have GND and VCC swapped around. Don't blow up your display!
Data - Connected to I2C SDA if Adafruit OLED display module
Clk - SCK (Serial Clock) - SPI communication.The clock pulses which synchronize data transmission generated by the master. Connect to I2C SCL if Adafruit OLED display module.
SA0 (DC or D/C) - This is Data/Command control pin. When it is pulled HIGH , the data at D[7:0] is treated as data. When it is pulled LOW, the data at D[7:0] will be transferred to the command register. In I2C mode, this pin acts as SA0 for slave address selection.
RST (RES) - This pin is reset signal input. When the pin is pulled LOW, initialization of the chip is executed. Keep this pin HIGH during normal operation.
CS - (Chip Select) - the pin that the master can use to enable and disable specific devices.
3.3vo (3.3v) - this is the power pin. Should be connected to +3.3 VDC pin of Arduino board.
Vin - this is the power pin. 3 to 5V power supply. All OLEDs are safe to use with 3.3V logic and power.
VCC - this is the power pin. Can be connected to +5VDC or +3.3VDC pin of Arduino board (depends on the display module). All OLEDs are safe to use with 3.3V logic and power.
GND - ground. Connected to Arduino board GND pin.
SDA - Serial Data Line. Connected to Arduino Uno SDA or Analog pin A4.
SCL - Serial Clock Line. Connected to Arduino Uno SCL or Analog pin A5.
D0 - Master In Slave Out (MISO) - SPI communication. The Slave line for sending data to the master.
DI (DIN) - Master Out/Slave In (MOSI). SPI communication. The Master line for sending data to the peripherals.
NC - Not in use.
Wiring
1. I2C interface
The display can be used with any I2C microcontroller. Because the I2C interface is for 'writing' to the display only, you'll still have to buffer the entire 512 byte frame in the microcontroller RAM - you can't read data from the OLED (even though I2C is a bidirectional protocol).
1a) Standard or Adafruit white 0.96" I2C OLED display module
0.96" I2C OLED display module -> Arduino Uno
SCL -> SCL (A5)
SDA -> SDA (A4)
VCC (Vin)-> 3.3V, can be 5V (depends on display module)
GND ->GND
1b) Adafruit white 0.96" I2C SPI OLED display module
To start, you'll need to solder the two jumpers on the back of the OLED. Both must be soldered 'closed' for I2C to work!
0.96" I2C / SPI OLED display -> Arduino Uno
GND -> GND
Vin -> 5V
Data -> SDA or Analog pin A4
Clk -> SCL or Analog pin A5
RST -> Digital pin 4 (you can change this pin in the code)
1c) Waveshare white 0.96" I2C SPI OLED display module
In its factory settings, BS0/BS1 pins are set to 0/0 and 4-wire SPI is selected as default. See picure below:
You need to change hardware configuration on the back (resolder the resistor - BS0/BS1 1/0)
0.96" I2C / SPI OLED display -> Arduino Uno
GND -> GND
VCC -> 3.3~5V power input
DIN -> SDA or Analog pin A4
CLK -> SCL or Analog pin A5
RST -> Digital pin 4 (you can change this pin in the code)
CS -> GND
D/C ->GND
2. SPI interface (3 wire/4 wire)
2a) Adafruit white 0.96" I2C SPI OLED display module
The breakouts are ready for SPI by default, but if you used them for I2C at some point, you'll need to remove the solder jumpers. Use wick or a solder sucker to make sure both are clear!
0.96" I2C / SPI OLED display -> Arduino Uno
GND -> GND
Vin -> 5V
Data -> Digital pin 9
Clk -> Digital pin 10
DC (D/C)-> Digital pin 11
Rst -> Digital pin 13
CS -> Digital pin 12
(Note: If using the display with other SPI devices, DC, CLK and Data may be shared, but CS must be unique for each device.)
2b) Waveshare white 0.96" I2C SPI OLED display module
4 WIRE SPI hardware configuration.In its factory settings, BS0/BS1 pins are set to 0/0 and 4-wire SPI is selected as default. See picure below:
0.96" I2C / SPI OLED display -> Arduino Uno
GND -> GND
VCC -> 3.3~5V power input
CS -> Digital pin 12
D/C -> Digital pin 11
Rst -> Digital pin 13
DIN -> (MOSI) Digital pin 9
CLK-> (SCLK) Digital pin 10
3 WIRE SPI hardware configuration. You need to change hardware configuration on the back (resolder the resistor - BS0/BS1 - 0/1).
0.96" I2C / SPI OLED display -> Arduino Uno
GND -> GND
VCC -> 3.3~5V power input
CS -> Digital pin 12
D/C -> GND
Rst -> Digital pin 13
DIN -> (MOSI) Digital pin 9
CLK-> (SCLK) Digital pin 10
Step by Step instruction
- Do wiring.
- Open Arduino IDE.
- Plug your Adruino Uno board into your PC and select the correct board and com port
- Find your I2C address. Each device has an I2C address that it uses to accept commands or send messages. Load the sketch over at http://playground.arduino.cc/Main/I2cScanner and follow the instructions to use it. By opening up the Serial monitor window after you upload the sketch, Arduino will scan the address range looking for a reply. The scanner can detect it (0x78, 0x7A,0x3C,0x3D) (for example, in our case 0x3C)
- Modify the bold part in the line display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
- Verify and upload the sketch to your Adruino Uno.
- The example program starts by showing the Adafruit logo, it then turns on a single pixel. Various graphics and text functions are then displayed.
Summary
We learnt how to connect 0.96" I2C OLED display module to Arduino board and use it.
You can create bitmaps to display easily with the LCD assistant software. First make your image using any kind of graphics software such as photoshop or Paint and save as a Monochrome Bitmap (bmp)
Select the following options (You might also want to try Horizontal if Vertical is not coming out right)
and import your monochrome bitmap image. Save the output to a cpp file
You can use the output directly with our example code
Code
The library cannot determine the screen size via software. You have to specify it in the header file. Go into the library folder and open the file Adafruit_SSD1306.h. Toward the top you'll see a section of comments that tell how how to edit the file for different kinds of display.
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. If you have SSD1306 128x64 display - comment out #define SSD1306_128_32 and uncomment #define SSD1306_128_64
1.OLEDtext sketch
After initializing the display, the OLEDtext sketch then draws a pixel at each extreme of the display by using drawPixel() to place a pixel in each corner of the screen. The first parameter passed to drawPixel() is the screen X coordinate and the second parameter is the screen Y coordinate. Screen dimensions are 128 by 64 pixels and pixel coordinates start at 0, 0 for the top left pixel. This means that the X coordinates for the screen are from 0 to 127 (not 1 to 128) left to right; and Y coordinates are from 0 to 63 (not 1 to 64) top to bottom. As can be seen in the sketch and on the display, the corner pixels are at the following coordinates:
- Top left pixel – x = 0, y = 0.
- Top right pixel – x = 127, y = 0.
- Bottom left pixel – x = 0, y = 63.
- Bottom right pixel – x = 127, y = 63.
Use print() to write a line of text to the display as shown in the above sketch. Before writing text to the display, call setTextSize() and setTextColor(). Because this is a monochrome display, setTextColor() must be passed WHITE for the text to be seen on a black background. Text that is written to the display is positioned by calling setCursor() to move the invisible cursor to the desired position. X and Y coordinates are passed to setCursor() to move the cursor and start of text to these pixel coordinates.
All text and graphics are written to buffer memory in the Arduino. Only when display() (display.display() in the above code) is called is the contents of the buffer displayed on the screen. This means that any text and graphical objects such as lines and circles will not appear on the screen until display() is called.
Adafruit_SSD1306 display(-1);
The number passed to the the Adafruit_SSD1306 constructor as shown in the above code is the number of the Arduino pin used to reset the display for displays that have a reset pin. As the display used in this tutorial does not have a reset pin, -1 is passed to the constructor so that none of the Arduino pins are used as a reset for the display.
If the display() function is called without first calling clearDisplay() as shown in the following code, the Adafruit logo appears on the screen. Where does this logo come from?
void setup() {
display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR);
display.display();
}
Memory used for the screen buffer is initialized with the Adafruit logo in the Adafruit_SSD1306 driver library. This code is found in the Adafruit_SSD1306.cpp file in the Arduino libraries folder at libraries → Adafruit_SSD1306. The logo consists of hexadecimal code used to initialize the buffer[] array near the top of the Adafruit_SSD1306.cpp file.
Calling clearDisplay() clears the logo from memory allowing new text and graphics to be written to the buffer.
2.U8glibexmplessketch
Uncomment the correct display module driver (you hve SSD1306), the rest of drivers should be commented in the sketch. You can also see the number of pixels (for example 128x64) and configuration of pins for I2C/SPT.
Library
- All libraries attached on the begining of the project description
- Adafruit_SSD1306 library. Download, unzip and add to libraries in our PC, for example C:\Users\toshiba\Documents\Arduino\libraries. This link you can find in Preferences of Adruino IDE program which installed in your PC. You can read about it here.The SSD1306 driver library is used to initialize the display and provide low level display functions.
- Adafruit_GFX library. Download, unzip and add to libraries in our PC, for example C:\Users\toshiba\Documents\Arduino\libraries. This link you can find in Preferences of Adruino IDE program which installed in your PC. You can read about it here.The GFX library provides graphics functions for displaying text, drawing lines and circles, etc.
- u8glib library. Download, unzip and add to libraries in our PC, for example C:\Users\toshiba\Documents\Arduino\libraries. This link you can find in Preferences of Adruino IDE program which installed in your PC. You can read about it here.This library supports the parallel and SPI mode but is not maintained anymore. We attached quite a lot examples in this project with this library. You need to setup u8g object if you will use different controller just replace U8GLIB_SSD1306_128X64 in each sketch with your constructor call. The complete list of supported devices with all constructor calls is here. You can check for you constructor in EXAMPLES directory of U8GLIB library.
- Wire library included in Arduino IDE.
- SPI library included in Arduino IDE.
Sketch
- See attachments on the begining of this project
Other projects of Lex C.










jobs.viewed