Arduino - OLED

news2024/10/6 8:26:50

Arduino - OLED

  • Arduino - OLED
  • Arduino通过u8g2库驱动OLED
  • U8g2 驱动oled自定义中文字库

The OLED (Organic Light-Emitting Diode) display is an alternative for LCD display. The OLED is super-light, almost paper-thin, flexible, and produce a brighter and crisper picture.
OLED(有机发光二极管)显示器是LCD显示器的替代品。OLED超轻,几乎像纸一样薄,灵活,可产生更明亮、更清晰的图像。

In this tutorial, we are going to learn:
在本教程中,我们将学习:

  • How to use OLED display with Arduino.
    如何将OLED显示器与Arduino一起使用。
  • How to display text, number on OLED using Arduino
    如何使用Arduino在OLED上显示文本,数字
  • How to vertical and horizontal center align text, number on OLED
    如何在OLED上垂直和水平中心对齐文本,数字
  • How to draw on OLED using Arduino
    如何使用Arduino在OLED上绘图
  • How to display image on OLED using Arduino
    如何使用Arduino在OLED上显示图像

About OLED Display 关于OLED显示屏

There are many types of OLED display. They differ from each other in communication interface, sizes and colors:
OLED显示器有很多种。它们在通信接口、尺寸和颜色上各不相同:

  • Communication interface: I2C, SPI
    通讯接口:I2C、SPI
  • Size: 128x64, 128×32… 尺寸: 128x64, 128×32…
  • Color: white, blue, dual color…
    颜色:白色、蓝色、双色…

Arduino OLED

SPI is generally faster than I2C but requires more Arduino pins. While I2C requires only two pins and can be shared with other I2C peripherals. It’s a trade-off between pins and communication speed. The choice is up to you. For OLED with I2C interface, there are several types of driver such as SSD1306, SH1106 driver . This tutorial uses SSD1306 I2C OLED Display 128x64 and 128x32
SPI 通常比 I2C 快,但需要更多的 Arduino 引脚。而 I2C 只需要两个引脚,并且可以与其他 I2C 外设共享。这是引脚和通信速度之间的权衡。选择权在您手中。对于具有I2C接口的OLED,有几种类型的驱动程序,例如SSD1306,SH1106驱动程序。本教程使用SSD1306 I2C OLED 显示屏 128x64 和 128x32

I2C OLED Display Pinout I2C OLED显示引脚排列

  • GND pin: should be connected to the ground of Arduino
    GND引脚:应接地Arduino的
  • VCC pin: is the power supply for the display which we connect the 5 volts pin on the Arduino.
    VCC引脚:是显示器的电源,我们将其连接到Arduino上的5伏引脚。
  • SCL pin: is a serial clock pin for I2C interface.
    SCL引脚:是用于I2C接口的串行时钟引脚。
  • SDA pin: is a serial data pin for I2C interface.
    SDA引脚:是用于I2C接口的串行数据引脚。

OLED Pinout

※ NOTE THAT: ※ 注意事项:

  • The order of the OLED module’s pins can vary between manufacturers and module types. ALWAYS use the labels printed on the OLED module. Look closely!
    OLED模块引脚的顺序可能因制造商和模块类型而异。始终使用印在OLED模块上的标签。仔细看!
  • This tutorial uses the OLED display that uses the SSD1306 I2C driver. We have tested with the OLED display from DIYables. It works without any issues.
    本教程使用使用 SSD1306 I2C 驱动程序的 OLED 显示器。我们已经用DIYables的OLED显示屏进行了测试。它可以毫无问题地工作。

Wiring Diagram 接线图

  • Wiring diagram between Arduino and OLED 128x64
    Arduino和OLED 128x64之间的接线图

Arduino OLED 128x64 wiring diagram

  • Wiring diagram between Arduino and OLED 128x32
    Arduino和OLED 128x32之间的接线图

Arduino OLED 128x32 wiring diagram

  • The real wiring diagram between Arduino and OLED 128x64
    Arduino和OLED 128x64之间的真实接线图

Arduino OLED 128x64 wiring diagram

  • The real wiring diagram between Arduino and OLED 128x32
    Arduino和OLED 128x32之间的真实接线图

Arduino OLED 128x32 wiring diagram

If you use other Arduino other than Uno, the pins are different. Refer below table for other Arduino
如果您使用 Uno 以外的其他 Arduino,则引脚会有所不同。有关其他Arduino,请参阅下表

OLED Module OLED模块Arduino Uno, Nano Arduino Uno,纳米Arduino Mega
Vin5V5V
GNDGNDGND
SDAA420
SCLA521

How To Use OLED with Arduino 如何将OLED与Arduino一起使用

Install SSD1306 OLED library 安装SSD1306 OLED库

  • Navigate to the Libraries icon on the left bar of the Arduino IDE.
    导航到 Arduino IDE 左侧栏上的 Libraries 图标。
  • Search “SSD1306”, then find the SSD1306 library by Adafruit
    搜索“SSD1306”,然后找到 Adafruit 的SSD1306库
  • Click Install button to install the library.
    单击“安装”按钮安装库。

Arduino OLED library

  • You will be asked for intalling some other library dependencies
    您将被要求安装一些其他库依赖项
  • Click Install All button to install all library dependencies.
    单击“全部安装”按钮以安装所有库依赖项。

Arduino Adafruit GFX sensor library

How to program for OLED 如何对OLED进行编程

  • Include library 包括库
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include < Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
  • Define the screen size if OLED 123x64
    定义 OLED 123x64 的屏幕尺寸
#define SCREEN_WIDTH 128 // OLED display width,  in pixels 
#define SCREEN_HEIGHT 64 // OLED display height, in pixels 
  • Define the screen size if OLED 128x32
    定义 OLED 128x32 的屏幕尺寸
#define SCREEN_WIDTH 128 // OLED display width,  in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels

  • Declare an SSD1306 OLED object
    声明 SSD1306 OLED 对象
// declare an SSD1306 display object connected to I2C
Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

  • In setup() function, initialize OLED display
    在setup()函数中,初始化OLED显示器
// initialize OLED display with address 0x3C for 128x64
if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
  Serial.println(F("SSD1306 allocation failed"));
  while (true);
}

  • And then you can display text, images, draw line …
    然后您可以显示文本、图像、画线…

※ NOTE THAT: ※ 注意事项:

From this point on, all codes are provided for OLED 128x64, but you can easily adapt for OLED 128x32 by changing the screen size and adjusts coordinates if needed
从现在开始,所有代码都适用于 OLED 128x64,但您可以通过更改屏幕尺寸并根据需要调整坐标轻松适应 OLED 128x32

Arduino Code - Display Text on OLED Arduino代码 - 在OLED上显示文本

/*

 * Created by ArduinoGetStarted.com
   *
 * This example code is in the public domain
   *
 * Tutorial page: https://arduinogetstarted.com/tutorials/arduino-oled
   */

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

#define SCREEN_WIDTH 128 // OLED display width,  in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

// declare an SSD1306 display object connected to I2C
Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

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

  // initialize OLED display with address 0x3C for 128x64
  if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    while (true);
  }

  delay(2000);         // wait for initializing
  oled.clearDisplay(); // clear display

  oled.setTextSize(1);          // text size
  oled.setTextColor(WHITE);     // text color
  oled.setCursor(0, 10);        // position to display
  oled.println("Hello World!"); // text to display
  oled.display();               // show on OLED
}

void loop() {
}

The below are some functions that you can use to display text on the OLED:
以下是可用于在OLED上显示文本的一些功能:

  • oled.clearDisplay(): all pixels are off
    所有像素都关闭
  • oled.drawPixel(x,y, color): plot a pixel in the x,y coordinates
    在 x,y 坐标中绘制一个像素
  • oled.setTextSize(n): set the font size, supports sizes from 1 to 8
    设置字体大小,支持1-8大小
  • oled.setCursor(x,y): set the coordinates to start writing text
    设置坐标开始写入文本
  • oled.setTextColor(WHITE): set the text color
    设置文本颜色
  • oled.setTextColor(BLACK, WHITE): set the text color, background color
    设置文本颜色、背景颜色
  • oled.println(“message”): print the characters
    打印字符
  • oled.println(number): print a number
    打印一个数字
  • oled.println(number, HEX): print a number IN hex format
    以十六进制格式打印数字
  • oled.display(): call this method for the changes to make effect
    调用此方法使更改生效
  • oled.startscrollright(start, stop): scroll text from left to right
    从左到右滚动文本
  • oled.startscrollleft(start, stop): scroll text from right to left
    从右向左滚动文本
  • oled.startscrolldiagright(start, stop): scroll text from left bottom corner to right upper corner
    将文本从左下角滚动到右上角
  • oled.startscrolldiagleft(start, stop): scroll text from right bottom corner to left upper corner
    将文本从右下角滚动到左上角
  • oled.stopscroll(): stop scrolling
    停止滚动

How to vertical and horizontal center align text/number on OLED 如何在OLED上垂直和水平中心对齐文本/数字

See How to vertical/horizontal center on OLED
如何在OLED上垂直/水平居中,无论文字大小,下面的代码都会自动将 OLED 上的文字/数字垂直和水平居中对齐。

/*
 * Created by ArduinoGetStarted.com
 *
 * This example code is in the public domain
 *
 * Tutorial page: https://arduinogetstarted.com/faq/how-to-vertical-and-horizontal-center-align-text-number-on-oled
 */

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

#define SCREEN_WIDTH 128 // OLED display width,  in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1); // // create SSD1306 display object connected to I2C

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

  // initialize OLED display with address 0x3C for 128x64
  if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    while (true);
  }

  delay(2000);         // wait for initializing
  oled.clearDisplay(); // clear display

  oled.setTextSize(2);          // text size
  oled.setTextColor(WHITE);     // text color
  oled.setCursor(0, 10);        // position to display
}

void loop() {
  // display string
  String text = "Hi!";
  oledDisplayCenter(text);
  delay(2000);

  // display number
  int number = 21;
  String str = String(number);
  oledDisplayCenter(str);
  delay(2000);
}

void oledDisplayCenter(String text) {
  int16_t x1;
  int16_t y1;
  uint16_t width;
  uint16_t height;

  oled.getTextBounds(text, 0, 0, &x1, &y1, &width, &height);

  // display on horizontal and vertical center
  oled.clearDisplay(); // clear display
  oled.setCursor((SCREEN_WIDTH - width) / 2, (SCREEN_HEIGHT - height) / 2);
  oled.println(text); // text to display
  oled.display();
}

Arduino Code - Drawing on OLED Arduino代码 - 在OLED上绘图

/*

 * Created by ArduinoGetStarted.com
   *
 * This example code is in the public domain
   *
 * Tutorial page: https://arduinogetstarted.com/tutorials/arduino-oled
   */

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

#define SCREEN_WIDTH 128 // OLED display width,  in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

// declare an SSD1306 display object connected to I2C
Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

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

  // initialize OLED display with address 0x3C for 128x64
  if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    while (true);
  }

  delay(2000); // wait for initializing
  oled.setCursor(0, 0);
}

void loop() {
  // draw rectangle
  oled.clearDisplay();
  oled.drawRect(0, 15, 60, 40, WHITE);
  oled.display();
  delay(2000);

  // fill rectangle
  oled.clearDisplay();
  oled.fillRect(0, 15, 60, 40, WHITE);
  oled.display();
  delay(2000);


  // draw the round rectangle
  oled.clearDisplay();
  oled.drawRoundRect(0, 15, 60, 40, 8, WHITE);
  oled.display();
  delay(2000);

  // fill the round rectangle
  oled.clearDisplay();
  oled.fillRoundRect(0, 15, 60, 40, 8, WHITE);
  oled.display();
  delay(2000);

  // draw circle
  oled.clearDisplay();
  oled.drawCircle(20, 35, 20, WHITE);
  oled.display();
  delay(2000);

  // fill circle
  oled.clearDisplay();
  oled.fillCircle(20, 35, 20, WHITE);
  oled.display();
  delay(2000);

  // draw triangle
  oled.clearDisplay();
  oled.drawTriangle(30, 15, 0, 60, 60, 60, WHITE);
  oled.display();
  delay(2000);

  // fill triangle
  oled.clearDisplay();
  oled.fillTriangle(30, 15, 0, 60, 60, 60, WHITE);
  oled.display();
  delay(2000);
}

Arduino Code – Display Image Arduino代码 - 显示图像

To draw image on OLED, we have to convert the image (any format) to the bitmap array first. The conversion can be done by using this online tool. Please see how to convert image to bitmap array on the below image. I converted the Arduino icon to bitmap array.
要在OLED上绘制图像,我们必须首先将图像(任何格式)转换为位图数组。可以使用此在线工具进行转换。请看如何将图像转换为下图中的位图数组。我将Arduino图标转换为位图数组。

image to bitmap array

After converting, copy the array code and update the array code in the ArduinoIcon array in the below code
转换完成后,复制数组代码,并在下面的代码中更新ArduinoIcon数组中的数组代码

/*

 * Created by ArduinoGetStarted.com
   *
 * This example code is in the public domain
   *
 * Tutorial page: https://arduinogetstarted.com/tutorials/arduino-oled
   */

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

#define SCREEN_WIDTH 128 // OLED display width,  in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

// declare an SSD1306 display object connected to I2C
Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

// bitmap of arduino-icon image
const unsigned char ArduinoIcon [] PROGMEM = {
  // 'arduino-icon', 128x64px
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xfe, 0x00, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x01, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xe0, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x3f, 0xff, 0xff,
  0xff, 0xff, 0x80, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x07, 0xff, 0xff,
  0xff, 0xfe, 0x00, 0x00, 0x00, 0x07, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x01, 0xff, 0xff,
  0xff, 0xfc, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff,
  0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff,
  0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff,
  0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff,
  0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x07, 0xff,
  0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff,
  0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff,
  0xfc, 0x00, 0x00, 0xff, 0xf0, 0x00, 0x00, 0xff, 0xfc, 0x00, 0x00, 0x3f, 0xfc, 0x00, 0x00, 0xff,
  0xfc, 0x00, 0x03, 0xff, 0xfc, 0x00, 0x00, 0x7f, 0xf8, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff,
  0xf8, 0x00, 0x0f, 0xff, 0xff, 0x00, 0x00, 0x3f, 0xf0, 0x00, 0x03, 0xff, 0xff, 0xc0, 0x00, 0x7f,
  0xf0, 0x00, 0x1f, 0xff, 0xff, 0xc0, 0x00, 0x1f, 0xe0, 0x00, 0x0f, 0xff, 0xff, 0xe0, 0x00, 0x7f,
  0xf0, 0x00, 0x7f, 0xff, 0xff, 0xe0, 0x00, 0x0f, 0xc0, 0x00, 0x1f, 0xff, 0xff, 0xf8, 0x00, 0x3f,
  0xe0, 0x00, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x07, 0x80, 0x00, 0x7f, 0xff, 0xff, 0xfc, 0x00, 0x1f,
  0xe0, 0x00, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x03, 0x80, 0x00, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x1f,
  0xc0, 0x01, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x03, 0x00, 0x01, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x1f,
  0xc0, 0x03, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0x00, 0x0f,
  0xc0, 0x03, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x07, 0xff, 0xf0, 0x7f, 0xff, 0x00, 0x0f,
  0xc0, 0x07, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x0f, 0xff, 0xf0, 0x7f, 0xff, 0x80, 0x0f,
  0x80, 0x07, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x1f, 0xff, 0xf0, 0x7f, 0xff, 0x80, 0x07,
  0x80, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x3f, 0xff, 0xf0, 0x7f, 0xff, 0xc0, 0x07,
  0x80, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x7f, 0xff, 0xf0, 0x7f, 0xff, 0xc0, 0x07,
  0x80, 0x0f, 0xfe, 0x00, 0x00, 0xff, 0xfc, 0x00, 0x00, 0xff, 0xfc, 0x00, 0x03, 0xff, 0xc0, 0x07,
  0x80, 0x0f, 0xfe, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x01, 0xff, 0xfc, 0x00, 0x01, 0xff, 0xc0, 0x07,
  0x80, 0x0f, 0xfe, 0x00, 0x00, 0xff, 0xff, 0x00, 0x03, 0xff, 0xfc, 0x00, 0x01, 0xff, 0xc0, 0x07,
  0x80, 0x0f, 0xfe, 0x00, 0x00, 0xff, 0xff, 0x00, 0x03, 0xff, 0xfc, 0x00, 0x01, 0xff, 0xc0, 0x07,
  0x80, 0x0f, 0xfe, 0x00, 0x00, 0xff, 0xff, 0x00, 0x03, 0xff, 0xfc, 0x00, 0x01, 0xff, 0xc0, 0x07,
  0x80, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x01, 0xff, 0xff, 0xe0, 0x7f, 0xff, 0xc0, 0x07,
  0x80, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0xff, 0xff, 0xf0, 0x7f, 0xff, 0xc0, 0x07,
  0x80, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0xff, 0xff, 0xf0, 0x7f, 0xff, 0xc0, 0x07,
  0x80, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x7f, 0xff, 0xf0, 0x7f, 0xff, 0xc0, 0x07,
  0x80, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x3f, 0xff, 0xf0, 0x7f, 0xff, 0x80, 0x07,
  0x80, 0x07, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x1f, 0xff, 0xf0, 0x7f, 0xff, 0x80, 0x07,
  0xc0, 0x07, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0x80, 0x0f,
  0xc0, 0x03, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x07, 0xff, 0xff, 0xff, 0xff, 0x00, 0x0f,
  0xc0, 0x03, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0x00, 0x0f,
  0xe0, 0x01, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x03, 0x00, 0x01, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x1f,
  0xe0, 0x00, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x07, 0x80, 0x00, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x1f,
  0xe0, 0x00, 0x7f, 0xff, 0xff, 0xf0, 0x00, 0x0f, 0xc0, 0x00, 0x3f, 0xff, 0xff, 0xf8, 0x00, 0x3f,
  0xf0, 0x00, 0x3f, 0xff, 0xff, 0xe0, 0x00, 0x1f, 0xe0, 0x00, 0x1f, 0xff, 0xff, 0xf0, 0x00, 0x3f,
  0xf8, 0x00, 0x1f, 0xff, 0xff, 0x80, 0x00, 0x3f, 0xe0, 0x00, 0x07, 0xff, 0xff, 0xe0, 0x00, 0x7f,
  0xf8, 0x00, 0x0f, 0xff, 0xff, 0x00, 0x00, 0x7f, 0xf8, 0x00, 0x03, 0xff, 0xff, 0xc0, 0x00, 0x7f,
  0xfc, 0x00, 0x03, 0xff, 0xf8, 0x00, 0x00, 0xff, 0xfc, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff,
  0xfe, 0x00, 0x00, 0x7f, 0xe0, 0x00, 0x01, 0xff, 0xfe, 0x00, 0x00, 0x1f, 0xf8, 0x00, 0x01, 0xff,
  0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff,
  0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff,
  0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x07, 0xff,
  0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff,
  0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff,
  0xff, 0xf8, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xff,
  0xff, 0xfc, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff,
  0xff, 0xff, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x03, 0xff, 0xff,
  0xff, 0xff, 0xc0, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x0f, 0xff, 0xff,
  0xff, 0xff, 0xf0, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x3f, 0xff, 0xff,
  0xff, 0xff, 0xff, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x03, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
};

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

  // initialize OLED display with address 0x3C for 128x64
  if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    while (true);
  }

  delay(2000); // wait for initializing
  oled.setCursor(0, 0);
}

void loop() {
  oled.clearDisplay();

  // display bitmap
  oled.drawBitmap(0, 0, ArduinoIcon, 128, 64, WHITE);
  oled.display();
  delay(2000);

  // invert display
  oled.invertDisplay(1);
  delay(2000);
}

※ NOTE THAT: ※ 注意事项:

  • The image size should be smaller than or equal to screen size.
    图像大小应小于或等于屏幕大小。
  • If you want to adapt the above code for OLED 128x32, you need to recale image and change width/ height in oled.drawBitmap(); function
    如果要将上述代码改编为OLED 128x32,则需要在oled.drawBitmap()中重新绘制图像并更改宽度/高度;功能

OLED Troubleshooting OLED故障排除

If OLED does not display any thing, please do the following check list:
如果OLED没有显示任何内容,请执行以下检查清单:

  • Make sure that your wiring is correct.
    确保您的接线正确无误。
  • Make sure that your I2C OLED uses SSD1306 Driver.
    确保您的 I2C OLED 使用 SSD1306 驱动程序。
  • Check the I2C address of OLED by running the below I2C Address Scanner code on Arduino
    通过在Arduino上运行以下I2C地址扫描器代码来检查OLED的I2C地址
// I2C address scanner program
#include <Wire.h>

void setup()
{
  Wire.begin();
  Serial.begin(9600);
  Serial.println("I2C Scanner");
}

void loop()
{
  byte error, address;
  int nDevices;

  Serial.println("Scanning...");

  nDevices = 0;
  for(address = 1; address < 127; address++ )
  {
    Wire.beginTransmission(address);
    error = Wire.endTransmission();

    if (error == 0)
    {
      Serial.print("I2C device found at address 0x");
      if (address < 16)
        Serial.print("0");

      Serial.print(address,HEX);
      Serial.println("  !");

      nDevices++;
    }
    else if (error==4)
    {
      Serial.print("Unknown error at address 0x");
      if (address < 16)
        Serial.print("0");

      Serial.println(address,HEX);
    }
  }

  if (nDevices == 0)
    Serial.println("No I2C devices found");
  else
    Serial.println("done");

  delay(5000); // wait 5 seconds for next scan
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1872238.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【乐吾乐2D可视化组态编辑器】图形库、组件库

15 图形库 15.1 图纸 新建文件夹、新建图纸、删除文件夹、删除图纸 15.2 系统组件 乐吾乐图形库一共分为三大类&#xff1a;基础图形库、电力图形库、物联网图形库、2.5D图形库&#xff0c;总共约4000个图元&#xff0c;能满足大部分行业的基本需求。 格式有三种&#xff1a…

智慧法务引领:构筑数字化法治核心,塑造未来企业竞争力

在全球化及信息化时代背景下&#xff0c;企业面临的法律环境越来越复杂&#xff0c;法治数字化成为企业维护合法权益、提升市场竞争力的必然选择。智慧法务管理系统作为推动企业法治数字化转型的重要工具&#xff0c;不仅提高了法律服务效率&#xff0c;而且加强了企业的法律风…

百问网全志D1h开发板投屏功能实现

投屏功能实现 D1系列号称点屏神器&#xff0c;不仅能点屏&#xff0c;还能用于投屏。 源码准备 百问网为 【百问网D1h开发板】提供了投屏功能需要使用的源码&#xff0c;直接git下载即可&#xff1a; git clone https://github.com/DongshanPI/DongshannezhaSTU_DLNA_Scree…

MoneyPrinterPlus:AI自动短视频生成工具-微软云配置详解

MoneyPrinterPlus可以使用大模型自动生成短视频&#xff0c;我们可以借助Azure提供的语音服务来实现语音合成和语音识别的功能。 Azure的语音服务应该是我用过的效果最好的服务了&#xff0c;微软还得是微软。 很多小伙伴可能不知道应该如何配置&#xff0c;这里给大家提供一…

沉淀强化镍基合金660大螺丝的物理性能

沉淀强化镍基合金660大螺丝&#xff0c;是一种高性能的工程材料&#xff0c;其在极端环境中展现了优异的稳定性和耐用性。以下&#xff0c;我们将深入解析其主要的物理性能。 首先&#xff0c;该合金螺丝的密度为7.99g/cm&#xff0c;这意味着它具有较高的质量密度&#xff0c;…

力扣随机一题 6/28 数组/矩阵

&#x1f4dd;个人主页&#x1f339;&#xff1a;誓则盟约⏩收录专栏⏪&#xff1a;IT 竞赛&#x1f921;往期回顾&#x1f921;&#xff1a;6/27 每日一题关注博主&#xff0c;后期持续更新系列文章如果有错误感谢请大家批评指出&#xff0c;及时修改感谢大家点赞&#x1f44d…

GEOS学习笔记(一)

下载编译GEOS 从Download and Build | GEOS (libgeos.org)下载geos-3.10.6.tar.bz2 使用cmake-3.14.0版本配置VS2015编译 按默认配置生成VS工程文件 编译后生成geos.dll&#xff0c;geos_c.dll 后面学习使用C接口进行编程

MySQL中的常用逻辑操作符

逻辑运算符在MySQL查询中扮演着重要角色&#xff0c;通过AND、OR、NOT等运算符的组合使用&#xff0c;可以提高查询的准确性和灵活性&#xff0c;确保查询结果满足业务需求。合理使用这些运算符还能优化查询性能&#xff0c;减少不必要的数据检索&#xff0c;并提高SQL语句的可…

maven 根据不同环境,走不同的实现(多种环境组合)

​ 原因&#xff1a; 线上程序同时支持人大金仓和mysql&#xff0c;且支持根据环境动态选择 java JCE 的实现方式前期已完成 springboot 从mysql 迁移人大金仓 -kingbase &#xff1a;https://blog.csdn.net/qq_26408545/article/details/137777602?spm1001.2014.3001.5502 …

检测SD NAND文件系统异常和修复的方法

目录 1、打开命令提示符&#xff1a; 2、运行chkdsk命令&#xff1a; 3、命令参数说明&#xff1a; chkdsk是Windows中的一个命令行工具&#xff0c;用于检查磁盘上的文件系统错误和修复坏块。MK米客方德为您提供指导&#xff0c;以下是使用chkdsk的步骤&#xff1a; 1、打开…

CAN收发器

1、收发器的主要功能 &#xff08;1&#xff09;CAN通讯&#xff08;即报文收发&#xff09; MCU要CAN通讯&#xff1a;收发器模式切换至正常通讯模式&#xff08;Normal&#xff09;&#xff0c;正常通讯模式收发器能收能发。 MCU不要CAN通讯&#xff1a;把收发器切换至其它…

EHS环境健康安全管理:制造业ESG尖子生的“绿色通行证”

嘿&#xff0c;亲爱的制造业老铁们&#xff01;你们是不是经常听到“EHS环安卫管理”这个词&#xff0c;但又觉得它有些神秘和高大上呢&#xff1f;别担心&#xff0c;今天我就带你们轻松愉快地了解这个让制造业更加绿色、健康、安全的“神器”&#xff01; 一、EHS环安卫管理&…

大模型学习笔记-汇总篇

本文记录一下最近一个月学习的大模型相关的技术知识点&#xff0c;为拥抱AI浪潮做些技术储备。 大模型术语相关 参数规模 GPT 3.5 千亿级别 GPT4 1.8W亿级别 国内一般都是十亿或百亿级别 ChatGLM2_2K_6B BAICHUAN_4K_13B 淘宝星辰_4K_13B 【一一AGI大模型学习 所有资源获…

点云可视化 .ply文件 | 方案汇总

前言 本文分析可视化点云.ply文件的几种方法&#xff0c;包括MeshLab软件、在线可视化点云.ply文件、通过PyntCloud库编程实现。 PLY是一种用于存储三维数据的文件格式&#xff0c;常用于点云数据和多边形网格。 被广泛应用于计算机图形学、3D扫描和3D打印等领域。PLY文件可…

【AI落地应用实战】如何让扫描工具更会思考——智能高清滤镜2.0实战测评

一、引言 在这个信息爆炸的数字化时代&#xff0c;扫描工具已经成为我们日常工作和学习中不可或缺的助手。最近&#xff0c;扫描全能王推出了革命性的“智能高清滤镜2.0”&#xff0c;本次更新后&#xff0c;智能高清滤镜能够智能识别并优化扫描过程中的各种问题。无论是光线不…

好书安利 | LangChain入门指南:构建高可复用、可扩展的LLM应用程序(送PDF)轻松入门LangChain

《LangChain入门指南》 LangChain作为大模型集成框架鼎鼎大名&#xff0c;这本《LangChain入门指南》是一本很及时的书&#xff0c;值得推荐&#xff5e; 01 为什么需要LangChain 首先想象一个开发者在构建一个LLM应用时的常见场景。 当你开始构建一个新项目时&#xff0c;…

云仓是如何发展起来的?

1、电子商务的繁荣&#xff1a; 随着电商的兴起&#xff0c;对高效仓储和物流的需求越来越大。传统的仓储方式难以满足海量订单处理和快速配送的要求&#xff0c;因此需要一种更加灵活和高效的仓储解决方案。 ------------------------------------------------- 2、科技进步…

Mac中的xshell、xftp

ROYAL TSX 插件式支持远程连接linux、支持命令行、支持ftp、支持远程windows桌面。 免费版就足够使用了。&#xff08;支持维护一个Connections文件夹&#xff09; 需要在本地创建一个文件夹&#xff0c;用以保存链接信息 使用方法

注意!!2024下《网络规划设计师》易混淆知识点来了,赶紧码住

宝子们&#xff0c;在复习软考网络规划设计师中&#xff0c;是不是觉得有很多知识点含义比较相近&#xff0c;很多友友刚看的时候&#xff0c;估计会像我一样把它们弄混&#xff0c;作为一个软考老鸟&#xff0c;在这里给大家整理了网规学习过程中易混淆的知识点&#xff0c;大…

【GreenHills】GHS中Build的高级选项设置

【更多软件使用问题请点击亿道电子官方网站】 1、 文档目标 了解GHS中高级构建选项的使用 2、 问题场景 1&#xff09;、想要清除工程的所有输出文件 2&#xff09;、想要对于工程进行重新构建的时候&#xff0c;希望删掉之前的输出文件&#xff0c;保证工程中所有输出文件…