【Arduino教程】使用u8g2驱动图形显示器-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 97878|回复: 250

[教程] 【Arduino教程】使用u8g2驱动图形显示器

  [复制链接]
发表于 2016-12-24 22:19 | 显示全部楼层 |阅读模式
在《Arduino程序设计基础》上介绍过u8glib这个arduino上最最牛逼的开源图形显示器驱动库:
使用U8glib驱动12864图形液晶显示器   http://www.arduino.cn/thread-20081-1-1.html
u8g2显示图片教程:http://www.arduino.cn/thread-42174-1-1.html


但这里要使用的不是u8glib,而是新一代的u8g——u8g2,其和u8glib有诸多不同:

----------------------------------------------------------------------
Full "RAM" memory buffer without picture loop
Arduino SPI and TWI Libraries instead of custom code
Support for Unicode and UTF-8
Faster compilation
High speed text only API (U8x8)
Hardware 180 degree rotation for some displays available
----------------------------------------------------------------------

本教程使用的显示设备——Openjumper出品的OLED模块
https://item.taobao.com/item.htm?id=43554060969

1.安装u8g2
·通过IDE自带的库管理器,搜索 u8g2,点击安装即可。
Arduino IDE使用——通过库管理器添加引用库   http://www.arduino.cn/thread-17883-1-1.html
·也可以通过以下链接下载u8g2:
https://github.com/olikraus/U8g2_Arduino/archive/master.zip

2.准备显示设备并连接到Arduino
在u8g2中,不同的显示设备对应不同的构造函数。
教程中使用的设备为 OpenJumper OLED模块

3.可使用两种类实例化一个显示器对象
u8g2提供了两类api——u8g2和u8x8,前者是标准完备的u8g api,后者是高效精简api。
对于OpenJumper OLED模块,可以使用如下语句进行实例化:
[mw_shl_code=cpp,true]
U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, SCL, SDA,resetPin);
U8X8_SSD1306_128X64_NONAME_SW_I2C u8x8(SCL,SDA,resetPin);
[/mw_shl_code]

4.使用例程即可了解如何开发

这里提供一个显示中文的例程:
[mw_shl_code=cpp,true]#include <Arduino.h>
#include <U8g2lib.h>

Reset_Pin=2;

U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0,SCL,SDA,Reset_Pin);

void setup(void) {
  u8g2.begin();
  u8g2.enableUTF8Print();
}

void loop(void) {
  u8g2.setFont(u8g2_font_unifont_t_chinese2);
  u8g2.setFontDirection(0);
  u8g2.clearBuffer();
  u8g2.setCursor(0, 15);
  u8g2.print("www.arduino.cn");
  u8g2.setCursor(0, 40);
  u8g2.sendBuffer();
  delay(1000);
}
[/mw_shl_code]
附 字表:
1.请注意,你使用的中文必须在表中,且在print前,使用setFont选中对应的字表,如:
  [mw_shl_code=cpp,true] u8g2.setFont(u8g2_font_unifont_t_chinese2);
u8g2.print("凹凸"); [/mw_shl_code]
2.使用中文会消耗大量的内存,更建议你使用Arduino 101、due等高配版的arduino。






QQ截图20161224221204.jpg
发表于 2016-12-24 23:46 | 显示全部楼层
顶一下看看
发表于 2016-12-25 10:53 | 显示全部楼层
教程在哪里?
发表于 2016-12-25 14:27 | 显示全部楼层
Support for Unicode and UTF-8
关键是能不能出个支持中文字符的教程。

点评

我也在研究怎么显示中文  详情 回复 发表于 2016-12-25 21:08
 楼主| 发表于 2016-12-25 21:08 | 显示全部楼层
Waston 发表于 2016-12-25 14:27
Support for Unicode and UTF-8
关键是能不能出个支持中文字符的教程。

我也在研究怎么显示中文
发表于 2016-12-26 13:41 | 显示全部楼层
谢谢分享                       
发表于 2016-12-26 15:58 | 显示全部楼层
谢谢楼主分享啊
发表于 2016-12-26 17:10 | 显示全部楼层
谢谢分享     
发表于 2016-12-26 19:55 | 显示全部楼层
谢谢奉献哈哈哈
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2024-9-20 21:42 , Processed in 0.136917 second(s), 27 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表