0 96 Zoll I2c Oled Display Arduino
0 96 Zoll I2c Oled Display Arduino
This guide shows how to utilize the 0.96 inch SSD1306 OLED display with ESP8266 using Arduino IDE. We'll evidence you how to write text, prepare different fonts, draw shapes and display bitmaps images.
Nosotros also have a dedicated guide that shows how to display temperature and humidity readings using DHT sensor and ESP8266.
Introducing 0.96 inch OLED Brandish
The OLED brandish that nosotros'll apply in this tutorial is the SSD1306 model: a monocolor, 0.96 inch display with 128×64 pixels as shown in the following effigy.
The OLED brandish doesn't require backlight, which results in a very overnice contrast in nighttime environments. Additionally, its pixels swallow energy simply when they are on, and so the OLED display consumes less power when compared to other displays.
The model we're using has four pins and communicates with whatever microcontroller using I2C communication protocol. At that place are models that come with an extra RESET pin or that communicate using SPI advice protocol.
OLED Display SSD1306 Pin Wiring
Considering the OLED display uses I2C communication protocol, wiring is very simple. You tin utilise the following table equally a reference.
Pin | ESP8266 |
Vin | 3.3V |
GND | GND |
SCL | GPIO 5 (D1) |
SDA | GPIO iv (D2) |
Alternatively, you lot can follow the next schematic diagram to wire the ESP8266 to the OLED display.
In this case, we're using I2C communication protocol. The nearly suitable pins for I2C advice in the ESP8266 are GPIO 5 (SCL) and GPIO four (SDA).
If you're using an OLED brandish with SPI communication protocol, utilize the post-obit GPIOs.
- GPIO 14: CLK
- GPIO 12: MISO
- GPIO 13: MOSI
- GPIO 15: CS
Read our ESP8266 Pinout Reference Guide to learn more well-nigh the ESP8266 GPIOs.
Installing SSD1306 OLED Library – ESP8266
In that location are several libraries bachelor to command the OLED display with the ESP8266. In this tutorial nosotros'll utilise two Adafruit libraries: Adafruit_SSD1306 library and Adafruit_GFX library.
Follow the side by side steps to install those libraries.
i. Open up your Arduino IDE and get toSketch>Include Library >Manage Libraries. The Library Manager should open.
2. Type "SSD1306" in the search box and install the SSD1306 library from Adafruit.
3. Subsequently installing the SSD1306 library from Adafruit, blazon "GFX" in the search box and install the library.
4. Afterwards installing the libraries, restart your Arduino IDE.
We'll program the ESP8266 using Arduino IDE, so yous must accept the ESP8266 add-on installed in your Arduino IDE. If yous haven't, follow the side by side tutorial starting time:
Testing OLED Display with ESP8266
After wiring the OLED display to the ESP8266 and installing all required libraries, you lot tin can use one example from the library to see if everything is working properly.
In your Arduino IDE, become to File > Examples > Adafruit SSD1306 and select the example for the display you lot're using.
The following code should load:
/********* Complete projection details at https://randomnerdtutorials.com This is an example for our Monochrome OLEDs based on SSD1306 drivers. Option one upward today in the adafruit shop! ------> http://www.adafruit.com/category/63_98 This instance is for a 128x32 pixel brandish using I2C to communicate 3 pins are required to interface (two I2C and 1 reset). Adafruit invests fourth dimension and resources providing this open source code, delight support Adafruit and open up-source hardware by purchasing products from Adafruit! Written past Limor Fried/Ladyada for Adafruit Industries, with contributions from the open source community. BSD license, bank check license.txt for more than data All text above, and the splash screen below must exist included in any redistribution. *********/ #include <SPI.h> #include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> #define SCREEN_WIDTH 128 // OLED display width, in pixels #define SCREEN_HEIGHT 64 // OLED brandish height, in pixels // Declaration for an SSD1306 display continued to I2C (SDA, SCL pins) #ascertain OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin) Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); #define NUMFLAKES 10 // Number of snowflakes in the animation example #define LOGO_HEIGHT 16 #define LOGO_WIDTH xvi static const unsigned char PROGMEM logo_bmp[] = { B00000000, B11000000, B00000001, B11000000, B00000001, B11000000, B00000011, B11100000, B11110011, B11100000, B11111110, B11111000, B01111110, B11111111, B00110011, B10011111, B00011111, B11111100, B00001101, B01110000, B00011011, B10100000, B00111111, B11100000, B00111111, B11110000, B01111100, B11110000, B01110000, B01110000, B00000000, B00110000 }; void setup() { Serial.begin(115200); // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { Series.println(F("SSD1306 allocation failed")); for(;;); // Don't go on, loop forever } // Show initial brandish buffer contents on the screen -- // the library initializes this with an Adafruit splash screen. display.brandish(); delay(2000); // Pause for 2 seconds // Articulate the buffer display.clearDisplay(); // Draw a single pixel in white display.drawPixel(ten, ten, WHITE); // Prove the display buffer on the screen. You MUST call display() after // cartoon commands to make them visible on screen! display.brandish(); delay(2000); // display.display() is NOT necessary after every single cartoon command, // unless that'south what you want...rather, you tin can batch upwards a bunch of // cartoon operations and then update the screen all at one time past calling // brandish.display(). These examples demonstrate both approaches... testdrawline(); // Draw many lines testdrawrect(); // Draw rectangles (outlines) testfillrect(); // Draw rectangles (filled) testdrawcircle(); // Depict circles (outlines) testfillcircle(); // Draw circles (filled) testdrawroundrect(); // Draw rounded rectangles (outlines) testfillroundrect(); // Describe rounded rectangles (filled) testdrawtriangle(); // Draw triangles (outlines) testfilltriangle(); // Depict triangles (filled) testdrawchar(); // Draw characters of the default font testdrawstyles(); // Draw 'stylized' characters testscrolltext(); // Draw scrolling text testdrawbitmap(); // Draw a minor bitmap epitome // Invert and restore display, pausing in-between display.invertDisplay(true); delay(1000); display.invertDisplay(false); filibuster(g); testanimate(logo_bmp, LOGO_WIDTH, LOGO_HEIGHT); // Animate bitmaps } void loop() { } void testdrawline() { int16_t i; brandish.clearDisplay(); // Clear brandish buffer for(i=0; i<display.width(); i+=4) { display.drawLine(0, 0, i, brandish.height()-ane, WHITE); display.display(); // Update screen with each newly-drawn line delay(1); } for(i=0; i<brandish.height(); i+=4) { display.drawLine(0, 0, display.width()-one, i, WHITE); display.brandish(); delay(1); } delay(250); brandish.clearDisplay(); for(i=0; i<display.width(); i+=4) { display.drawLine(0, brandish.height()-1, i, 0, WHITE); display.display(); delay(one); } for(i=brandish.height()-1; i>=0; i-=4) { display.drawLine(0, display.height()-ane, display.width()-1, i, WHITE); brandish.display(); delay(1); } filibuster(250); display.clearDisplay(); for(i=brandish.width()-ane; i>=0; i-=4) { brandish.drawLine(display.width()-1, display.height()-1, i, 0, WHITE); display.display(); delay(1); } for(i=display.pinnacle()-one; i>=0; i-=iv) { brandish.drawLine(display.width()-1, display.height()-1, 0, i, WHITE); brandish.display(); delay(1); } filibuster(250); display.clearDisplay(); for(i=0; i<display.height(); i+=4) { display.drawLine(display.width()-1, 0, 0, i, WHITE); display.display(); delay(1); } for(i=0; i<brandish.width(); i+=four) { display.drawLine(display.width()-ane, 0, i, display.height()-1, WHITE); display.display(); filibuster(1); } delay(2000); // Pause for 2 seconds } void testdrawrect(void) { display.clearDisplay(); for(int16_t i=0; i<display.height()/2; i+=2) { display.drawRect(i, i, display.width()-2*i, brandish.top()-two*i, WHITE); display.display(); // Update screen with each newly-drawn rectangle delay(1); } filibuster(2000); } void testfillrect(void) { display.clearDisplay(); for(int16_t i=0; i<display.superlative()/2; i+=three) { // The Inverse colour is used so rectangles alternating white/black display.fillRect(i, i, display.width()-i*2, brandish.meridian()-i*2, INVERSE); brandish.brandish(); // Update screen with each newly-drawn rectangle filibuster(one); } delay(2000); } void testdrawcircle(void) { display.clearDisplay(); for(int16_t i=0; i<max(display.width(),display.superlative())/2; i+=2) { display.drawCircle(brandish.width()/two, display.tiptop()/two, i, WHITE); display.display(); delay(one); } delay(2000); } void testfillcircle(void) { display.clearDisplay(); for(int16_t i=max(display.width(),brandish.height())/2; i>0; i-=3) { // The Changed color is used and so circles alternate white/black display.fillCircle(brandish.width() / 2, display.height() / 2, i, INVERSE); display.display(); // Update screen with each newly-drawn circle delay(1); } delay(2000); } void testdrawroundrect(void) { display.clearDisplay(); for(int16_t i=0; i<display.top()/ii-2; i+=two) { display.drawRoundRect(i, i, brandish.width()-2*i, display.pinnacle()-2*i, display.height()/4, WHITE); display.brandish(); filibuster(ane); } delay(2000); } void testfillroundrect(void) { brandish.clearDisplay(); for(int16_t i=0; i<brandish.pinnacle()/2-2; i+=two) { // The INVERSE color is used so round-rects alternating white/blackness display.fillRoundRect(i, i, display.width()-ii*i, display.top()-2*i, brandish.height()/4, Inverse); display.display(); delay(i); } delay(2000); } void testdrawtriangle(void) { display.clearDisplay(); for(int16_t i=0; i<max(brandish.width(),display.height())/2; i+=5) { display.drawTriangle( display.width()/2 , display.peak()/two-i, display.width()/2-i, display.height()/2+i, display.width()/2+i, display.height()/two+i, WHITE); display.display(); delay(ane); } filibuster(2000); } void testfilltriangle(void) { display.clearDisplay(); for(int16_t i=max(brandish.width(),display.height())/two; i>0; i-=v) { // The INVERSE color is used then triangles alternate white/black display.fillTriangle( display.width()/two , brandish.height()/2-i, display.width()/2-i, brandish.height()/2+i, display.width()/2+i, brandish.pinnacle()/2+i, INVERSE); display.brandish(); delay(i); } delay(2000); } void testdrawchar(void) { display.clearDisplay(); display.setTextSize(i); // Normal 1:ane pixel scale display.setTextColor(WHITE); // Draw white text brandish.setCursor(0, 0); // Start at top-left corner brandish.cp437(true); // Utilize full 256 char 'Code Page 437' font // Not all the characters volition fit on the display. This is normal. // Library will draw what it can and the rest will be clipped. for(int16_t i=0; i<256; i++) { if(i == '\n') display.write(' '); else display.write(i); } display.brandish(); filibuster(2000); } void testdrawstyles(void) { display.clearDisplay(); brandish.setTextSize(one); // Normal i:ane pixel scale display.setTextColor(WHITE); // Draw white text display.setCursor(0,0); // Beginning at top-left corner display.println(F("Hello, world!")); display.setTextColor(BLACK, WHITE); // Draw 'changed' text display.println(three.141592); display.setTextSize(2); // Draw 2X-scale text display.setTextColor(WHITE); display.print(F("0x")); brandish.println(0xDEADBEEF, HEX); display.brandish(); delay(2000); } void testscrolltext(void) { display.clearDisplay(); display.setTextSize(ii); // Draw 2X-calibration text display.setTextColor(WHITE); display.setCursor(x, 0); display.println(F("scroll")); brandish.display(); // Evidence initial text delay(100); // Scroll in various directions, pausing in-betwixt: display.startscrollright(0x00, 0x0F); filibuster(2000); brandish.stopscroll(); delay(g); brandish.startscrollleft(0x00, 0x0F); filibuster(2000); display.stopscroll(); delay(1000); brandish.startscrolldiagright(0x00, 0x07); delay(2000); display.startscrolldiagleft(0x00, 0x07); delay(2000); display.stopscroll(); delay(1000); } void testdrawbitmap(void) { display.clearDisplay(); display.drawBitmap( (display.width() - LOGO_WIDTH ) / two, (display.height() - LOGO_HEIGHT) / 2, logo_bmp, LOGO_WIDTH, LOGO_HEIGHT, one); display.display(); delay(1000); } #define XPOS 0 // Indexes into the 'icons' array in function below #ascertain YPOS one #ascertain DELTAY 2 void testanimate(const uint8_t *bitmap, uint8_t w, uint8_t h) { int8_t f, icons[NUMFLAKES][3]; // Initialize 'snowflake' positions for(f=0; f< NUMFLAKES; f++) { icons[f][XPOS] = random(1 - LOGO_WIDTH, display.width()); icons[f][YPOS] = -LOGO_HEIGHT; icons[f][DELTAY] = random(ane, half dozen); Serial.print(F("x: ")); Serial.print(icons[f][XPOS], DEC); Serial.print(F(" y: ")); Serial.print(icons[f][YPOS], Dec); Series.impress(F(" dy: ")); Serial.println(icons[f][DELTAY], DEC); } for(;;) { // Loop forever... brandish.clearDisplay(); // Clear the display buffer // Draw each snowflake: for(f=0; f< NUMFLAKES; f++) { display.drawBitmap(icons[f][XPOS], icons[f][YPOS], bitmap, west, h, WHITE); } display.display(); // Show the display buffer on the screen filibuster(200); // Suspension for one/10 2nd // And then update coordinates of each scrap... for(f=0; f< NUMFLAKES; f++) { icons[f][YPOS] += icons[f][DELTAY]; // If snowflake is off the lesser of the screen... if (icons[f][YPOS] >= display.tiptop()) { // Reinitialize to a random position, just off the top icons[f][XPOS] = random(i - LOGO_WIDTH, display.width()); icons[f][YPOS] = -LOGO_HEIGHT; icons[f][DELTAY] = random(1, half dozen); } } } }
If your OLED doesn't accept a RESET pivot, you should set the OLED_RESET variable to -i as shown beneath:
#define OLED_RESET -ane // Reset pivot # (or -i if sharing Arduino reset pivot)
Note: if your OLED has a RESET pin, you should connect it to a different GPIO than GPIO 4, because that pivot is beingness used for I2C advice in the EPS8266.
Upload the code to your ESP8266 board. Don't forget to select the correct board and COM port in the Tools carte du jour.
You should get a series of unlike animations in the OLED as shown in the following short video.
If your OLED display is not showing anything:
- Check that the OLED display is properly wired to the ESP8266
- Double-check the OLED display I2C address: with the OLED connected to the ESP8266, upload this code and bank check the I2C accost in the Serial Monitor
You should change the OLED accost in the following line, if necessary. In our case, the accost is 0x3C.
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Write Text – OLED Display
The Adafruit library for the OLED display comes with several functions to write text. In this department, you lot'll learn how to write and scroll text using the library functions.
"Hello, world!" OLED Display
The following sketch displays Howdy, world! bulletin in the OLED display.
/********* Rui Santos Consummate project details at https://randomnerdtutorials.com *********/ #include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> #define SCREEN_WIDTH 128 // OLED display width, in pixels #define SCREEN_HEIGHT 64 // OLED display acme, in pixels // Announcement for an SSD1306 brandish connected to I2C (SDA, SCL pins) Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -i); void setup() { Serial.begin(115200); if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64 Series.println(F("SSD1306 allocation failed")); for(;;); } filibuster(2000); display.clearDisplay(); display.setTextSize(1); display.setTextColor(WHITE); display.setCursor(0, 10); // Display static text display.println("Hello, world!"); brandish.display(); } void loop() { }
After uploading the lawmaking, this is what you lot'll get in your OLED:
Permit'south accept a quick await on how the code works.
Importing libraries
Get-go, you need to import the necessary libraries. The Wire library to use I2C and the Adafruit libraries to write to the display: Adafruit_GFX and Adafruit_SSD1306.
#include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h>
Initialize the OLED display
Then, you lot define your OLED width and superlative. In this case, we're using a 128×64 OLED brandish. If you're using other sizes, you lot can change that in the SCREEN_WIDTH, and SCREEN_HEIGHT variables.
#define SCREEN_WIDTH 128 // OLED brandish width, in pixels #define SCREEN_HEIGHT 64 // OLED display height, in pixels
And then, initialize a display object with the width and top divers earlier with I2C communication protocol (&Wire).
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
The (-one) parameter ways that your OLED display doesn't have a RESET pin. If your OLED brandish does have a RESET pivot, it should be connected to a GPIO. In that case, you should pass the GPIO number as a parameter.
In the setup(), initialize the Serial Monitor at a baud raute of 115200 for debugging purposes.
Serial.begin(115200);
Initialize the OLED display with the begin() method equally follows:
if(!brandish.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { Serial.println("SSD1306 allocation failed"); for(;;); // Don't proceed, loop forever }
This snippet as well prints a bulletin on the Series Monitor, in example nosotros're not able to connect to the display.
Serial.println("SSD1306 resource allotment failed");
In instance you lot're using a different OLED display, you may demand to change the OLED address. In our case, the address is 0x3C.
if(!display.brainstorm(SSD1306_SWITCHCAPVCC, 0x3C)) {
If this address doesn't piece of work, you can run an I2C scanner sketch to discover your OLED address. You tin can detect the I2C scanner sketch hither.
After initializing the display, add a two 2d filibuster, so that the OLED has plenty time to initialize before writing text:
delay(2000);
Clear brandish, set font size, color and write text
After initializing the display, clear the display buffer with the clearDisplay() method:
display.clearDisplay();
Before writing text, you need to set the text size, colour and where the text will exist displayed in the OLED.
Set up the font size using the setTextSize() method:
display.setTextSize(i);
Set the font color with the setTextColor() method:
display.setTextColor(WHITE);
WHITE sets white font and black background.
Define the position where the text starts using the setCursor(x,y) method. In this case, we're setting the text to outset at the (0,10) coordinates.
display.setCursor(0,10);
Finally, y'all can send the text to the display using the println() method, equally follows:
display.println("How-do-you-do, earth!");
Then, you lot need to phone call the brandish() method to really display the text on the screen.
display.display();
Scrolling Text
The Adafruit OLED library provides useful methods to easily scroll text.
- startscrollright(0x00, 0x0F): scroll text from left to right
- startscrollleft(0x00, 0x0F): roll text from right to left
- startscrolldiagright(0x00, 0x07): scroll text from left bottom corner to right upper corner
- startscrolldiagleft(0x00, 0x07): curlicue text from right bottom corner to left upper corner
The following sketch implements those methods.
/********* Rui Santos Complete projection details at https://randomnerdtutorials.com *********/ #include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> #ascertain SCREEN_WIDTH 128 // OLED display width, in pixels #ascertain SCREEN_HEIGHT 64 // OLED display tiptop, in pixels // Declaration for an SSD1306 display connected to I2C (SDA, SCL pins) Adafruit_SSD1306 brandish(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1); void setup() { Serial.brainstorm(115200); if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64 Serial.println(F("SSD1306 allocation failed")); for(;;); } delay(2000); display.clearDisplay(); display.setTextSize(1); display.setTextColor(WHITE); display.setCursor(0, 0); // Display static text display.println("Scrolling Hello"); display.brandish(); delay(100); } void loop() { // Coil in various directions, pausing in-betwixt: display.startscrollright(0x00, 0x0F); filibuster(2000); brandish.stopscroll(); delay(1000); display.startscrollleft(0x00, 0x0F); delay(2000); display.stopscroll(); delay(1000); display.startscrolldiagright(0x00, 0x07); delay(2000); brandish.startscrolldiagleft(0x00, 0x07); delay(2000); display.stopscroll(); delay(thousand); }
The text scrolls as shown in the following short video.
Using Other Fonts – OLED Display
The Adafruit GFX library allows united states of america to use some alternate fonts also the built-in fonts. It allows you to chose betwixt Serif, Sans, and Mono. Each font is available in bold, italic and in unlike sizes.
The sizes are prepare by the bodily font. So, the setTextSize() method doesn't work with these fonts. The fonts are bachelor in 9, 12, 18 and 24 point sizes and also comprise seven-bit characters (ASCII codes) (described equally 7b in the font name).
You tin can choose from the next pick of fonts:
FreeMono12pt7b.h FreeSansBoldOblique12pt7b.h FreeMono18pt7b.h FreeSansBoldOblique18pt7b.h FreeMono24pt7b.h FreeSansBoldOblique24pt7b.h FreeMono9pt7b.h FreeSansBoldOblique9pt7b.h FreeMonoBold12pt7b.h FreeSansOblique12pt7b.h FreeMonoBold18pt7b.h FreeSansOblique18pt7b.h FreeMonoBold24pt7b.h FreeSansOblique24pt7b.h FreeMonoBold9pt7b.h FreeSansOblique9pt7b.h FreeMonoBoldOblique12pt7b.h FreeSerif12pt7b.h FreeMonoBoldOblique18pt7b.h FreeSerif18pt7b.h FreeMonoBoldOblique24pt7b.h FreeSerif24pt7b.h FreeMonoBoldOblique9pt7b.h FreeSerif9pt7b.h FreeMonoOblique12pt7b.h FreeSerifBold12pt7b.h FreeMonoOblique18pt7b.h FreeSerifBold18pt7b.h FreeMonoOblique24pt7b.h FreeSerifBold24pt7b.h FreeMonoOblique9pt7b.h FreeSerifBold9pt7b.h FreeSans12pt7b.h FreeSerifBoldItalic12pt7b.h FreeSans18pt7b.h FreeSerifBoldItalic18pt7b.h FreeSans24pt7b.h FreeSerifBoldItalic24pt7b.h FreeSans9pt7b.h FreeSerifBoldItalic9pt7b.h FreeSansBold12pt7b.h FreeSerifItalic12pt7b.h FreeSansBold18pt7b.h FreeSerifItalic18pt7b.h FreeSansBold24pt7b.h FreeSerifItalic24pt7b.h FreeSansBold9pt7b.h FreeSerifItalic9pt7b.h
The fonts that work meliorate with the OLED display are the 9 and 12 points size.
To apply 1 of those fonts, first you need to include it in your sketch, for instance:
#include <Fonts/FreeSerif12pt7b.h>
Next, you lot just need to use the setFont() method and pass as statement, the specified font:
brandish.setFont(&FreeSerif12pt7b);
Subsequently specifying the font, all methods to write text will use that font. To get dorsum to utilize the original font, you just need to call the setFont() method with no arguments:
display.setFont();
Upload the adjacent sketch to your board:
/********* Rui Santos Complete project details at https://randomnerdtutorials.com *********/ #include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> #include <Fonts/FreeSerif9pt7b.h> #define SCREEN_WIDTH 128 // OLED display width, in pixels #define SCREEN_HEIGHT 64 // OLED brandish elevation, in pixels // Declaration for an SSD1306 display continued to I2C (SDA, SCL pins) Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1); void setup() { Serial.brainstorm(115200); if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { Series.println("SSD1306 resource allotment failed"); for(;;); } filibuster(2000); display.setFont(&FreeSerif9pt7b); display.clearDisplay(); display.setTextSize(1); display.setTextColor(WHITE); display.setCursor(0,20); display.println("Hello, earth!"); display.display(); delay(2000); } void loop() { }
At present, your display prints the "Howdy, earth!" bulletin in FreeSerif font.
Describe Shapes in the OLED Display
The Adafruit OLED library provides useful methods to draw pixels, lines and shapes. Let's accept a quick look at those methods.
Draw a pixel
To draw a pixel in the OLED display, you tin can employ the drawPixel(x, y, colour) method that accepts as arguments the x and y coordinates where the pixel appears, and color. For example:
brandish.drawPixel(64, 32, WHITE);
Draw a line
Use the drawLine(x1, y1, x2, y2, color) method to create a line. The (x1, y1) coordinates indicate the showtime of the line, and the (x2, y2) coordinates indicates where the line ends. For example:
display.drawLine(0, 0, 127, twenty, WHITE);
Depict a rectangle
The drawRect(10, y, width, pinnacle, color) provides an easy fashion to draw a rectangle. The (x, y) coordinates signal the top left corner of the rectangle. Then, you need to specify the width, height and color:
display.drawRect(x, 10, fifty, 30, WHITE);
You tin can use the fillRect(ten, y, width, tiptop, colour) to draw a filled rectangle. This method accepts the same arguments as drawRect().
The library also provides methods to displays rectangles with circular corners: drawRoundRect() and fillRoundRect(). These methods take the same arguments every bit previous methods plus the radius of the corner. For example:
display.drawRoundRect(x, 10, 30, fifty, two, WHITE);
Or a filled round rectangle:
display.fillRoundRect(10, 10, 30, l, two, WHITE);
Depict a circle
To depict a circle use the drawCircle(ten, y, radius, colour) method. The (x,y) coordinates betoken the center of the circle. You should also pass the radius equally an statement. For example:
display.drawCircle(64, 32, 10, WHITE);
In the same mode, to build a filled circle, use the fillCircle() method with the same arguments:
brandish.fillCircle(64, 32, 10, WHITE);
Draw a triangle
Utilise the the drawTriangle(x1, y1, x2, y2, x3, y3, colour) method to build a triangle. This method accepts as arguments the coordinates of each corner and the color.
display.drawTriangle(ten, 10, 55, 20, 5, 40, WHITE);
Use the fillTriangle() method to draw a filled triangle.
brandish.fillTriangle(x, x, 55, 20, five, 40, WHITE);
Invert
The library provides an additional method that you can use with shapes or text: the invertDisplay() method. Pass true as statement to invert the colors of the screen or simulated to get back to the original colors.
If you call the following command later on defining the triangle:
brandish.invertDisplay(true);
You'll get an inverted triangle as follows:
Code – Depict Shapes
Upload the post-obit sketch that implements each snippet of code we've covered previously and goes through all the shapes.
/********* Rui Santos Complete projection details at https://randomnerdtutorials.com *********/ #include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> #ascertain SCREEN_WIDTH 128 #define SCREEN_HEIGHT 64 // Annunciation for an SSD1306 display connected to I2C (SDA, SCL pins) Adafruit_SSD1306 brandish(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1); void setup() { Serial.begin(115200); if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { Serial.println(F("SSD1306 allotment failed")); for(;;); } delay(2000); // Pause for 2 seconds // Clear the buffer display.clearDisplay(); // Draw a single pixel in white display.drawPixel(64, 32, WHITE); brandish.display(); delay(3000); // Draw line display.clearDisplay(); display.drawLine(0, 0, 127, xx, WHITE); display.brandish(); filibuster(3000); // Draw rectangle display.clearDisplay(); brandish.drawRect(xxx, 10, l, thirty, WHITE); brandish.display(); delay(3000); // Fill up rectangle display.fillRect(30, 10, 50, 30, WHITE); brandish.brandish(); delay(3000); // Draw round rectangle brandish.clearDisplay(); display.drawRoundRect(x, 10, 30, fifty, 2, WHITE); brandish.brandish(); delay(3000); // Make full round rectangle brandish.clearDisplay(); display.fillRoundRect(x, 10, thirty, l, 2, WHITE); display.brandish(); filibuster(3000); // Draw circle display.clearDisplay(); display.drawCircle(64, 32, x, WHITE); display.display(); delay(3000); // Make full circle display.fillCircle(64, 32, 10, WHITE); display.display(); filibuster(3000); // Draw triangle display.clearDisplay(); brandish.drawTriangle(ten, 10, 55, 20, 5, xl, WHITE); display.brandish(); delay(3000); // Fill triangle display.fillTriangle(ten, 10, 55, 20, 5, 40, WHITE); brandish.brandish(); delay(3000); // Invert and restore display, pausing in-between brandish.invertDisplay(true); delay(3000); brandish.invertDisplay(false); delay(3000); } void loop() { }
Display Bitmap Images in the OLED
You lot tin can display 128×64 bitmap monocolor images on the OLED brandish.
First, use an imaging plan to resize a photo or picture and save it equally monochrome bitmap. If yous're on a Windows PC, you can utilise Paint.
And so, use a Prototype to C Array converter to convert the paradigm into an array. I've used LCD Epitome Converter.
Run the program and showtime with a new image. Go to Epitome > Import and select the bitmap paradigm you lot've created earlier.
Go to Options > Conversion and in the Fix tab, select the post-obit options:
- Type: Monochrome, Threshold Dither
- Main Browse Direction: Acme to Bottom
- Line Scan Direction: Forward
Become to the Epitome tab and select the post-obit options:
- Split to rows
- Cake size: 8 bit
- Byte order: Picayune-Endian
Then, click OK. Finally, in the main card, become to File > Convert. A new file with .c extension should be saved. That file contains the C array for the epitome. Open up that file with a text editor, and copy the array.
In our case, this is the array that we go:
static const uint8_t image_data_Saraarray[1024] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x14, 0x9e, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x36, 0x3f, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x6d, 0xff, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0xfb, 0xff, 0x80, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x03, 0xd7, 0xff, 0x80, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x07, 0xef, 0xff, 0x80, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x0f, 0xdf, 0xff, 0x90, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x0f, 0xbf, 0xff, 0xd0, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x1d, 0x7f, 0xff, 0xd0, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x01, 0x1b, 0xff, 0xff, 0xc0, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x02, 0xa7, 0xff, 0xff, 0xc0, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x03, 0xff, 0xc0, 0x00, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0xff, 0x80, 0x00, 0x0b, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x03, 0xff, 0xff, 0xff, 0xf0, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x07, 0xff, 0xff, 0xff, 0xf0, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x0f, 0x07, 0xff, 0xf8, 0xf8, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x0e, 0x01, 0xff, 0xc0, 0x38, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x1c, 0x46, 0xff, 0xb1, 0x18, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x3f, 0x97, 0xff, 0xc0, 0x7a, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xfe, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xfe, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x01, 0x3f, 0xff, 0xff, 0xff, 0xfe, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x01, 0xbf, 0xff, 0xff, 0xff, 0xfe, 0x81, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0xbf, 0xff, 0xff, 0xff, 0xfc, 0x81, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0xff, 0xff, 0xfe, 0xff, 0xfd, 0x83, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0xbf, 0xff, 0xfe, 0xff, 0xfd, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x7f, 0xff, 0xff, 0xff, 0xff, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x7f, 0xff, 0xff, 0xff, 0xfb, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x3f, 0xff, 0xdc, 0xff, 0xfa, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xd8, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xf8, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xd0, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xf8, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x90, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xf8, 0x02, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xb0, 0x00, 0x0f, 0xf5, 0xff, 0xd7, 0xf8, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xb0, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x5f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xa0, 0x00, 0x0f, 0xfb, 0xff, 0xff, 0xf0, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x0f, 0xfd, 0xff, 0xdf, 0xf0, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x07, 0xff, 0xff, 0xbf, 0xf0, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x07, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x87, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x03, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x43, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x60, 0x00, 0x01, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x73, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xe0, 0x00, 0x00, 0xff, 0xff, 0xff, 0x80, 0x00, 0x7b, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfd, 0xe0, 0x00, 0x00, 0x7f, 0xff, 0xfe, 0x00, 0x00, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfd, 0xe0, 0x00, 0x00, 0x3f, 0xff, 0xf8, 0x00, 0x00, 0x27, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x0f, 0xff, 0xf0, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x60, 0x00, 0x00, 0x67, 0xff, 0xe0, 0x00, 0x00, 0x1b, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfd, 0x40, 0x00, 0x00, 0xf3, 0xff, 0xc4, 0x00, 0x00, 0x0b, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x80, 0x00, 0x00, 0xfc, 0xff, 0x8c, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x7f, 0x3c, 0x3c, 0x00, 0x00, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x3f, 0xc0, 0x7c, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xfc, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff };
Copy your assortment to the sketch. Then, to display the array, employ the drawBitmap() method that accepts the following arguments (x, y, image array, image width, prototype pinnacle, rotation). The (ten, y) coordinates define where the image starts to be displayed.
Copy the code beneath to display your bitmap paradigm in the OLED.
/********* Rui Santos Complete project details at https://randomnerdtutorials.com *********/ #include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> #define SCREEN_WIDTH 128 #define SCREEN_HEIGHT 64 Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1); static const uint8_t image_data_Saraarray[1024] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x14, 0x9e, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x36, 0x3f, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x6d, 0xff, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0xfb, 0xff, 0x80, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x03, 0xd7, 0xff, 0x80, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x07, 0xef, 0xff, 0x80, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x0f, 0xdf, 0xff, 0x90, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x0f, 0xbf, 0xff, 0xd0, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x1d, 0x7f, 0xff, 0xd0, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x01, 0x1b, 0xff, 0xff, 0xc0, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x02, 0xa7, 0xff, 0xff, 0xc0, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x03, 0xff, 0xc0, 0x00, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0xff, 0x80, 0x00, 0x0b, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x03, 0xff, 0xff, 0xff, 0xf0, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x07, 0xff, 0xff, 0xff, 0xf0, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x0f, 0x07, 0xff, 0xf8, 0xf8, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x0e, 0x01, 0xff, 0xc0, 0x38, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x1c, 0x46, 0xff, 0xb1, 0x18, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x3f, 0x97, 0xff, 0xc0, 0x7a, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xfe, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xfe, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x01, 0x3f, 0xff, 0xff, 0xff, 0xfe, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x01, 0xbf, 0xff, 0xff, 0xff, 0xfe, 0x81, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0xbf, 0xff, 0xff, 0xff, 0xfc, 0x81, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0xff, 0xff, 0xfe, 0xff, 0xfd, 0x83, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0xbf, 0xff, 0xfe, 0xff, 0xfd, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x7f, 0xff, 0xff, 0xff, 0xff, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x7f, 0xff, 0xff, 0xff, 0xfb, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x3f, 0xff, 0xdc, 0xff, 0xfa, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xd8, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xf8, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xd0, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xf8, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x90, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xf8, 0x02, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xb0, 0x00, 0x0f, 0xf5, 0xff, 0xd7, 0xf8, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xb0, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x5f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xa0, 0x00, 0x0f, 0xfb, 0xff, 0xff, 0xf0, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x0f, 0xfd, 0xff, 0xdf, 0xf0, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x07, 0xff, 0xff, 0xbf, 0xf0, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x07, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x87, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x03, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x43, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x60, 0x00, 0x01, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x73, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xe0, 0x00, 0x00, 0xff, 0xff, 0xff, 0x80, 0x00, 0x7b, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfd, 0xe0, 0x00, 0x00, 0x7f, 0xff, 0xfe, 0x00, 0x00, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfd, 0xe0, 0x00, 0x00, 0x3f, 0xff, 0xf8, 0x00, 0x00, 0x27, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x0f, 0xff, 0xf0, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x60, 0x00, 0x00, 0x67, 0xff, 0xe0, 0x00, 0x00, 0x1b, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfd, 0x40, 0x00, 0x00, 0xf3, 0xff, 0xc4, 0x00, 0x00, 0x0b, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x80, 0x00, 0x00, 0xfc, 0xff, 0x8c, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x7f, 0x3c, 0x3c, 0x00, 0x00, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x3f, 0xc0, 0x7c, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xfc, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff }; void setup() { Serial.brainstorm(115200); if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { Serial.println(F("SSD1306 allocation failed")); for(;;); } filibuster(2000); // Pause for 2 seconds // Clear the buffer. brandish.clearDisplay(); // Describe bitmap on the screen display.drawBitmap(0, 0, image_data_Saraarray, 128, 64, one); brandish.display(); } void loop() { }
Later on uploading the code, this is what nosotros go on the brandish.
Troubleshooting
If yous get the "SSD1306 resource allotment failed" error or if the OLED is non displaying annihilation in the screen, information technology can be 1 of the following issues:
Wrong I2C address
The I2C address for the OLED display we are using is 0x3C. However, yours may be different. Then, brand sure you cheque your display I2C address using an I2C scanner sketch.
SDA and SCL not continued properly
Please make certain that you have the SDA and SCL pins of the OLED display wired correctly. In case of the ESP8266, connect SDA pin to GPIO 4 (D2) and SCL pin to GPIO 5 (D1).
Wrapping Upward
We hope you've found this guide nearly the OLED brandish with EPS8266 useful. Now, yous can integrate the OLED display in your own projects. Proceed to the adjacent tutorial to learn how to display sensor readings on the OLED brandish:
If you like ESP8266, you'll certainly like our ESP8266 resources:
- Home Automation using ESP8266 (eBook)
- MicroPython Programming with ESP8266 (eBook)
- 30+ ESP8266 Projects
- ESP8266 Pinout Reference: Which GPIO pins should you utilise?
Some of our most popular projects with ESP8266:
- Hack a PIR Move Sensor with an ESP8266
- Build a Multisensor Shield for ESP8266
- ESP8266 Web Server with Arduino IDE
- Depression Power Weather Station Datalogger
Thanks for reading.
0 96 Zoll I2c Oled Display Arduino
Posted by: shoemakeengand1972.blogspot.com
0 Response to "0 96 Zoll I2c Oled Display Arduino"
Post a Comment