我认为你有你的Arduino IDE已经准备好所需的图书馆运行nodemcu代码。如果不是,请访问我的授予教程:从blynk眨眼,对nodemcu esp-12e翅膀IOT的旅程
现在是时候安装OLED显示屏,我们的老朋友,SSD1306,这主要特点:
-
显示尺寸:0.96“
-
IIC串行I2C
-
128x64
-
白光OLED液晶LED
连接器件引脚的nodemcu,如波纹管在以上电气图所示:
-
SDA的= = > D1(5)
-
SCL * = = > D2(4)*你也可以找到“A”中的文本
-
VCC = = >的SSD1306可采用5V或3.3V(外部)直接从nodemcu模块。
-
GND = = > GND
一旦我们有了连接显示器,让我们下载我们的Arduino IDE安装它的图书馆。我们利用以前的项目使库的版本,但这一次我们将探讨另一个:“ESP8266 OLED为SSD1306显示“Daniel Eichhorn开发的驱动程序(确保你使用的版本3.0.0或更大!)。
贝娄图书馆必须下载并安装在你的Arduino IDE:
https://github.com/squix78/esp8266-oled-ssd1306
一旦你重新启动IDE,图书馆应该已经安装。
该库支持I2C协议,使用内置的有线接入的OLED显示屏。H库:
#包括<<丝。”
#包括“SSD1306。H”
SSD1306显示(地址,SDA,SDC);
我们列出了一些重要的API将使用我们的OLED显示器。完整的列表可以在上面提供的GitHub创立。
A.显示控制:
无效();//初始化显示
无效resetdisplay(void);//循环通过初始化
无效显示(void);/ /打开
无效displayoff显示(void);//将显示产品
清空(void);//清除局部像素缓冲
无效invertdisplay(void);/ /倒置显示模式
虚空(void);正常/正常显示模式
无效setcontrast(char对比);//设置显示对比
无效flipscreenvertically();//把显示器颠倒
B.像素图
无效设置颜色(oleddisplay_color颜色);//设置所有像素操作
空隙SetPixel颜色(int16_t X,Y int16_t);/ /画一个像素在给定的位置
空隙DrawLine(int16_t x0,int16_t Y0,int16_t int16_t X1,Y1);//画一条线从0到1
POS POS无效drawhorizontalline(int16_t X,Y int16_t,int16_t长度);//画一条水平线
无效drawverticalline(int16_t X、Y int16_t,int16_t长度);//画林垂直
无效drawfastimage(int16_t X,Y int16_t,int16_t int16_t宽度,高度,const char *图像);/ /画一个位图图像格式的内部
C.文本操作:
无效的束带(int16_t X,Y int16_t,字符串文本);
/写的文字在给定的位置
uint16_t getstringwidth(const char *的文字,uint16_t长度);
/字符串的当前字体设置
宽度/返回const uint16_t getstringwidth(文本/方便的方法为const char版);
/
无效settextalignment(oleddisplay_text_alignment TextAlignment);
/ text_align_left,text_align_center,text_align_right,text_align_center_both
无效设置字体(const char* fontdata);
/。
/可用的默认字体:arialmt_plain_10,arialmt_plain_16
D.帧(“UI库”)
UI库是用来提供一个基本的用户界面元素,<em>框架</em>和<em>覆盖</em>。一个框架是用来提供默认行为是显示某个确定的时间比移动到下一个信息(如“页”)。标准库还提供了一个指标,会相应的更新。另一方面,一个覆盖是一件信息(如时钟)显示总是在相同的位置。
无效();//初始化显示
无效settargetfps(uint8_t FPS);/ /配置内部目标FPS
无效enableautotransition();/ /启用自动过渡到下一帧
无效disableautotransition();/ /禁用自动过渡到下一帧。
无效setautotransitionforwards();//设置方向如果自动转换
无效setautotransitionbackwards();//设置方向如果自动转换
无效settimeperframe(uint16_t时间);//设置约时间框显示
无效settimepertransition(uint16_t时间);//设置约时间的过渡将
无效setframeanimation(animationdirection目录);//设置动画是用来过渡
无效setframes(framecallback * framefunctions,uint8_t frameCount);//加框的绘图功能
int8_t update();//这需要召集主要是
一旦两OLED本身及其库安装,让我们写一个简单的“Hello World程序来测试它。输入以下代码在您的IDE,结果应该显示在上面的照片所示:
/* Hello World OLED Test */
#include // Only needed for Arduino 1.6.5 and earlier
#include "SSD1306.h" // alias for `#include "SSD1306Wire.h"`
SSD1306 display(0x3c, 5, 4); // Initialise the OLED display using Wire library
void setup()
{
Serial.begin(115200);
display.init(); // Initialising the UI will init the display too.
display.flipScreenVertically();
display.clear();
drawHelloWorld();
display.display();
}
void loop()
{
}
void drawHelloWorld()
{
display.setTextAlignment(TEXT_ALIGN_LEFT);
display.setFont(ArialMT_Plain_10);
display.drawString(0, 0, "Hello world");
display.setFont(ArialMT_Plain_16);
display.drawString(0, 10, "Hello world");
display.setFont(ArialMT_Plain_24);
display.drawString(0, 26, "Hello world");
}
现在,上传素描:<em>ssd1306simpledemo.ino</em>,部分实例库。在运行代码,改变OLED引脚连接一致:
//初始化OLED显示器使用钢丝库
SSD1306显示(0x3C,5,4);
视频显示的OLED播放演示测试代码: