0
  • 聊天消息
  • 系统消息
  • 评论与回复
登录后你可以
  • 下载海量资料
  • 学习在线课程
  • 观看技术视频
  • 写文章/发帖/加入社区
会员中心
创作中心

完善资料让更多小伙伴认识你,还能领取20积分哦,立即完善>

3天内不再提示

使用arduino控制oled屏幕循环轮播显示两种不同的字样

工程师邓生 来源:续加仪 作者:续加仪 2022-09-29 16:14 次阅读

Arduino控制oled屏幕显示

oled屏幕

oled

连接线路

Oled-Arduino:

GND-GND

VCC-3v3

SCL-A4

SDA-A5

案例

使用arduino控制oled屏幕循环轮播显示两种不同的“续加仪”字样。

库使用

需要使用到已有库Wire、Adafruit_GFX、Adafruit_SSD1306,可直接在arduino中搜素安装

基本的用法如下:

//引入IIC通讯所需的Wire库文件

#include

// 引入驱动OLED0.96所需的库

#include

#include

// 参数依次为:屏幕像素宽、高、Wire对象、重置引脚

Adafruit_SSD1306 display(128, 64, &Wire, 4);

// 初始化OLED并设置其IIC地址为 0x3C

display.begin(SSD1306_SWITCHCAPVCC, 0x3C);

//设置光标位置

display.setCursor(0, 0);

//输出文字(西文);

display.print("hello Xujiayi!");

//显示

display.display();

自定义图形/文字输出:

static const unsigned char PROGMEM xu[] = {

0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x01,0x00,0x1C,0x00,0x03,0x80,0x18,0x00,

0x03,0x00,0x18,0x60,0x02,0x07,0xFF,0xF0,0x06,0x00,0x18,0x00,0x04,0x20,0x18,0x00,

0x0C,0x38,0x18,0x00,0x08,0x70,0x18,0x08,0x10,0x6F,0xFF,0xFC,0x31,0xC0,0x08,0x1C,

0x3E,0x82,0x0E,0x30,0x11,0x81,0xCC,0x20,0x01,0x00,0xCC,0x00,0x02,0x00,0x4C,0x00,

0x06,0x06,0x0C,0x00,0x04,0x03,0x8C,0x00,0x08,0xF1,0x8C,0x00,0x1F,0x01,0x08,0x18,

0x18,0x1F,0xFF,0xFC,0x00,0x00,0x08,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x18,0x00,

0x00,0xE0,0x37,0x00,0x1F,0x00,0x61,0xC0,0x38,0x00,0xC0,0x70,0x00,0x03,0x80,0x30,

0x00,0x0E,0x00,0x10,0x00,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};/*"续",0*/

// 显示文字 (左上x坐标,右上y坐标, 图形数组, 图形像素点宽、高, 颜色)

display.drawBitmap(0, 0, xu, 32, 32, 1);

其中图形数组的获取方法见下文。

取模

使用pctolcd软件即可完成:

b6dd5f52-3f9f-11ed-9e49-dac502259ad0.png
b6f7e8f4-3f9f-11ed-9e49-dac502259ad0.png

b71df6c0-3f9f-11ed-9e49-dac502259ad0.png

然后复制数据作为数组数据即可

实现

static const unsigned char PROGMEM xu[] = {

0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x01,0x00,0x1C,0x00,0x03,0x80,0x18,0x00,

0x03,0x00,0x18,0x60,0x02,0x07,0xFF,0xF0,0x06,0x00,0x18,0x00,0x04,0x20,0x18,0x00,

0x0C,0x38,0x18,0x00,0x08,0x70,0x18,0x08,0x10,0x6F,0xFF,0xFC,0x31,0xC0,0x08,0x1C,

0x3E,0x82,0x0E,0x30,0x11,0x81,0xCC,0x20,0x01,0x00,0xCC,0x00,0x02,0x00,0x4C,0x00,

0x06,0x06,0x0C,0x00,0x04,0x03,0x8C,0x00,0x08,0xF1,0x8C,0x00,0x1F,0x01,0x08,0x18,

0x18,0x1F,0xFF,0xFC,0x00,0x00,0x08,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x18,0x00,

0x00,0xE0,0x37,0x00,0x1F,0x00,0x61,0xC0,0x38,0x00,0xC0,0x70,0x00,0x03,0x80,0x30,

0x00,0x0E,0x00,0x10,0x00,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};/*"续",0*/

static const unsigned char PROGMEM jia[] = {

0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0xC0,0x00,0x00,0x01,0x80,0x00,0x00,

0x01,0x80,0x00,0x00,0x01,0x80,0x00,0x00,0x01,0x80,0x00,0x10,0x01,0x82,0x1F,0xF8,

0x3F,0xFF,0x10,0x18,0x01,0x83,0x10,0x18,0x01,0x82,0x10,0x18,0x01,0x82,0x10,0x18,

0x01,0x82,0x10,0x18,0x01,0x82,0x10,0x18,0x01,0x82,0x10,0x18,0x01,0x82,0x10,0x18,

0x01,0x82,0x10,0x18,0x01,0x82,0x10,0x18,0x01,0x02,0x10,0x18,0x01,0x02,0x10,0x18,

0x03,0x06,0x10,0x18,0x03,0x06,0x10,0x18,0x02,0x06,0x10,0x18,0x06,0x06,0x10,0x18,

0x04,0x06,0x10,0x18,0x0D,0x0C,0x1F,0xF8,0x08,0xFC,0x10,0x18,0x10,0x38,0x10,0x18,

0x20,0x10,0x10,0x18,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};/*"加",1*/

static const unsigned char PROGMEM yi[] = {

0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x70,0x80,0x00,0x00,0xE0,0x40,0x00,

0x00,0xC0,0x20,0x00,0x00,0xC0,0x30,0x00,0x01,0x80,0x38,0x40,0x01,0x80,0x18,0x60,

0x03,0x04,0x10,0xE0,0x03,0x04,0x00,0xC0,0x03,0x82,0x00,0x80,0x07,0x82,0x01,0x80,

0x0D,0x82,0x01,0x80,0x09,0x81,0x03,0x00,0x19,0x81,0x03,0x00,0x11,0x80,0x86,0x00,

0x21,0x80,0xC6,0x00,0x41,0x80,0x44,0x00,0x01,0x80,0x6C,0x00,0x01,0x80,0x28,0x00,

0x01,0x80,0x38,0x00,0x01,0x80,0x38,0x00,0x01,0x80,0x6C,0x00,0x01,0x80,0x46,0x00,

0x01,0x80,0x83,0x80,0x01,0x83,0x01,0xC0,0x01,0x86,0x00,0xF0,0x01,0x88,0x00,0x7E,

0x01,0xB0,0x00,0x30,0x01,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};/*"仪",2*/

static const unsigned char PROGMEM xu1[] = {

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x00,

0x00,0x60,0x38,0x00,0x00,0xE3,0xFF,0xC0,0x01,0xE3,0xFF,0xC0,0x07,0x80,0x38,0x30,

0x0E,0x37,0xFF,0xF0,0x1C,0xF7,0x00,0x70,0x1F,0xE1,0xCC,0x30,0x11,0xC0,0xEE,0x10,

0x03,0x03,0x0C,0x10,0x06,0xF3,0xCC,0x10,0x0F,0xC0,0x2C,0x00,0x0E,0x07,0xFF,0xFE,

0x00,0x7F,0xFF,0xFE,0x07,0xE0,0x38,0x3C,0x3F,0x80,0x77,0x00,0x7E,0x01,0xE7,0x80,

0x38,0x3F,0xC1,0xC0,0x00,0x1E,0x00,0xE0,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};/*"续",0*/

static const unsigned char PROGMEM jia1[] = {

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x00,

0x00,0x1C,0x00,0x00,0x03,0x18,0x00,0x00,0x07,0xF8,0x00,0x00,0x0F,0xFF,0x18,0x18,

0x00,0x3F,0xBF,0xF8,0x00,0x73,0xBF,0xF8,0x00,0x63,0xB8,0x38,0x00,0xE3,0x38,0x18,

0x00,0xC3,0x38,0x18,0x01,0xC3,0x38,0x18,0x03,0x87,0x38,0x18,0x03,0x86,0x38,0x38,

0x07,0x0E,0x3F,0xF8,0x1E,0x0E,0x1F,0xF8,0x3C,0x1C,0x00,0x00,0x78,0x78,0x00,0x00,

0x31,0xF8,0x00,0x00,0x01,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};/*"加",1*/

static const unsigned char PROGMEM yi1[] = {

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,

0x00,0x70,0xC3,0x00,0x03,0xE0,0xE3,0x80,0x7F,0xC0,0x63,0x80,0x7F,0x80,0x27,0x00,

0x7F,0x8E,0x07,0x00,0x33,0x8F,0x07,0x00,0x03,0x83,0xCE,0x00,0x03,0x81,0xEE,0x00,

0x03,0x80,0x7C,0x00,0x03,0x80,0x3C,0x00,0x03,0x80,0x3C,0x00,0x03,0x80,0x7F,0x00,

0x03,0x81,0xE7,0x80,0x03,0x87,0xC3,0xE0,0x03,0xFF,0x81,0xF8,0x03,0xBE,0x00,0xFF,

0x03,0x80,0x00,0xFE,0x03,0x80,0x00,0x7C,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};/*"仪",2*/

//引入IIC通讯所需的Wire库文件

#include

// 引入驱动OLED0.96所需的库

#include

#include

// 参数依次为:屏幕像素宽、高、Wire对象、重置引脚

Adafruit_SSD1306 display(128, 64, &Wire, 4);

void setup()

{

// 初始化OLED并设置其IIC地址为 0x3C

display.begin(SSD1306_SWITCHCAPVCC, 0x3C);

}

int pos_x = 0;

void loop()

{

if(pos_x<256){

// 显示之前清屏

display.clearDisplay();

showCon(pos_x++);

showCon(pos_x-128);

//显示图形

display.display();

}else if(pos_x<512){

// 显示之前清屏

display.clearDisplay();

showCon1(pos_x++-256);

showCon1(pos_x-256-128);

//显示图形

display.display();

}else

pos_x=0;

}

void showCon(int x)

{

display.drawBitmap(x, 16, xu, 32, 32, 1);

display.drawBitmap(x+32, 16, jia, 32, 32, 1);

display.drawBitmap(x+64, 16, yi, 32, 32, 1);

}

void showCon1(int x)

{

display.drawBitmap(x+0, 16, xu1, 32, 32, 1);

display.drawBitmap(x+32, 16, jia1, 32, 32, 1);

display.drawBitmap(x+64, 16, yi1, 32, 32, 1);

}




审核编辑:刘清

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
  • OLED屏幕
    +关注

    关注

    3

    文章

    206

    浏览量

    27959
  • Arduino
    +关注

    关注

    187

    文章

    6456

    浏览量

    186467
  • GND
    GND
    +关注

    关注

    2

    文章

    527

    浏览量

    38616

原文标题:Arduino控制oled屏幕显示自定义字体文字

文章出处:【微信号:续加仪,微信公众号:续加仪】欢迎添加关注!文章转载请注明出处。

收藏 人收藏

    评论

    相关推荐

    用单片机编写控制OLED屏幕驱动显示

    单片机OLEDOLED屏幕OLED显示技术
    jf_76415565
    发布于 :2022年09月13日 21:41:08

    OLED显示流程(简析)

    ;)和OLED_Refresh_Gram();,(63和48是字符串在屏幕显示的位置,这里我们不管他。。)这条语句的拆解步骤如下:1、既然是显示
    发表于 05-07 20:26

    labview的两种循环

    可以将其中的几种结合到一起来完成复杂的程序流程。 两种循环  如果使用过其他编程语言的话,对于需要重复执行的代码要怎么处理可能就会想到循环结构。在LabVIEW里面提供了两种
    发表于 05-29 07:40

    显示屏幕主要有LED、LCD、OLED、AMOLED、TFT这五

    显示屏幕主要有LED、LCD、OLED、AMOLED、TFT这五,在什么场合选用哪种屏幕更合适呢?它们的驱动电路有哪些需要注意的地方?
    发表于 08-10 18:02

    基于stm32f103与IIC的0.96OLED屏幕显示字符与平滑滚动显示 精选资料推荐

    、效果演示一、0.96OLED屏幕简介1、类型区分及接线模块有7针和4针两种,下面的是7针模块,主要引脚与4针相同2、IIC通信原理关于IIC在之前的文章AHT20与stm32中介绍过,这里只做主要的时序介绍。IIC总线开始信号
    发表于 08-24 06:42

    介绍两种基于Arduino的风扇自动调速方案

    话不多说,夏天到了,天气逐渐热起来,风扇成了必不可少的消暑利器。本文主要介绍两种基于Arduino的风扇自动调速方案,使用的是5V的USB风扇,物美价廉还省电。方案一是通过舵机控制旋钮变压器实现调速
    发表于 09-08 06:20

    各种OLED屏幕的使用方式的总结

    本文主要是笔者在学习单片机过程中,所遇各种OLED屏幕的使用方式的总结归纳。关于SSD1306驱动的OLED屏幕开源程序有很多,其与单片机通信的方式主要有
    发表于 12-07 07:38

    单个GPIO控制两种LED交替显示的过程

    今天在看单片机的时候发现引脚不够用了,就想到一个可以用单个引脚来控制两种灯色显示。不多说了,下面上图:
    发表于 02-14 06:03

    Arduino UNO机械开关和OLED屏幕护罩的资料分享

    描述Arduino UNO机械开关和OLED屏幕护罩材料:4 个 10 欧姆电阻。4 个机械键盘开关。1x Arduino UNO20x 通用引脚。1x
    发表于 08-30 06:54

    分析lcd屏幕oled屏幕之间的区别

    屏幕是手机上重要的一个部分,就仿佛就是人类的一张脸,通过色彩的精细程度与分辨率给用户呈现视觉画面。目前手机采用的屏幕的主流材质为发展技术成熟传统的LCD屏幕,和采用最新技术并在手机界普及开来的
    发表于 10-29 16:20 5w次阅读

    手机LCD屏幕OLED屏幕性能测试测试专家——大电流弹片微针模组

    手机屏幕也称显示屏,主要用于显示图像和色彩,LCD屏、OLED屏作为目前主流的手机屏幕材质,因为这两种
    发表于 05-06 09:44 2538次阅读

    单个GPIO控制两种LED交替显示

    今天在看单片机的时候发现引脚不够用了,就想到一个可以用单个引脚来控制两种灯色显示。不多说了,下面上图:
    发表于 12-08 19:06 5次下载
    单个GPIO<b class='flag-5'>控制</b><b class='flag-5'>两种</b>LED交替<b class='flag-5'>显示</b>

    Arduino UNO机械开关和OLED屏幕护罩开源分享

    电子发烧友网站提供《Arduino UNO机械开关和OLED屏幕护罩开源分享.zip》资料免费下载
    发表于 08-11 09:33 0次下载
    <b class='flag-5'>Arduino</b> UNO机械开关和<b class='flag-5'>OLED</b><b class='flag-5'>屏幕</b>护罩开源分享

    Hello Alexa使用OLED显示模块和Arduino

    电子发烧友网站提供《Hello Alexa使用OLED显示模块和Arduino.zip》资料免费下载
    发表于 11-10 10:37 1次下载
    Hello Alexa使用<b class='flag-5'>OLED</b><b class='flag-5'>显示</b>模块和<b class='flag-5'>Arduino</b>

    Micro OLED和Micro LED两种显示技术有哪些不同?

    Micro OLED和Micro LED两种显示技术有哪些不同? Micro OLED和Micro LED是两种不同的
    的头像 发表于 12-11 14:26 6543次阅读