快捷搜索:  汽车  科技

esp8266支持什么液晶屏(ESP8266驱动OLED屏)

esp8266支持什么液晶屏(ESP8266驱动OLED屏)上传完成后,可以看到OLED可以显示了。程序下载IOT Kit连接在Arduino IDE中新建sketch,拷贝如下代码并保存。/* * oled * ESP8266驱动OLED屏 */ #include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> Adafruit_SSD1306 oled(128 64 &Wire -1); void setup() { oled.begin(SSD1306_SWITCHCAPVCC 0x3C); oled.setTextColor(WHITE);//开像素点发光 oled.clearDisplay();//清屏 oled.setTextSize(1); //设置字体大小 oled.set

1. 安装驱动库

使用「Adafruit_SSD1306」驱动库。

在Arduino IDE中点击「项目」—「加载库」—「管理库」,查找选择最新版本,点击安装,然后在弹出的对话框中选择Install all,安装全部的关联库。

esp8266支持什么液晶屏(ESP8266驱动OLED屏)(1)

安装驱动库

2.硬件连接

这里使用IIC驱动屏,在IOT Kit开发板上,ESP8266的GPIO4和GPIO5分别通过跳线帽连接到OLED屏的SDA和SCL引脚。

esp8266支持什么液晶屏(ESP8266驱动OLED屏)(2)

IOT Kit连接

3.编程下载

在Arduino IDE中新建sketch,拷贝如下代码并保存。

/* * oled * ESP8266驱动OLED屏 */ #include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> Adafruit_SSD1306 oled(128 64 &Wire -1); void setup() { oled.begin(SSD1306_SWITCHCAPVCC 0x3C); oled.setTextColor(WHITE);//开像素点发光 oled.clearDisplay();//清屏 oled.setTextSize(1); //设置字体大小 oled.setCursor(35 5);//设置显示位置 oled.println("-TonyCode-"); oled.setTextSize(2);//设置字体大小 oled.setCursor(15 30);//设置显示位置 oled.println("OLED TEST"); oled.display(); // 开显示 } void loop() {}

电脑连接开发板,在「工具」—「开发板」—「端口」中选择正确的端口号,点击上传,程序编译并上传。

esp8266支持什么液晶屏(ESP8266驱动OLED屏)(3)

程序下载

上传完成后,可以看到OLED可以显示了。

esp8266支持什么液晶屏(ESP8266驱动OLED屏)(4)

实验现象

4. 显示WiFi信息

在完成对OLED屏的驱动后,结合前篇连接网络的例程,我们就可以在OLED屏上查看连网信息了。

拷贝如下程序编译上传,之前在串口显示的连网信息就可以在OLED屏上显示了。

/* * oled_infor * OLED显示连网信息 */ #include <ESP8266WiFi.h> #include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> const char* ssid = "your-ssid";//连接WIFI名(SSID) const char* password = "your-password";//WIFI密码 Adafruit_SSD1306 oled(128 64 &Wire -1); void setup() { oled.begin(SSD1306_SWITCHCAPVCC 0x3C); oled.setTextColor(WHITE);//开像素点发光 oled.clearDisplay();//清屏 oled.setTextSize(1); //设置字体大小 oled.setCursor(15 5);//设置显示位置 oled.println("WiFi Information"); oled.setCursor(2 20);//设置显示位置 WiFi.begin(ssid password);//启动网络连接 while (WiFi.status() != WL_CONNECTED)//检测网络是否连接成功 { delay(500); oled.print(".");//设置显示位置 oled.display(); // 开显示 } oled.setTextSize(1);//设置字体大小 oled.setCursor(2 35);//设置显示位置 oled.println("Connected IP address:"); oled.println(); oled.println(WiFi.localIP()); oled.display(); // 开显示 } void loop() {}

esp8266支持什么液晶屏(ESP8266驱动OLED屏)(5)

实验现象

猜您喜欢: