写文章也是为了记录自己的学习过程,顺便给后来人指指路,迷路了可别怪我~~~~~~
开发环境:PLATFORMIO
1、首先上一张我用的ESP8266开发板ESP-12E
首先新建一个工程,输入项目名称,选择自己所用的开发板,
的
U8G2_SSD1306_128X64_NONAME_1_SW_I2C u8g2(U8G2_R0, /* clock=SCL*/ 14, /* data=SDA*/ 2, /* reset=*/ U8X8_PIN_NONE);
这里我选了一个时钟的示例程序如下所示,傻傻的复制过来一运行发现报错额,原来是需要根据自己的板子选择一个其驱动类
构造器的名字包括以下几方面:
U8G2是前缀,
SSD1306是显示器的驱动芯片型号,
128X64_NONAME显示器像素,
1表示缓存大小Buffer Size,可取如下:
1 保持一页的缓冲区,用于firstPage/nextPage的PageMode.
2 保持两页的缓冲区,用于firstPage/nextPage的PageMode…
F 获取整个屏幕的缓冲区,ram消耗大,一般用在ram空间比较大的arduino板子.
4W_SW_SPI表示的是Communication通信协议:
4W_SW_SPI 4-wire (clock, data, cs and dc) software emulated SPI
4W_HW_SPI 4-wire (clock, data, cs and dc) hardware SPI (based on Arduino SPI library)
2ND_4W_HW_SPI If supported, second 4-wire hardware SPI (based on Arduino SPI library)
3W_SW_SPI 3-wire (clock, data and cs) software emulated SPI
SW_I2C Software emulated I2C/TWI
HW_I2C Hardware I2C based on the Arduino Wire library
2ND_HW_I2C If supported, use second hardware I2C (Arduino Wire lib)
6800 8-bit parallel interface, 6800 protocol
8080 8-bit parallel interface, 8080 protocol
参数除了第一个,后面的看注释就知道是什么意思了,但要注意填写的数字是ESP8266的GPIOx的数字x。
#include
#include
#ifdef U8X8_HAVE_HW_SPI
#include
#endif
#ifdef U8X8_HAVE_HW_I2C
#include
#endif
//我的板子驱动类如下所示
U8G2_SSD1306_128X64_NONAME_1_SW_I2C u8g2(U8G2_R0, /* clock=SCL*/ 14, /* data=SDA*/ 2, /* reset=*/ U8X8_PIN_NONE); //
// End of constructor list
void setup(void) {
/* U8g2 Project: SSD1306 Test Board */
//pinMode(10, OUTPUT);
//pinMode(9, OUTPUT);
//digitalWrite(10, 0);
//digitalWrite(9, 0);
/* U8g2 Project: T6963 Test Board */
//pinMode(18, OUTPUT);
//digitalWrite(18, 1);
/* U8g2 Project: KS0108 Test Board */
//pinMode(16, OUTPUT);
//digitalWrite(16, 0);
/* U8g2 Project: LC7981 Test Board, connect RW to GND */
//pinMode(17, OUTPUT);
//digitalWrite(17, 0);
/* U8g2 Project: Pax Instruments Shield: Enable Backlight */
//pinMode(6, OUTPUT);
//digitalWrite(6, 0);
u8g2.begin();
}
uint8_t m = 24;
void loop(void) {
char m_str[3];
strcpy(m_str, u8x8_u8toa(m, 2)); /* convert m to a string with two digits */
u8g2.firstPage();
do {
u8g2.setFont(u8g2_font_logisoso62_tn);
u8g2.drawStr(0,63,"9");
u8g2.drawStr(33,63,":");
u8g2.drawStr(50,63,m_str);
} while ( u8g2.nextPage() );
delay(1000);
m++;
if ( m == 60 )
m = 0;
}
运行效果图