DIYMall 0.96 Inch / 128x64 series

< BACK to Arduino Projects page
Click HERE to open in a new tab full-screen if not already.

This little OLED display is just flat out awesome. It is low cost on power consumption (see test results) and is fairly fast to update. You can even hook up two to the same pinouts without any issues that I could find. It is hard to go wrong with this neat component, especially considering the low price. A must have for simple projects that need data out displayed without a serial view.

DIYMall 0.96 Inch Yellow/Blue I2c Serial Oled display
   
Man let me tell you what. Being new to this stuff will pay off for anyone watching cause I really goofed on this one. After watching someone else hook this up to power, and wham there was a test screen, I figured that just supplying power would do the same. The example I saw never said that code was running. It looked as if they just used the Arduino 5v supply to turn it on. Not. The display has to be initialized of course just like other I2c things. I used Adafruit's SSD1306 library to get this thing working. Nice library. Let's see what was involved.
Note - you will need to have the I2c address for the device you are using. If you don't know it or it's not labeled, then you will need an I2c scanner. Click HERE to get the .ino file. Compile and upload to your Arduino after you hook up the display and the program will scan for the device and tell you the address it is on.

I looked a few things up and went straight to github for the Adafruit SSD1306 lib. Go HERE to get the same one. Or just click HERE to download the one I used in this example. Upon looking into this project I discovered that the OLED library was dependent on another one. I would also need Adafruit's graphics core library. You can get that from github HERE or download the copy I used HERE to save some time. In either case you will need to add both of these to your compiler. Then it's just a case of hooking up the hardware, compiling and uploading the code.

Here's a few screenshots of the oled for your approval. Click on one to see the full size picture in a new tab. I have seen versions that are all blue with no yellow, but I wanted this one to place a menu across the top that would stand out against the contrasting blue where I will likely place data to be viewed. Note that two can function on the same I2c address. And they are both being powered from the Arduino's 5v source.
~ On a side note - as of this update I have been running the included test program on my arduino shown pictured with both displays running now FOR 18 HOURS. They are both powered by a 6xAA battery pack and I have seen no drop in brilliance/luminance. I'm going to let them run the program until the batteries are depleted. I will give the results then... TEST RESULTS HERE.

Once you have the libraries installed you can download my code HERE, or just copy and paste it from below...

//------------------------------------------------------------------------
// OLED 128x64 display example
// 01/27/17 by: Atomkey
// Libraries used: Adafruit_SSD1306-master.zip, Adafruit-GFX-Library-master.zip
// Get the libraries from atomkey.net under code/AVR section
// Or - goto https://github.com/adafruit/Adafruit_SSD1306
// and here: https://github.com/adafruit/Adafruit-GFX-Library
// Using Adafruit's examples may cause issues. This code should work with no
// problems. Take a look at the header files for both libraries - there are 
// plenty of functions to draw lines/circles/scroll text, etc...
//------------------------------------------------------------------------

//#include <SPI.h>     // should compile, upload, and run without 
//#include <Wire.h>    // out these. If not, uncomment them.

#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#include <gfxfont.h>

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

/****************************************/
void setup()   
{                
  int ct = 0; // general purpose counter
  //Serial.begin(9600);

  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2c addy 0x3D (for the 128x64)
  
  display.clearDisplay();                     // the adafruit logo defaults everytime the display is initialized
                                              // so clear it out first, and...
  display.display();                          // display a blank screen.

  ct = 100;
   while(ct--) drawstatic(100);               // make static/snow on the screen
  delay(500);
  display.clearDisplay();                     // this method does NOT require you to call
                                              // the .display method to update the screen as cleared

  display.setTextSize(1);                // show some text on the screen with font size 1
  display.setTextColor(WHITE);           // invert values with (BLACK, WHITE) - see below
  display.setCursor(0,0);
  display.println("Once upon a time\nin a galaxy\nfar far away...");
  display.display();                     // you have to call .display to update it with what you have 'painted'
  delay(3000);                           // give some time to read

  display.clearDisplay();                
  display.setCursor(0,0);
  
  display.println("3.141592 = text");    // println has an overloaded method that can handle numbers
  display.print(3.141592);               // or text - float numbers are rounded to the 1/100*
  display.setTextColor(BLACK, WHITE);    // invert foreground and background
  display.println(" = float");
  display.display();
  delay(3000);

  display.setTextColor(WHITE);           // get ready to demonstrate font sizes

  ct = 4;
  while(ct)
   showfonts(ct--);                      // show font sizes 4-1 in descending order
 }

/****************************************/
void loop() 
{
  int reps = 10; // repeate how many times?
   
  while(reps--)  // do the reps
   {   
     display.invertDisplay(true);  // flash the screen back and forth
     delay(100);                   // for 'rep' number of times
     display.invertDisplay(false);
     delay(100);                   // delay a bit between flashes
   }
   
  setup();                         // start demonstration all over with static again
}

//------------------------------------------ quick function to draw a static pattern 
//------------------------------------------ on the display. 
void drawstatic(int how_fast)
{
  while(how_fast--) // paint how many pixels before updating display?
   {
     // radomly place a white or black (on/off) pixel somewhere 
     // on the display canvas 
     
     display.drawPixel(random(128), random(64), WHITE);
     display.drawPixel(random(128), random(64), BLACK);
   }
  
  display.display(); // show the canvas
}

//------------------------------------------ quick function to show a font size 
//------------------------------------------ and test word on the display
void showfonts(int font_size)
{
  display.clearDisplay();                        // setup display for some work
  display.setCursor(0,0);

  display.setTextSize(font_size);                // set the font size 
  display.print(font_size);                      // display font size example
  display.println(" font");
  display.display();
  delay(3000);                                   // give the user a moment to view
}

// ------------- end of code --

Click to see full size with pinouts labeled. +Opens in a new tab.

Whoa