{"id":13085,"date":"2017-02-01T19:45:08","date_gmt":"2017-02-02T00:45:08","guid":{"rendered":"http:\/\/embedded-lab.com\/blog\/?p=13085"},"modified":"2023-04-11T22:18:16","modified_gmt":"2023-04-12T02:18:16","slug":"tutorial-3-connecting-oled-display-esp8266","status":"publish","type":"post","link":"https:\/\/embedded-lab.com\/blog\/tutorial-3-connecting-oled-display-esp8266\/","title":{"rendered":"Tutorial 3: Connecting an OLED display to ESP8266"},"content":{"rendered":"<p>Whether you want to show sensor readings, implement a navigational user interface menu, or display diagnostic information during prototyping a\u00a0project, a graphic OLED display is always a cool add-on to embedded systems. In this tutorial, we will learn how to interface an I2C monochromatic OLED screen to ESP8266 (we will use EasyESP-1 board) using Arduino IDE. The OLED display used in this tutorial is\u00a0SSD1306-based that can be bought for ~$5 on eBay or Aliexpress. You can also get a similar I2C OLED display with a\u00a0grove connector from <strong><a href=\"https:\/\/www.elecrow.com\/crowtail-222\/crowtail-oled-p-1276.html\" target=\"_blank\" rel=\"noopener noreferrer\">Elecrow<\/a><\/strong> for plug-and-play interfacing with the EasyESP-1 board.<\/p>\n<div id=\"attachment_13087\" style=\"width: 797px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/01\/Featured.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-13087\" class=\"size-full wp-image-13087\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/01\/Featured.jpg\" alt=\"Interfacing an SSD1306-based I2C OLED to EasyESP-1\" width=\"787\" height=\"526\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/01\/Featured.jpg 787w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/01\/Featured-580x388.jpg 580w\" sizes=\"auto, (max-width: 787px) 100vw, 787px\" \/><\/a><p id=\"caption-attachment-13087\" class=\"wp-caption-text\">Interfacing an SSD1306-based I2C OLED to EasyESP-1<\/p><\/div>\n<h3><a href=\"https:\/\/www.elecrow.com\/cde82664e.html\" target=\"_blank\" rel=\"noopener noreferrer\">Buy EasyESP-1 board<\/a><\/h3>\n<h3>Hardware Setup<\/h3>\n<p>The I2C OLED breakout board chosen for this\u00a0tutorial consists of\u00a0a 0.96&#8243; diagonal length display with 128&#215;64 monochrome pixels. Despite its small size, the readability is pretty good due to its high contrast. Individual pixels are\u00a0turned on or off by the on-board SSD1306 controller chip that supports both SPI and I2C interface. This tutorial uses an OLED display\u00a0with I2C interface and has only four signal lines, namely VCC, GND, SCL, and SDA. For this experiment, these pins are connected to 3.3V, GND, D1, and D2 pins on the EasyESP-1 board, respectively.<\/p>\n<div id=\"attachment_13090\" style=\"width: 687px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/01\/OLED.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-13090\" class=\"size-full wp-image-13090\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/01\/OLED.jpg\" alt=\"SSD1306 based 0.96&quot; OLED display module\" width=\"677\" height=\"520\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/01\/OLED.jpg 677w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/01\/OLED-580x445.jpg 580w\" sizes=\"auto, (max-width: 677px) 100vw, 677px\" \/><\/a><p id=\"caption-attachment-13090\" class=\"wp-caption-text\">SSD1306 based 0.96&#8243; OLED display module<\/p><\/div>\n<div id=\"attachment_13089\" style=\"width: 810px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/01\/setup.jpeg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-13089\" class=\"size-full wp-image-13089\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/01\/setup.jpeg\" alt=\"Wiring OLED pins to the EasyESP-1 board\" width=\"800\" height=\"816\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/01\/setup.jpeg 800w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/01\/setup-580x592.jpeg 580w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/a><p id=\"caption-attachment-13089\" class=\"wp-caption-text\">Wiring OLED pins to the EasyESP-1 board<\/p><\/div>\n<p>If you would like to use a grove OLED module, it can be connected to one of the I2C port on the EasyESP-1 board, as shown below.<\/p>\n<div id=\"attachment_13086\" style=\"width: 810px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/01\/P_20170131_162259.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-13086\" class=\"size-full wp-image-13086\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/01\/P_20170131_162259.jpg\" alt=\"Connecting a grove OLED\" width=\"800\" height=\"604\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/01\/P_20170131_162259.jpg 800w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/01\/P_20170131_162259-580x438.jpg 580w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/a><p id=\"caption-attachment-13086\" class=\"wp-caption-text\">Connecting a grove OLED to I2C connector on the EasyESP-1 board<\/p><\/div>\n<h3>Software<\/h3>\n<p>There are several libraries available to support the SSD1036-based OLEDs for Arduino platform. For ESP8266, I would suggest to use one written by\u00a0<em>Daniel Eichhorn<\/em> from <strong><a href=\"https:\/\/blog.squix.org\/\" target=\"_blank\" rel=\"noopener noreferrer\">squix<\/a><\/strong>. It supports both I2C and SPI versions of SSD1306 based 128&#215;64 pixel OLED displays on the Arduino\/ESP8266 platform. The library is very versatile and supports drawing pixels, lines, rectangles, and text of different font sizes. You can download this from the following github link.<\/p>\n<p><a href=\"https:\/\/github.com\/squix78\/esp8266-oled-ssd1306\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/github.com\/squix78\/esp8266-oled-ssd1306<\/a><\/p>\n<p>Installation and setup of an external user library to Arduino IDE is easy. First, download the <strong><a href=\"https:\/\/github.com\/squix78\/esp8266-oled-ssd1306\/archive\/master.zip\" target=\"_blank\" rel=\"noopener noreferrer\">zipped library folder<\/a><\/strong> to your machine. Then unzip it and move the unzipped library folder to your <em><strong>Documents\/Arduino\/libraries\/<\/strong><\/em> location. You need to restart the Arduino IDE in order to use it in your new application.<\/p>\n<p>After installing the OLED library, it&#8217;s time to try some built-in examples that come with the library. Open\u00a0<strong>File-&gt;Examples-&gt;ESP8266 Oled Driver for SSD1306 display-&gt; SSD1306SimpleDemo<\/strong>.<\/p>\n<div id=\"attachment_13104\" style=\"width: 802px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/02\/example.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-13104\" class=\"wp-image-13104 size-full\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/02\/example.jpg\" alt=\"fgf\" width=\"792\" height=\"1083\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/02\/example.jpg 792w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/02\/example-475x650.jpg 475w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/02\/example-749x1024.jpg 749w\" sizes=\"auto, (max-width: 792px) 100vw, 792px\" \/><\/a><p id=\"caption-attachment-13104\" class=\"wp-caption-text\">Testing OLED examples<\/p><\/div>\n<p>The example programs are configured for I2C version of SSD1306 OLED by default. So, the only thing that you need to modify in the example code is to assign the correct ESP8266 I\/O pins for I2C communication. Note that the EasyESP-1 I2C ports use D2 for SDA and D1 for SCL. So find the following I2C initialization statement in the code and make the changes as<\/p>\n<p>\/\/ Initialize the OLED display using Wire library<br \/>\nSSD1306 display(0x3c, D2, D1);<\/p>\n<p>Next, compile the program and upload it to the EasyESP-1 board.<\/p>\n<h3>Output<\/h3>\n<p>The <strong>SSD1306SimpleDemo<\/strong>\u00a0example cycles through all the basic features of the OLED library, like drawing pixels, rectangle, circles, texts, WiFi logo, etc.<\/p>\n<div id=\"attachment_13088\" style=\"width: 810px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/01\/output1.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-13088\" class=\"size-full wp-image-13088\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/01\/output1.jpg\" alt=\"Drawing concentric circles\" width=\"800\" height=\"726\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/01\/output1.jpg 800w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/01\/output1-580x526.jpg 580w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/a><p id=\"caption-attachment-13088\" class=\"wp-caption-text\">Drawing concentric circles<\/p><\/div>\n<div id=\"attachment_13099\" style=\"width: 810px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/01\/P_20170131_162058.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-13099\" class=\"size-full wp-image-13099\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/01\/P_20170131_162058.jpg\" alt=\"OLED text output\" width=\"800\" height=\"594\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/01\/P_20170131_162058.jpg 800w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/01\/P_20170131_162058-580x431.jpg 580w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/a><p id=\"caption-attachment-13099\" class=\"wp-caption-text\">OLED text output<\/p><\/div>\n<p>You can also try running other examples in<em>\u00a0Daniel&#8217;s<\/em>\u00a0OLED library. There is one called SSD1306ClockDemo that displays an analog and digital clock on the LED screen. For this example, you will need to install the\u00a0<strong><a href=\"https:\/\/github.com\/PaulStoffregen\/Time\/archive\/master.zip\" target=\"_blank\" rel=\"noopener noreferrer\">Arduino Time library<\/a><\/strong>.<\/p>\n<div id=\"attachment_13106\" style=\"width: 810px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/02\/clock.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-13106\" class=\"size-full wp-image-13106\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/02\/clock.jpg\" alt=\"Clock example\" width=\"800\" height=\"685\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/02\/clock.jpg 800w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/02\/clock-580x497.jpg 580w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/a><p id=\"caption-attachment-13106\" class=\"wp-caption-text\">Clock example<\/p><\/div>\n<h3><a href=\"https:\/\/www.elecrow.com\/cde82664e.html\" target=\"_blank\" rel=\"noopener noreferrer\">Buy EasyESP-1 board<\/a><\/h3>\n<h4>More tutorials<\/h4>\n<h5 class=\"post-title\"><a href=\"http:\/\/embedded-lab.com\/blog\/tutorial-2-easyesp-1-hello-world-example\/\" target=\"_blank\" rel=\"noopener noreferrer\">TUTORIAL 2: EASYESP-1 \u201cHELLO WORLD\u201d EXAMPLE<\/a><\/h5>\n<h5 class=\"post-title\"><a href=\"http:\/\/embedded-lab.com\/blog\/tutorial-1-setting-arduino-ide-easyesp-1\/\" target=\"_blank\" rel=\"noopener noreferrer\">TUTORIAL 1: SETTING UP THE ARDUINO IDE FOR EASYESP-1<\/a><\/h5>\n<h5 class=\"post-title\"><a href=\"http:\/\/embedded-lab.com\/blog\/easyesp-1-rapid-prototyping-development-board-esp8266\/\" target=\"_blank\" rel=\"noopener noreferrer\">EASYESP-1: A RAPID PROTOTYPING AND DEVELOPMENT BOARD FOR ESP8266<\/a><\/h5>\n","protected":false},"excerpt":{"rendered":"<p>Whether you want to show sensor readings, implement a navigational user interface menu, or display diagnostic information during prototyping a\u00a0project, a graphic OLED display is always a cool add-on to embedded systems. In this tutorial, we will learn how to interface an I2C monochromatic OLED screen to ESP8266 (we will use EasyESP-1 board) using Arduino IDE. The OLED display used in this tutorial is\u00a0SSD1306-based that can be bought for ~$5 on eBay or Aliexpress. You can also get a similar I2C OLED display with a\u00a0grove connector from Elecrow for plug-and-play interfacing with the EasyESP-1 board. Buy EasyESP-1 board Hardware Setup<\/p>\n","protected":false},"author":1,"featured_media":13087,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1603,1044,1464,1466],"tags":[1512,1618],"class_list":["post-13085","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-esp8266-tutorials","category-esp8266","category-featured","category-tutorials","tag-arduino-oled","tag-esp8266-i2c-oled"],"_links":{"self":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/13085","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/comments?post=13085"}],"version-history":[{"count":16,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/13085\/revisions"}],"predecessor-version":[{"id":15142,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/13085\/revisions\/15142"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/media\/13087"}],"wp:attachment":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/media?parent=13085"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/categories?post=13085"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/tags?post=13085"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}