在Arduino IDE中编程利用ESP-01s点亮一块OLED。
为了方便使用,直接上代码
#include "SSD1306Wire.h"
/* 设置oled屏幕的相关信息 */
const int I2C_ADDR = 0x3c; // oled屏幕的I2c地址
#define SDA_PIN 2 // SDA引脚,默认gpio4(D2)
#define SCL_PIN 0 // 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.mirrorScreen(); //屏幕翻转(我用了分光棱镜所以采用了翻转)
oled.setContrast(255); // 设置屏幕亮度
drawRect(); // 测试屏幕显示
oled.clear(); oled.display(); // 清除屏幕
oled.setFont(ArialMT_Plain_16); // 设置字体
oled.drawString(10, 0, "ONLY ZI MU"); // 将要显示的文字写入缓存
oled.drawString(30,40,"888");
oled.display();
}
void loop() {
}
//画矩形动画框
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);
}
}
是不是明白了?ESP01在Arduino IDE中实际就是使用ESP8266芯片包烧录,其本质也就是一块ESP8266。
之后就可以将代码进行烧录了。
也可以参考这个网站 https://developer.aliyun.com/article/1206718
这是阿里云官方的教程,基本通用。
如果采用我的代码无效,一般是驱动库版本不同,如果有问题可以评论,我会把库文件上传。