Home CodeArduino Due Arduino Due and OLED display example

Arduino Due and OLED display example

by shedboy71

This example uses an OLED display these typically come in a couple of different sizes 128×32 and 128×64, this particular example will use the I2C connection from the Micro:bit to the display. There are a couple of libraries that make life easier.

Lets look at a typical oled display

These will come in useful for various projects for example displaying the date and time or maybe temperature readings from a sensor

Connection

Pin Label Arduino PIN I2C Function Notes
GND Ground Ground 0V
VCC Power Power Regulated 5V supply.
SDA SDA / 20 SDA Serial data in
SCL SCL / 21 SCL  I2C clock

This layout shows a 128×32 connected to the Arduino Due, 128×64 I2C devices would be the same

 

Code

This example uses the https://github.com/adafruit/Adafruit_SSD1306/archive/master.zip and https://github.com/adafruit/Adafruit-GFX-Library/archive/master.zip , theer are several built in examples. I have modified one just to display text as further examples will write text to a display

 

[codesyntax lang=”cpp”]

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4

Adafruit_SSD1306 display(OLED_RESET);

void setup()   
{                  
  Serial.begin(9600);   
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3C (for the 128x32)  // init done  
  display.clearDisplay();  // text display tests  
  display.setTextSize(1);  
  display.setTextColor(WHITE);  
  display.setCursor(0,0);  
  display.println("Hello, world!");  
  display.setTextColor(BLACK, WHITE); // &#039;inverted&#039; text  
  display.println(3.141592);  
  display.setTextSize(2);  
  display.setTextColor(WHITE);  
  display.print("0x");   
  display.println(0xDEADBEEF, HEX);  
  display.display();  
  display.clearDisplay();
}
  
void loop() 
{  
}

[/codesyntax]

 

Link

1Pcs 128X64 OLED LCD LED Display Module For Arduino 0.96″ I2C IIC SPI Serial new original

Share

You may also like