Arduino使用OLED显示内容
来源:互联网 发布:想开个淘宝店 编辑:程序博客网 时间:2024/05/29 18:31
之前买了一块OLED,128×64,芯片为SSD1306,IIC接口
给的资料很少,网上找到支持库为U8glib,貌似这个已经很久不更新了
新的库叫U8g2,可以直接在Arduino库中找到并下载
下载了U8glib,发现例子基本都是SPI接口的,IIC的
U8glib例子中没有IIC的接口使用方法,到处找资料
硬件连接为A5-SCL,A4-SDA,并且定义如下
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE);
几个常用的方法:
u8g.setRot90(); //旋转90°u8g.setRot180(); //旋转180°u8g.setRot270(); //旋转270°u8g.undoRotation(); //取消旋转u8g.setFont(u8g_font_osb18); //设置字体u8g.drawStr(0, 20, "ABC"); //画出字符在(0,20)的位置u8g.setPrintPos(0,15); //设置位置u8g.print("Error Code: "); //打印内容u8g.drawBitmapP( 0, 0, 1, 9, bitmap); //画位图,每行一个字节(8个点),总共9行,数据定义在bitmap[]u8g.drawXBMP( 0, 0, 38, 24, bitmap); //画位图,38×24,数据定义在bitmap[]// 还有一个需要注意的地方,u8g有缓存,所以一般显示要使用下面的方法,将绘图函数放到draw()中void loop(void) { // picture loop u8g.firstPage(); do { draw(); } while( u8g.nextPage() ); // rebuild the picture after some delay delay(1000);}
后面又下载了U8g2,功能更强大了,提供了对话框什么的,直接使用例子就行,非常方便
#include <u8x8lib.h>U8X8_SSD1306_128X64_NONAME_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE);void setup(void){ // 定义输入按键 u8x8.begin(/*Select=*/ 7, /*Right/Next=*/ A1, /*Left/Prev=*/ A2, /*Up=*/ A0, /*Down=*/ A3, /*Home/Cancel=*/ 8);}void loop(void){ uint8_t r; u8x8.setFont(u8x8_font_chroma48medium8_r); r = u8x8_UserInterfaceMessage(u8x8.getU8x8(), "Message", "Box", NULL, " Ok \n Cancel "); if ( r == 0 ) { u8x8.userInterfaceMessage("You pressed the", "Home/Quit", "Button", " Ok "); } else if ( r == 1 ) { u8x8.userInterfaceMessage("You selected the", "Ok", "Button", " Ok "); } else if ( r == 2 ) { u8x8.userInterfaceMessage("You selected the", "Cancel", "Button", " Ok "); }}
阅读全文
0 0
- Arduino使用OLED显示内容
- Arduino Uno 驱动OLED进阶 显示图片
- Arduinoの温湿度OLED及串口显示
- Arduino Uno 驱动OLED进阶 显示中英文字
- Arduino Uno 驱动OLED进阶 显示几何动画
- 【Arduino】【MATLAB】用ssd1306 oled屏显示任意图片
- Arduino Nano下使用u8glib点亮Oled 128x6
- Arduino--基础(三)--0.96英寸的OLED的使用
- GPS OLED DHT11 Arduino
- Arduino驱动SSD1306 OLED
- arduino+oled测试实验
- Intel Edison arduino代码驱动OLED(SSD1306)
- OLED显示汉字
- oled显示中文字母
- OLED显示小数
- 单片机显示方案-OLED
- arduino使用液晶1602来显示字母
- OLED屏使用
- RabbitMQ官方中文入门教程(PHP版) 第一部分:Hello World
- nodejs 客户端拍照调用azure face api对比身份证照片进行验证
- (BP进阶1)从M-P模型到BP神经网络
- 知识图谱之入门篇
- maven依赖包下载失败解决办法
- Arduino使用OLED显示内容
- postman-api自动化调试图解
- Number String UVA
- 小甲鱼python 基础
- 汇编指令
- CentOS安装Maven
- HDU1234-开门人和关门人-水
- opencv源码编译
- 简述 典型处理器(如Cortex A9)中一条存储器读写指令的执行全过程