代码很简单,用u8g2自带的例程即可,屏幕是I2C的,选择对应的参数,针脚我定义到了D5和D6。屏幕一共四个端子,其中2个是电源,scl接D5,sda接D6。
#include <Arduino.h>
#include <U8g2lib.h>
#include <Wire.h>
U8G2_SSD1306_128X64_NONAME_1_SW_I2C
u8g2(U8G2_R0
, D5
, D6
, U8X8_PIN_NONE
);
void setup(void) {
u8g2
.begin();
}
void loop(void) {
u8g2
.firstPage();
do {
u8g2
.setFont(u8g2_font_ncenB10_tr
);
u8g2
.drawStr(0,24,"Hello new World!");
} while ( u8g2
.nextPage() );
}