C/C++教程

【基于Arduino开发环境ESP8266 oled1306绘图(程序是修改至CSDN的Willliam_william博主)】

本文主要是介绍【基于Arduino开发环境ESP8266 oled1306绘图(程序是修改至CSDN的Willliam_william博主)】,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

基于Arduino开发环境ESP8266 oled1306绘图(程序是修改至CSDN的Willliam_william博主)

需要使用Arduino-OLED第三方库:https://github.com/ThingPulse/esp8266-oled-ssd1306/tree/4.2.0网址进行下载然后得到esp8266-oled-ssd1306-master.zip文件然后解压到你的用户库Arduino\libraries里边

例如我的库路径是:C:\Users\Administrator\Documents\Arduino\libraries
在这里插入图片描述

因为程序里的SSD1306Wire.h头文件在这里边esp8266-oled-ssd1306-master.zip
在这里插入图片描述
也可以到我QQ群里下载项目文件 :
雨过天亮电子DIY
578065133
基于Arduino ESP8266 oled绘图(Zero创客).zip
在这里插入图片描述
下面是程序:

//draw.ion文件
/*
 * 程序是修改至CSDN的Willliam_william博主
 * 修改人:Zero创客
 * ESP8266-NodeMCU通过驱动oled显示文文字和图片
 * 需要使用Arduino-OLED第三方库:https://github.com/ThingPulse/esp8266-oled-ssd1306/tree/4.2.0
 */

/* 使用0.96寸的OLED屏幕需要使用包含这个头文件 */
#include "SSD1306Wire.h"

#include "image.h"

/* 设置oled屏幕的相关信息 */
const int I2C_ADDR = 0x3c;              // oled屏幕的I2c地址
#define SDA_PIN 4                       // SDA引脚,默认gpio4(D2)
#define SCL_PIN 5                       // SCL引脚,默认gpio5(D1)

/* 新建一个oled屏幕对象,需要输入IIC地址,SDA和SCL引脚号 */
SSD1306Wire oled(I2C_ADDR, SDA_PIN, SCL_PIN);


void setup() {
  /* 1. 初始化串口通讯波特率为115200*/
  Serial.begin(115200);

  /* 2. oled屏幕初始化 */
  oled.init();
  oled.flipScreenVertically();          // 设置屏幕翻转
  oled.setContrast(255);                // 设置屏幕亮度
  //drawRect();                           // 测试屏幕显示
  oled.clear(); oled.display();         // 清除屏幕

  /* 1. 显示欢迎字母 */
  oled.setFont(ArialMT_Plain_16);       // 设置字体
  oled.drawString(40, 0, "Hello!"); // 将要显示的字母写入缓存
  oled.drawString(10, 20, "I'm Zero Hacker"); // 将要显示的字母写入缓存
  oled.display();                       // 将缓存里的文字在屏幕上显示
  delay(1500);
  oled.clear(); oled.display();         // 清除屏幕
}

void loop() {
  
  /* 2. 显示Zero创客Logo图片*/
  oled.drawFastImage(32, 0, 64, 64, image);
  oled.display();
  //delay(1000);
  
  //oled.clear(); oled.display();         // 清除屏幕

  /* 3. LED状态取反 */
 // digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); 
}
/*
void drawRect(void) {
  for (int16_t i=0; i<oled.getHeight()/2; i+=2) {
    oled.drawRect(i, i, oled.getWidth()-2*i, oled.getHeight()-2*i);
    oled.display();
    delay(50);
  }
}
*/
//image.h存放绘图取模数据的头文件
/*
*用于存储图片的头文件
*
*
*/
//Zero创客Logo
const uint8_t image[] PROGMEM = {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFC,0xFF,0x89,0xAA,0xAA,0xAA,0x2A,0x00,0xFE,0xFF,0x57,0x55,0x55,0x55,0xD5,0x00,
0x06,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0xE6,0x10,0x00,0x00,0x00,0x00,0xD0,0x00,0xA6,0x11,0x00,0x00,0x00,0x00,0x81,0x00,
0x24,0x19,0x00,0x00,0x00,0x80,0xC2,0x00,0x26,0x0F,0x00,0x00,0x00,0x40,0x84,0x00,0x06,0x00,0x00,0x00,0x00,0x40,0xD4,0x00,
0xC6,0x0F,0x00,0x00,0x00,0x40,0x84,0x00,0x24,0x18,0x00,0x00,0x00,0x00,0xC0,0x00,0x24,0x10,0x00,0x00,0x00,0x00,0x80,0x00,
0x26,0x10,0x00,0x11,0x00,0x40,0xC4,0x00,0xC6,0x0F,0xE0,0x00,0x00,0x40,0x80,0x00,0x04,0x00,0x44,0x44,0x01,0x40,0xC4,0x00,
0x04,0x00,0x02,0x00,0x0B,0x00,0x84,0x00,0x06,0x00,0x53,0x55,0x1F,0x40,0xC4,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x85,0x7A,
0x04,0x00,0x44,0x44,0x44,0x40,0xC5,0x2A,0x06,0x60,0x00,0x00,0x00,0x40,0x81,0x7E,0x04,0x20,0x61,0x04,0x55,0x40,0xC1,0x2A,
0x04,0x10,0xF8,0x30,0x00,0x40,0x85,0x7A,0x06,0x10,0xF8,0x23,0x44,0x42,0xC5,0x00,0x04,0x00,0x8C,0x33,0x00,0x42,0x85,0x56,
0x00,0x10,0x0C,0x33,0x51,0x43,0xC5,0x7C,0x06,0x00,0x0C,0x36,0x00,0x02,0x85,0x54,0x06,0x48,0x0C,0x3E,0x44,0x46,0xC5,0x7E,
0x06,0x00,0x0C,0x1C,0x00,0x02,0x85,0x44,0x06,0x50,0x01,0x00,0x55,0x47,0xC5,0x40,0x06,0x00,0x00,0x00,0x00,0x42,0x85,0x00,
0x04,0x44,0x04,0x00,0x44,0x46,0xC5,0x48,0x04,0x00,0xC0,0x3F,0x00,0x00,0x84,0x2A,0x06,0x50,0xC3,0x3F,0x51,0x05,0xC5,0x1E,
0x06,0x08,0x82,0x00,0x00,0x00,0x85,0x1A,0x04,0x48,0x84,0x01,0x55,0x44,0xC5,0x2A,0x04,0x00,0x80,0x3F,0x22,0x40,0x85,0x48,
0x04,0x50,0x15,0x3F,0x55,0x45,0xC5,0x00,0x04,0x00,0x00,0x00,0x00,0x40,0x81,0x54,0x04,0x48,0x44,0x44,0x54,0x40,0xC5,0x7C,
0x04,0x00,0x0C,0x00,0x20,0x00,0x85,0x16,0x04,0x50,0x55,0x51,0x55,0x41,0xC1,0x7C,0x04,0x00,0x00,0x00,0x00,0x00,0x85,0x54,
0x06,0x40,0x44,0x47,0xC4,0x40,0xC5,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x84,0x00,0x46,0x00,0x55,0x55,0x1D,0x40,0xC4,0x00,
0xB6,0x02,0x00,0x00,0x06,0x00,0x80,0x00,0x22,0x0D,0x44,0x4C,0x07,0x40,0xC4,0x00,0xA2,0x0A,0x18,0x00,0x00,0x00,0x80,0x00,
0x00,0x00,0x80,0x8B,0x00,0x40,0xD4,0x00,0xD2,0x02,0x00,0x10,0x00,0x00,0x84,0x00,0xB2,0x05,0x00,0x00,0x00,0x40,0xC4,0x00,
0xD2,0x0A,0x00,0x00,0x00,0x80,0x82,0x00,0x26,0x07,0x00,0x00,0x00,0x00,0xC1,0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x80,0x00,
0x0C,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,0xFC,0x0F,0xA3,0xAA,0xAA,0xAA,0xAA,0x00,0xFE,0x5F,0x55,0x55,0x55,0x75,0x77,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};

oled控制引脚:
SDA_PIN 4 // SDA引脚,默认gpio4(D2)
SCL_PIN 5 // SCL引脚,默认gpio5(D1)

程序烧录后屏幕会显示:
Hello!
I’m Zero Hacker
在这里插入图片描述

接着显示我的logo
在这里插入图片描述

这篇关于【基于Arduino开发环境ESP8266 oled1306绘图(程序是修改至CSDN的Willliam_william博主)】的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!