Thursday 4 February 2021

OLED displays - arduino

 Organic Light Emitting Diodes or OLEDs don't need backlights,
They contain a film of an organic compound that emits light in response to electric currents.
They also consume less energy than LCDs
I2C uses just 4 pins
(though some come with an extra reset pin).
 
This is a 0.96" OLED LCD Display Module IIC I2C Interface 128x64

 
 
PinWiring to Arduino Uno
Vin5V
GNDGND
SCLA5
SDAA4              
 
To control the OLED display you need the Wire.h , adafruit_SSD1306.h and the adafruit_GFX.h libraries.
The Wire.h library will be installed by default  


 
 
Functions that are useful with OLEDS
  • display.clearDisplay() – all pixels are off
  • display.drawPixel(x,y, color) – plot a pixel in the x,y coordinates
  • display.setTextSize(n) – set the font size, supports sizes from 1 to 8
  • display.setCursor(x,y) – set the coordinates to start writing text
  • display.print(“message”) – print the characters at location x,y
  • display.display() – call this method for the changes to make effect 

 OLEDs communicate with your Arduino via i2c.
+ LCD display i2c - part 1   
 
The I2C is a type of serial bus developed by Philips, which uses two bidirectional lines, called SDA (Serial Data Line) and SCL (Serial Clock Line).  

Data connects to A4
Clock connects to A5 (Uno)


If when you first power it up and nothing happens, try to use a program with a different resolution
 
The  0.96" OLED may be 128x64 or 128x32

Though I bought this OLED thinking it was a 126 x 64 pixel, it runs the ssd1306_128x32_i2c
code.


 
 
 
 
 
 
 
 
 
 
 
 
 
 

 
 
 //*********************************************************************
 Code 2 - featherwing - in the examples of the IDE
 
This is the splashscreen
 

//****************
 #include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

Adafruit_SSD1306 display = Adafruit_SSD1306(128, 32, &Wire);

// OLED FeatherWing buttons map to different pins depending on board:
#if defined(ESP8266)
  #define BUTTON_A  0
  #define BUTTON_B 16
  #define BUTTON_C  2
#elif defined(ESP32)
  #define BUTTON_A 15
  #define BUTTON_B 32
  #define BUTTON_C 14
#elif defined(ARDUINO_STM32_FEATHER)
  #define BUTTON_A PA15
  #define BUTTON_B PC7
  #define BUTTON_C PC5
#elif defined(TEENSYDUINO)
  #define BUTTON_A  4
  #define BUTTON_B  3
  #define BUTTON_C  8
#elif defined(ARDUINO_FEATHER52832)
  #define BUTTON_A 31
  #define BUTTON_B 30
  #define BUTTON_C 27
#else // 32u4, M0, M4, nrf52840 and 328p
  #define BUTTON_A  9
  #define BUTTON_B  6
  #define BUTTON_C  5
#endif

void setup() {
  Serial.begin(9600);

  Serial.println("OLED FeatherWing test");
  // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Address 0x3C for 128x32

  Serial.println("OLED begun");

  // Show image buffer on the display hardware.
  // Since the buffer is intialized with an Adafruit splashscreen
  // internally, this will display the splashscreen.
  display.display();
  delay(1000);

  // Clear the buffer.
  display.clearDisplay();
  display.display();

  Serial.println("IO test");

  pinMode(BUTTON_A, INPUT_PULLUP);
  pinMode(BUTTON_B, INPUT_PULLUP);
  pinMode(BUTTON_C, INPUT_PULLUP);

  // text display tests
  display.setTextSize(1);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(0,0);
  display.print("Connecting to SSID\n'adafruit':");
  display.print("connected!");
  display.println("IP: 10.0.1.23");
  display.println("Sending val #0");
  display.setCursor(0,0);
  display.display(); // actually display all of the above
}

void loop() {
  if(!digitalRead(BUTTON_A)) display.print("A");
  if(!digitalRead(BUTTON_B)) display.print("B");
  if(!digitalRead(BUTTON_C)) display.print("C");
  delay(10);
  yield();
  display.display();
}
//**********************
 
 
 
 Links
 
 
+ https://www.youtube.com/watch?v=HdgugXvqR3I 

-------------------------------------------------------------------------------------------

 ---------------------------------
-------------------------------------

No comments:

Post a Comment