标题: Arduino为什么无法用u8g2驱动12864OLED屏?求找出错误 [打印本页]

作者: CyanKing    时间: 2019-7-30 14:25
标题: Arduino为什么无法用u8g2驱动12864OLED屏?求找出错误
前几日入手了一块中景园的2.42寸12864OLED屏。
驱动芯片为SSD1309。通信方式为SPI
用arduino IDE装了个OLED屏驱动库U8G2。
但在Esp8266(nodemcu)上跑库中的例程时,怎么也无法使得屏幕显示。
软件SPI和硬件SPI都试过,都不行。
检查了SCL和SDA管脚,发现管脚上的电平是正常的。
求大神解答。

我使用的代码如下:
引脚:
SCL:D4
SDA:D3
DC:D2
CS:D1
RES:D0

#include <Arduino.h>
#include <U8g2lib.h>

#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif

U8G2_SSD1309_128X64_NONAME0_1_4W_SW_SPI u8g2(U8G2_R0,D4,D3, /* cs=*/ D1, /* dc=*/ D2, /* reset=*/ D0);

void setup(void) {
  u8g2.begin();
  u8g2.enableUTF8Print();   // enable UTF8 support for the Arduino print() function
}

void loop(void) {
  u8g2.setFont(u8g2_font_unifont_t_chinese2);  // use chinese2 for all the glyphs of "你好世界"
  u8g2.setFontDirection(0);
  u8g2.firstPage();
  do {
    u8g2.setCursor(0, 15);
    u8g2.print("Hello World!");
    u8g2.setCursor(0, 40);
    u8g2.print("你好世界");   // Chinese "Hello World"
  } while ( u8g2.nextPage() );
  delay(1000);
}

1.jpg (126.83 KB, 下载次数: 46)

1.jpg

2.jpg (112.3 KB, 下载次数: 52)

2.jpg

作者: bonarm    时间: 2019-9-9 15:46
你少了一句:
u8g2.sendBuffer();  




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1