Home CodeArduino micro:bit and OLED display example

micro:bit and OLED display example

by shedboy71

micro:bit and OLED display example

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 Microbit PIN I2C Function Notes
GND Ground Ground 0V
VCC Power Power Regulated 5V supply.
SDA SDA / P20 SDA Serial data in
SCL SCL / P19 SCL  I2C clock

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

 

microbit and oled

microbit and oled

 

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 , there 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

You may also like

Leave a Comment