|
本帖最后由 86852335 于 2019-5-4 10:36 编辑
请大神帮忙分析下,遇到奇怪问题,在arduino 1.8.7 u8g2版本忘记了,程序可正常运行
换新版后,I2C通讯遇到问题,使用 Wire.begin(); 显示屏不能显示,不使用反而能显示,好像只要是与 .begin 初始化相关的都会导致显示屏幕不显示。贴出的程序可以直接运行可显示,无报错, 去掉 // 注释后,无报错但是显示屏无输出了
[mw_shl_code=arduino,true]/*
ATMEL328PAU - SSD1306_12864 - HTU21D
通信方式: I2C
-VCC D3231SN & SSD306_12864 = 5.0V
-VCC HTU21D = 3.3V
-GND = GND
-SDA = A4
-SCL = A5
*/
#include <Arduino.h>
#include <U8g2lib.h>
#include <Wire.h>
#include <HTU21D.h>
HTU21D myHumidity;
/* 年 Zfull-GB7; 小六 点阵为:宽x高=8x9 */
static const unsigned char nian[] =
{ 0x00,0x04,0xFC,0x12,0x7D,0x14,0xFF,0x10,0x10 };
/* 月 Zfull-GB7; 小六 点阵为:宽x高=8x9 */
static const unsigned char yue[] =
{ 0x00,0x7E,0x42,0x7E,0x42,0x7E,0x42,0x52,0x61 };
/* 日 Zfull-GB7; 小六 点阵为:宽x高=8x9 */
static const unsigned char ri[] =
{ 0x00,0x00,0x7E,0x42,0x42,0x7E,0x42,0x42,0x7E };
/* ℃ Zfull-GB7; 小六 点阵为:宽x高=8x9 */
static const unsigned char du[] =
{ 0x00,0x62,0x95,0x0A,0x08,0x08,0x08,0x90,0x60 };
/* % MS Sans Serif8; 点阵为:宽x高=8x13*/
static const unsigned char bai[] =
{ 0x00,0x00,0x0C,0x92,0x4C,0x20,0x10,0x08,0x64,0x92,0x60,0x00,0x00 };
U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE);
void setup(void) {
//Wire.begin();
//myHumidity.begin();
u8g2.begin();
delay(100);
}
void loop(void) {
//float humd = myHumidity.readHumidity();
//float temp = myHumidity.readTemperature();
u8g2.firstPage(); do {
u8g2.setFontDirection(0);
u8g2.clearBuffer();
u8g2.setCursor(10, 60);
u8g2.setFont(u8g2_font_6x13_tf);
//u8g2.print(temp, 1);
u8g2.print("23");
u8g2.drawXBM(24, 50, 8, 9, du);
u8g2.setCursor(60, 60);
//u8g2.print(humd, 1);
u8g2.print("23");
u8g2.drawXBM(80, 50, 8, 13, bai);
u8g2.sendBuffer();
} while (u8g2.nextPage() );
delay(450);
}[/mw_shl_code]
|
|