Arduino使用教程 基于UNO PLUS的例程 Arduino OLED教程

arduino使用教程 提供基于uno plus的例程
硬件连接 我们提供的例程是基于uno plus的,提供的连接方式也是对应的uno plus的引脚,如果需要移植程序,请按实际引脚连接
oled uno
vcc 3.3v/5v
gnd gnd
din spi:d11 / i2c:sda
clk spi:d13 / i2c:scl
cs d10
dc d7
rst d8
四线spi接线图:
arduino ide 安装教程 arduino ide 安装教程
运行程序 下载程序,找到arduino程序文件目录。
使用arduino ide打开对应型号的工程文件夹下的 .ino 文件,重新编译下载即可。
例如您购买的是 1.3inch oled module (c) 就打开 \arduino\oled_1in3_c 目录下的 oled_1in3_c.ino
软件说明 下载程序,打开arduino程序文件目录,即可看到不同型号oled的arduino程序,具体对应关系可以看下方‘型号程序对应表’
根据你购买的尺寸和类型选择打开的文件夹,并打开 xxx.ino 文件,我们以1.3inch oled module (c)为例:打开oled_1in3_c,然后双击 oled_1in3_c.ino 打开arduino的工程。
型号程序对应表 屏幕型号 程序文件夹
0.91inch oled module oled_0in91
0.95inch rgb oled (a)/(b) oled_0in95_rgb
0.96inch oled (a)/(b) oled_0in96
1.3inch oled (a)/(b) oled_1in3
1.3inch oled module (c) oled_1in3_c
1.5inch oled module oled_1in5
1.5inch rgb oled module oled_1in5_rgb
程序说明 底层硬件接口 我们进行了底层的封装,由于硬件平台不一样,内部的实现是不一样的,如果需要了解内部实现可以去对应的目录中查看 在dev_config.c(.h)可以看到很多定义
接口选择: #define use_spi_4w  1 #define use_iic     0 注意:切换spi/i2c直接修改这里
数据类型: #define ubyte   uint8_t #define uword   uint16_t #define udouble uint32_t
模块初始化与退出的处理: ubyte system_init(void); void    system_exit(void); 注意: 1.这里是处理使用液晶屏前与使用完之后一些gpio的处理; 2.system_exit函数使用后,会关闭oled显示屏;
gpio读写: void dev_digital_write(uword pin, ubyte value); ubyte dev_digital_read(uword pin);
spi写数据 ubyte spi4w_write_byte(uint8_t value);
iic写数据: void i2c_write_byte(uint8_t value, uint8_t cmd);
上层应用 对于屏幕而言,如果需要进行画图、显示中英文字符、显示图片等怎么办,这些都是上层应用做的。这有很多小伙伴有问到一些图形的处理,我们这里提供了一些基本的功能 在如下的目录中可以找到gui和其自带的字库,在目录:arduino\oled_xxx\gui_paint.c(.h)
新建图像属性:新建一个图像属性,这个属性包括图像缓存的名称、宽度、高度、翻转角度、颜色 void paint_newimage(uword width, uword height, uword rotate, uword color); 参数: width : 图像缓存的宽度; height: 图像缓存的高度; rotate:图像的翻转的角度 color :图像的初始颜色;
设置清屏函数,通常直接调用oled的clear函数; void paint_setclearfuntion(void (*clear)(uword)); 参数: clear : 指向清屏函数的指针,用于快速将屏幕清空变成某颜色;
设置画像素点函数; void paint_setdisplayfuntion(void (*display)(uword,uword,uword)); 参数: display: 指向画像素点函数的指针,用于向oled内部ram指定位置写入数据;
选择图像缓存:选择图像缓存,选择的目的是你可以创建多个图像属性,图像缓存可以存在多个,你可以选择你所创建的每一张图像 void paint_selectimage(ubyte *image) 参数: image: 图像缓存的名称,实际上是一个指向图像缓存首地址的指针;
图像旋转:设置选择好的图像的旋转角度,最好使用在paint_selectimage()后,可以选择旋转0、90、180、270 void paint_setrotate(uword rotate) 参数: rotate: 图像选择角度,可以选择rotate_0、rotate_90、rotate_180、rotate_270分别对应0、90、180、270度
图像镜像翻转:设置选择好的图像的镜像翻转,可以选择不镜像、关于水平镜像、关于垂直镜像、关于图像中心镜像。 void paint_setmirroring(ubyte mirror) 参数: mirror: 图像的镜像方式,可以选择mirror_none、mirror_horizontal、mirror_vertical、mirror_origin分别对应不镜像、关于水平镜像、关于垂直镜像、关于图像中心镜像
设置点在缓存中显示位置和颜色:这里是gui最核心的一个函数、处理点在缓存中显示位置和颜色; void paint_setpixel(uword xpoint, uword ypoint, uword color) 参数: xpoint: 点在图像缓存中x位置 ypoint: 点在图像缓存中y位置 color : 点显示的颜色
图像缓存填充颜色:把图像缓存填充为某颜色,一般作为屏幕刷白的作用 void paint_clear(uword color) 参数: color: 填充的颜色
图像缓存部分窗口填充颜色:把图像缓存的某部分窗口填充为某颜色,一般作为窗口刷白的作用,常用于时间的显示,刷白上一秒 void paint_clearwindows(uword xstart, uword ystart, uword xend, uword yend, uword color) 参数: xstart: 窗口的x起点坐标 ystart: 窗口的y起点坐标 xend: 窗口的x终点坐标 yend: 窗口的y终点坐标 color: 填充的颜色
画点:在图像缓存中,在(xpoint, ypoint)上画点,可以选择颜色,点的大小,点的风格 void paint_drawpoint(uword xpoint, uword ypoint, uword color, dot_pixel dot_pixel, dot_style dot_style) 参数: xpoint: 点的x坐标 ypoint: 点的y坐标 color: 填充的颜色 dot_pixel: 点的大小,提供默认的8种大小点 typedef enum { dot_pixel_1x1  = 1, // 1 x 1 dot_pixel_2x2  , // 2 x 2 dot_pixel_3x3  , // 3 x 3 dot_pixel_4x4  , // 4 x 4 dot_pixel_5x5  , // 5 x 5 dot_pixel_6x6  , // 6 x 6 dot_pixel_7x7  , // 7 x 7 dot_pixel_8x8  , // 8 x 8 } dot_pixel; dot_style: 点的风格,大小扩充方式是以点为中心扩大还是以点为左下角往右上扩大 typedef enum {   dot_fill_around  = 1,   dot_fill_rightup, } dot_style;
画线:在图像缓存中,从 (xstart, ystart) 到 (xend, yend) 画线,可以选择颜色,线的宽度,线的风格 void paint_drawline(uword xstart, uword ystart, uword xend, uword yend, uword color, line_style line_style , line_style line_style) 参数: xstart: 线的x起点坐标 ystart: 线的y起点坐标 xend: 线的x终点坐标 yend: 线的y终点坐标 color: 填充的颜色 line_width: 线的宽度,提供默认的8种宽度 typedef enum { dot_pixel_1x1  = 1, // 1 x 1 dot_pixel_2x2  , // 2 x 2 dot_pixel_3x3  , // 3 x 3 dot_pixel_4x4  , // 4 x 4 dot_pixel_5x5  , // 5 x 5 dot_pixel_6x6  , // 6 x 6 dot_pixel_7x7  , // 7 x 7 dot_pixel_8x8  , // 8 x 8 } dot_pixel; line_style: 线的风格,选择线是以直线连接还是以虚线的方式连接 typedef enum { line_style_solid = 0, line_style_dotted, } line_style;
画矩形:在图像缓存中,从 (xstart, ystart) 到 (xend, yend) 画一个矩形,可以选择颜色,线的宽度,是否填充矩形内部 void paint_drawrectangle(uword xstart, uword ystart, uword xend, uword yend, uword color, dot_pixel line_width, draw_fill draw_fill) 参数: xstart: 矩形的x起点坐标 ystart: 矩形的y起点坐标 xend: 矩形的x终点坐标 yend: 矩形的y终点坐标 color: 填充的颜色 line_width: 矩形四边的宽度,提供默认的8种宽度 typedef enum { dot_pixel_1x1  = 1, // 1 x 1 dot_pixel_2x2  , // 2 x 2 dot_pixel_3x3  , // 3 x 3 dot_pixel_4x4  , // 4 x 4 dot_pixel_5x5  , // 5 x 5 dot_pixel_6x6  , // 6 x 6 dot_pixel_7x7  , // 7 x 7 dot_pixel_8x8  , // 8 x 8 } dot_pixel; draw_fill: 填充,是否填充矩形的内部 typedef enum { draw_fill_empty = 0, draw_fill_full, } draw_fill;
画圆:在图像缓存中,以 (x_center y_center) 为圆心,画一个半径为radius的圆,可以选择颜色,线的宽度,是否填充圆内部 void paint_drawcircle(uword x_center, uword y_center, uword radius, uword color, dot_pixel line_width, draw_fill draw_fill) 参数: x_center: 圆心的x坐标 y_center: 圆心的y坐标 radius:圆的半径 color: 填充的颜色 line_width: 圆弧的宽度,提供默认的8种宽度 typedef enum { dot_pixel_1x1  = 1, // 1 x 1 dot_pixel_2x2  , // 2 x 2 dot_pixel_3x3  , // 3 x 3 dot_pixel_4x4  , // 4 x 4 dot_pixel_5x5  , // 5 x 5 dot_pixel_6x6  , // 6 x 6 dot_pixel_7x7  , // 7 x 7 dot_pixel_8x8  , // 8 x 8 } dot_pixel; draw_fill: 填充,是否填充圆的内部 typedef enum { draw_fill_empty = 0, draw_fill_full, } draw_fill;
写ascii字符:在图像缓存中,在 (xstart ystart) 为左顶点,写一个ascii字符,可以选择ascii码可视字符字库、字体前景色、字体背景色 void paint_drawchar(uword xstart, uword ystart, const char ascii_char, sfont* font, uword color_foreground, uword color_background) 参数: xstart: 字符的左顶点x坐标 ystart: 字体的左顶点y坐标 ascii_char:ascii字符 font: ascii码可视字符字库,在fonts文件夹中提供了以下字体: font8:5*8的字体 font12:7*12的字体 font16:11*16的字体 font20:14*20的字体 font24:17*24的字体 color_foreground: 字体颜色 color_background: 背景颜色
写英文字符串:在图像缓存中,在 (xstart ystart) 为左顶点,写一串英文字符,可以选择ascii码可视字符字库、字体前景色、字体背景色 void paint_drawstring_en(uword xstart, uword ystart, const char * pstring, sfont* font, uword color_foreground, uword color_background) 参数: xstart: 字符的左顶点x坐标 ystart: 字体的左顶点y坐标 pstring:字符串,字符串是一个指针 font: ascii码可视字符字库,在fonts文件夹中提供了以下字体: font8:5*8的字体 font12:7*12的字体 font16:11*16的字体 font20:14*20的字体 font24:17*24的字体 color_foreground: 字体颜色 color_background: 背景颜色
写中文字符串:在图像缓存中,在 (xstart ystart) 为左顶点,写一串中文字符,可以选择gb2312编码字符字库、字体前景色、字体背景色; void paint_drawstring_cn(uword xstart, uword ystart, const char * pstring, cfont* font, uword color_foreground, uword color_background) 参数: xstart: 字符的左顶点x坐标 ystart: 字体的左顶点y坐标 pstring:字符串,字符串是一个指针 font: gb2312编码字符字库,在fonts文件夹中提供了以下字体: font12cn:ascii字符字体11*21,中文字体16*21 font24cn:ascii字符字体24*41,中文字体32*41 color_foreground: 字体颜色 color_background: 背景颜色
写数字:在图像缓存中,在 (xstart ystart) 为左顶点,写一串数字,可以选择ascii码可视字符字库、字体前景色、字体背景色 void paint_drawnum(uword xpoint, uword ypoint, double nummber, sfont* font, uword digit, uword color_foreground, uword color_background) 参数: xpoint: 字符的左顶点x坐标 ypoint: 字体的左顶点y坐标 nummber:显示的数字,可以是小数        digit:小数位数,不足补零 font: ascii码可视字符字库,在fonts文件夹中提供了以下字体: font8:5*8的字体 font12:7*12的字体 font16:11*16的字体 font20:14*20的字体 font24:17*24的字体 color_foreground: 字体颜色 color_background: 背景颜色
显示时间:在图像缓存中,在 (xstart ystart) 为左顶点,显示一段时间,可以选择ascii码可视字符字库、字体前景色、字体背景色; void paint_drawtime(uword xstart, uword ystart, paint_time *ptime, sfont* font, uword color_background, uword color_foreground) 参数: xstart: 字符的左顶点x坐标 ystart: 字体的左顶点y坐标 ptime:显示的时间,这里定义好了一个时间的结构体,只要把时分秒各位数传给参数; font: ascii码可视字符字库,在fonts文件夹中提供了以下字体: font8:5*8的字体 font12:7*12的字体 font16:11*16的字体 font20:14*20的字体 font24:17*24的字体 color_foreground: 字体颜色 color_background: 背景颜色

一份图谱告诉你学习自动驾驶的路径就是这么简单
骁龙8Gen1怎么样,骁龙8Gen1评测来袭
浅谈单模光纤的多模光纤的区别
J2CN-SPK-30W外挂FLASH串口语音播放模块说明
雷柏M100/M200鼠标评测 值不值得买
Arduino使用教程 基于UNO PLUS的例程 Arduino OLED教程
液晶电视维修:LED灯光电路图原理分析
自动驾驶汽车的未来趋势_汽车语音识别系统市场分析
“新基建”与5G加持,工业互联网发展潜力巨大
EFR32MG21助力打造产品更优性能
Type-C端口保护方案指南——就是更安全
5G带来了PCB需求的增长 促进了PCB产业的发展
Pyro开关:隐藏式红外检测
二氧化硫试验箱的技术参数
中国信通院发布国内手机市场总体情况
如果不是IBM所提供的系统,我们也就不可能登上月球
中芯国际不在为华为提供芯片制作华为芯片应该如何解决
各大企业是如何运用人工智能技术的
医疗废物全过程在线监测系统让医废监管智慧化
稳压二极管的选用和代换