Tutorial X: OLED Screen Control Demo

From Waveshare Wiki
Jump to: navigation, search

Modules Usage Tutorial

OLED Screen Control

The General Driver for Robots has an onboard IIC interface. The OLED module of SSD1306 can be connected to the driver board with IIC to achieve the effect of displaying information on the OLED screen. The OLED screen control program is provided below.

Demo

Upload Demo

Download dependency library Adafruit_SSD1306.
Tutorial VIII01EN.png
After downloading the zip file, open SSD1306.ino, connect the multifunctional driver board to the computer with a USB cable (here the Type-C port of the USB of the multifunctional driver board is plugged in), click "Tools" → "Ports", and then click Click "Tools" → "Ports", and then click on the newly appeared COM port.
UGV1 doenload03EN.png
In Arduino IDE, click "Tools" → "Development Board" → "ESP32" → "ESP32 Dev Module". Upload the demo after selecting the development board and the port. After uploading the demo, connect the IIC peripheral expansion interface to the OLED screen and WAVESHARE will be displayed on the OLED screen.

Demo Analysis

#include <Wire.h>

#define S_SCL   33
#define S_SDA   32

#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128    //OLED display width and pixels 
#define SCREEN_HEIGHT 32    //OLED display height and pixels
#define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

void InitScreen(){
  if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {    //Initialize OLED display  
    Serial.println(F("SSD1306 allocation failed"));
  }
  display.clearDisplay();    //Clear display
  display.display();
}

void Screenupdate(){
  //Clear the display first, and then set the size and color of the text, cursor position, and output "WAVESHARE"
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(0,0);
  display.print(F("WAVESHARE"));
  display.display();
}

void setup() {
  Wire.begin(S_SDA,S_SCL);
  InitScreen();

}

void loop() {
  Screenupdate();    //Call Screenupdate() function
  delay(1);
}

Resource