天天看点

nodemcu(esp8266)u8g2 oled显示汉字获取网络时间

我的OLED是1.3寸128×64点阵,驱动是SH1106 I2C接口,我用的U8G2的模块,u8G2有16×16的汉字,Chinese1,chinese2,chinese3,三个汉字字体,是unicode编码,不过我发现汉字不全,只有很少一部分,用DrewGlyph显示。有知道的欢迎讨论。本来分两个文件,发现问题比较多,现在用一个init.lua文件,发现是可以的,连接热点后,可以同步时间,并且在OLED上显示出来,显示正常,程序如下:I2C用的1,2为数据端。时间刷新10S,也可设短,但是改程序,不好传进去。

function init_OLED(sda,scl)

     sla = 0x3c

     i2c.setup(0, sda, scl, i2c.SLOW)

     disp=u8g2.sh1106_i2c_128x64_noname(0,sla)

     disp:setFontPosTop()

end

function print_OLED()

 disp:clearBuffer()

  disp:setFont(u8g2.font_unifont_t_chinese1)

   disp:drawGlyph(45, 3, 24180)

   disp:drawStr(1, 3, tostring(time["year"]))

    disp:drawStr(64, 3, tostring(time["mon"]))

     disp:drawStr(97, 3, tostring(time["day"]))

    disp:setFont(u8g2.font_unifont_t_chinese2)

   disp:drawGlyph(80, 3,26376)

 disp:setFont(u8g2.font_unifont_t_chinese2)

   disp:drawGlyph(115, 3,26085)

disp:drawLine(10,25,120,25)

   disp:setFont(u8g2.font_unifont_t_chinese2)

   disp:drawGlyph(44, 30,26102)

    disp:drawStr(28, 30, tostring(time["hour"]+8))

     disp:drawStr(60, 30, tostring(time["min"]))

      disp:drawStr(97, 30, tostring(time["sec"]))

  disp:setFont(u8g2.font_unifont_t_chinese1)

   disp:drawGlyph(80, 30, 20998)

   以上部分代吗,三天的时间,主要是做个总结,需要全部代码的。联系我,[email protected]

nodemcu(esp8266)u8g2 oled显示汉字获取网络时间

继续阅读