【雕爷学编程】Arduino动手做(187)---1.3寸OLED液晶屏模块2

37款传感器与模块的提法,在网络上广泛流传,其实Arduino能够兼容的传感器模块肯定是不止37种的。鉴于本人手头积累了一些传感器和执行器模块,依照实践出真知(一定要动手做)的理念,以学习和交流为目的,这里准备逐一动手试试多做实验,不管成功与否,都会记录下来——小小的进步或是搞不掂的问题,希望能够抛砖引玉。

【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验一百八十七:1.3寸OLED液晶屏 I2C IIC通信 4针模块 1106/1306驱动 128*64像素

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

【Arduino】168种传感器模块系列实验(资料代码+图形编程+仿真编程)
实验一百八十一:1.3寸OLED液晶屏 I2C IIC通信 4针模块 1106/1306驱动 132*64像素
项目之三:基于Adafruit_SH1106库的标准屏幕测试

实验开源代码

/*【Arduino】168种传感器模块系列实验(资料代码+图形编程+仿真编程)实验一百八十一:1.3寸OLED液晶屏 I2C IIC通信 4针模块 1106/1306驱动 132*64像素项目之三:基于Adafruit_SH1106库的标准屏幕测试实验接线:oled模块    Ardunio UnoGND---------GND接地线VCC---------5V 接电源SDA---------D6SCL ------- D4
*///#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH1106.h>#define OLED_RESET 4
Adafruit_SH1106 display(OLED_RESET);#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH  16
static const unsigned char PROGMEM logo16_glcd_bmp[] =
{ B00000000, B11000000,B00000001, B11000000,B00000001, B11000000,B00000011, B11100000,B11110011, B11100000,B11111110, B11111000,B01111110, B11111111,B00110011, B10011111,B00011111, B11111100,B00001101, B01110000,B00011011, B10100000,B00111111, B11100000,B00111111, B11110000,B01111100, B11110000,B01110000, B01110000,B00000000, B00110000
};#if (SH1106_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SH1106.h!");
#endifvoid setup()   {Serial.begin(9600);// by default, we'll generate the high voltage from the 3.3v line internally! (neat!)display.begin(SH1106_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3D (for the 128x64)// init done// Show image buffer on the display hardware.// Since the buffer is intialized with an Adafruit splashscreen// internally, this will display the splashscreen.display.display();delay(2000);// Clear the buffer.display.clearDisplay();// draw a single pixeldisplay.drawPixel(10, 10, WHITE);// Show the display buffer on the hardware.// NOTE: You _must_ call display after making any drawing commands// to make them visible on the display hardware!display.display();delay(2000);display.clearDisplay();// draw many linestestdrawline();display.display();delay(2000);display.clearDisplay();// draw rectanglestestdrawrect();display.display();delay(2000);display.clearDisplay();// draw multiple rectanglestestfillrect();display.display();delay(2000);display.clearDisplay();// draw mulitple circlestestdrawcircle();display.display();delay(2000);display.clearDisplay();// draw a white circle, 10 pixel radiusdisplay.fillCircle(display.width() / 2, display.height() / 2, 10, WHITE);display.display();delay(2000);display.clearDisplay();testdrawroundrect();delay(2000);display.clearDisplay();testfillroundrect();delay(2000);display.clearDisplay();testdrawtriangle();delay(2000);display.clearDisplay();testfilltriangle();delay(2000);display.clearDisplay();// draw the first ~12 characters in the fonttestdrawchar();display.display();delay(2000);display.clearDisplay();// draw scrolling text/* testscrolltext();delay(2000);display.clearDisplay();*/// text display testsdisplay.setTextSize(1);display.setTextColor(WHITE);display.setCursor(0, 0);display.println("Hello, world!");display.setTextColor(BLACK, WHITE); // 'inverted' textdisplay.println(3.141592);display.setTextSize(2);display.setTextColor(WHITE);display.print("0x"); display.println(0xDEADBEEF, HEX);display.display();delay(2000);// miniature bitmap displaydisplay.clearDisplay();display.drawBitmap(30, 16,  logo16_glcd_bmp, 16, 16, 1);display.display();// invert the displaydisplay.invertDisplay(true);delay(1000);display.invertDisplay(false);delay(1000);// draw a bitmap icon and 'animate' movementtestdrawbitmap(logo16_glcd_bmp, LOGO16_GLCD_HEIGHT, LOGO16_GLCD_WIDTH);
}void loop() {
}void testdrawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) {uint8_t icons[NUMFLAKES][3];// initializefor (uint8_t f = 0; f < NUMFLAKES; f++) {icons[f][XPOS] = random(display.width());icons[f][YPOS] = 0;icons[f][DELTAY] = random(5) + 1;Serial.print("x: ");Serial.print(icons[f][XPOS], DEC);Serial.print(" y: ");Serial.print(icons[f][YPOS], DEC);Serial.print(" dy: ");Serial.println(icons[f][DELTAY], DEC);}while (1) {// draw each iconfor (uint8_t f = 0; f < NUMFLAKES; f++) {display.drawBitmap(icons[f][XPOS], icons[f][YPOS], logo16_glcd_bmp, w, h, WHITE);}display.display();delay(200);// then erase it + move itfor (uint8_t f = 0; f < NUMFLAKES; f++) {display.drawBitmap(icons[f][XPOS], icons[f][YPOS],  logo16_glcd_bmp, w, h, BLACK);// move iticons[f][YPOS] += icons[f][DELTAY];// if its gone, reinitif (icons[f][YPOS] > display.height()) {icons[f][XPOS] = random(display.width());icons[f][YPOS] = 0;icons[f][DELTAY] = random(5) + 1;}}}
}void testdrawchar(void) {display.setTextSize(1);display.setTextColor(WHITE);display.setCursor(0, 0);for (uint8_t i = 0; i < 168; i++) {if (i == '\n') continue;display.write(i);if ((i > 0) && (i % 21 == 0))display.println();}display.display();
}void testdrawcircle(void) {for (int16_t i = 0; i < display.height(); i += 2) {display.drawCircle(display.width() / 2, display.height() / 2, i, WHITE);display.display();}
}void testfillrect(void) {uint8_t color = 1;for (int16_t i = 0; i < display.height() / 2; i += 3) {// alternate colorsdisplay.fillRect(i, i, display.width() - i * 2, display.height() - i * 2, color % 2);display.display();color++;}
}void testdrawtriangle(void) {for (int16_t i = 0; i < min(display.width(), display.height()) / 2; i += 5) {display.drawTriangle(display.width() / 2, display.height() / 2 - i,display.width() / 2 - i, display.height() / 2 + i,display.width() / 2 + i, display.height() / 2 + i, WHITE);display.display();}
}void testfilltriangle(void) {uint8_t color = WHITE;for (int16_t i = min(display.width(), display.height()) / 2; i > 0; i -= 5) {display.fillTriangle(display.width() / 2, display.height() / 2 - i,display.width() / 2 - i, display.height() / 2 + i,display.width() / 2 + i, display.height() / 2 + i, WHITE);if (color == WHITE) color = BLACK;else color = WHITE;display.display();}
}void testdrawroundrect(void) {for (int16_t i = 0; i < display.height() / 2 - 2; i += 2) {display.drawRoundRect(i, i, display.width() - 2 * i, display.height() - 2 * i, display.height() / 4, WHITE);display.display();}
}void testfillroundrect(void) {uint8_t color = WHITE;for (int16_t i = 0; i < display.height() / 2 - 2; i += 2) {display.fillRoundRect(i, i, display.width() - 2 * i, display.height() - 2 * i, display.height() / 4, color);if (color == WHITE) color = BLACK;else color = WHITE;display.display();}
}void testdrawrect(void) {for (int16_t i = 0; i < display.height() / 2; i += 2) {display.drawRect(i, i, display.width() - 2 * i, display.height() - 2 * i, WHITE);display.display();}
}void testdrawline() {for (int16_t i = 0; i < display.width(); i += 4) {display.drawLine(0, 0, i, display.height() - 1, WHITE);display.display();}for (int16_t i = 0; i < display.height(); i += 4) {display.drawLine(0, 0, display.width() - 1, i, WHITE);display.display();}delay(250);display.clearDisplay();for (int16_t i = 0; i < display.width(); i += 4) {display.drawLine(0, display.height() - 1, i, 0, WHITE);display.display();}for (int16_t i = display.height() - 1; i >= 0; i -= 4) {display.drawLine(0, display.height() - 1, display.width() - 1, i, WHITE);display.display();}delay(250);display.clearDisplay();for (int16_t i = display.width() - 1; i >= 0; i -= 4) {display.drawLine(display.width() - 1, display.height() - 1, i, 0, WHITE);display.display();}for (int16_t i = display.height() - 1; i >= 0; i -= 4) {display.drawLine(display.width() - 1, display.height() - 1, 0, i, WHITE);display.display();}delay(250);display.clearDisplay();for (int16_t i = 0; i < display.height(); i += 4) {display.drawLine(display.width() - 1, 0, 0, i, WHITE);display.display();}for (int16_t i = 0; i < display.width(); i += 4) {display.drawLine(display.width() - 1, 0, i, display.height() - 1, WHITE);display.display();}delay(250);
}/*void testscrolltext(void) {display.setTextSize(2);display.setTextColor(WHITE);display.setCursor(10,0);display.clearDisplay();display.println("scroll");display.display();display.startscrollright(0x00, 0x0F);delay(2000);display.stopscroll();delay(1000);display.startscrollleft(0x00, 0x0F);delay(2000);display.stopscroll();delay(1000);display.startscrolldiagright(0x00, 0x07);delay(2000);display.startscrolldiagleft(0x00, 0x07);delay(2000);display.stopscroll();}*/

实验场景图

在这里插入图片描述
在这里插入图片描述

【Arduino】168种传感器模块系列实验(资料代码+图形编程+仿真编程)
实验一百八十一:1.3寸OLED液晶屏 I2C IIC通信 4针模块 1106/1306驱动 132*64像素
项目之三:基于Adafruit_SH1106库的标准屏幕测试显示

实验视频剪辑

https://v.youku.com/v_show/id_XNTgwOTMyMTk3Ng==.html?firsttime=0

在这里插入图片描述
【Arduino】168种传感器模块系列实验(资料代码+图形编程+仿真编程)
实验一百八十一:1.3寸OLED液晶屏 I2C IIC通信 4针模块 1106/1306驱动 132*64像素
项目之四:初始化ss_oled库

实验开源代码

/*【Arduino】168种传感器模块系列实验(资料代码+图形编程+仿真编程)实验一百八十一:1.3寸OLED液晶屏 I2C IIC通信 4针模块 1106/1306驱动 132*64像素项目之四:初始化ss_oled库实验接线:oled模块    Ardunio UnoGND---------GND接地线VCC---------5V 接电源SDA---------D6SCL ------- D4
*/#include <ss_oled.h>// Use -1 for the Wire library default pins
// or specify the pin numbers to use with the Wire library or bit banging on any GPIO pins
// These are reversed because I did straight-through wiring for my SSD1306
// and it has the 4-pin header as GND,VCC,SCL,SDA, but the GROVE connector is
// GND,VCC,SDA,SCL
#define GROVE_SDA_PIN 32
#define GROVE_SCL_PIN 26
// These are the pin numbers for the M5Stack Atom default I2C
#define SDA_PIN 8
#define SCL_PIN 9
// Set this to -1 to disable or the GPIO pin number connected to the reset
// line of your display if it requires an external reset
#define RESET_PIN -1
// let ss_oled figure out the display address
#define OLED_ADDR -1
// don't rotate the display
#define FLIP180 0
// don't invert the display
#define INVERT 0
// Bit-Bang the I2C bus
#define USE_HW_I2C 0// Change these if you're using different OLED displays
#define MY_OLED1 OLED_128x64
#define MY_OLED2 OLED_128x64// 2 copies of the SSOLED structure. Each structure is about 56 bytes
// There is no limit to the number of simultaneous displays which can be controlled by ss_oled 
SSOLED ssoled[2];void setup() {
char *msgs[] = {(char *)"SSD1306 @ 0x3C", (char *)"SSD1306 @ 0x3D",(char *)"SH1106 @ 0x3C",(char *)"SH1106 @ 0x3D"};
int rc;
// The I2C SDA/SCL pins set to -1 means to use the default Wire library
// If pins were specified, they would be bit-banged in software
// This isn't inferior to hw I2C and in fact allows you to go faster on certain CPUs
// The reset pin is optional and I've only seen it needed on larger OLEDs (2.4")
//    that can be configured as either SPI or I2C
//
//oledInit(SSOLED *, type, oled_addr, rotate180, invert, bWire, SDA_PIN, SCL_PIN, RESET_PIN, speed)rc = oledInit(&ssoled[0], MY_OLED1, OLED_ADDR, FLIP180, INVERT, 1, SDA_PIN, SCL_PIN, RESET_PIN, 400000L); // use standard I2C bus at 400Khzif (rc != OLED_NOT_FOUND){oledFill(&ssoled[0], 0, 1);oledWriteString(&ssoled[0], 0,0,0,msgs[rc], FONT_NORMAL, 0, 1);oledWriteString(&ssoled[0], 0,8,3,(char *)"Display", FONT_STRETCHED, 0, 1);oledWriteString(&ssoled[0], 0,56,6,(char *)"0", FONT_STRETCHED, 0, 1);}
rc = oledInit(&ssoled[1], MY_OLED2, OLED_ADDR, FLIP180, INVERT, 0, GROVE_SDA_PIN, GROVE_SCL_PIN, RESET_PIN, 400000L); // use standard I2C bus at 400Khzif (rc != OLED_NOT_FOUND){oledFill(&ssoled[1], 0, 1);oledSetTextWrap(&ssoled[1], 1);oledWriteString(&ssoled[1], 0,0,0,msgs[rc], FONT_SMALL, 0, 1);oledWriteString(&ssoled[1], 0,4,2,(char *)"Display", FONT_NORMAL, 0, 1);oledWriteString(&ssoled[1], 0,28,3,(char *)"1", FONT_NORMAL, 0, 1);}
} /* setup() */void loop() {// put your main code here, to run repeatedly:} /* loop() */

实验场景图

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/24480.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Spring Security OAuth2.0(7):自定义认证连接数据库

自定义认证连接数据库 首先创建数据库和用户表 CREATE TABLE t_user (id bigint(20) NOT NULL AUTO_INCREMENT,username varchar(64) DEFAULT NULL,password varchar(64) DEFAULT NULL,fullname varchar(255) DEFAULT NULL,mobile varchar(20) DEFAULT NULL,PRIMARY KEY (id)…

Django W292 no newline at end of file

这个警告 "W292 no newline at end of file" 表示在文件末尾没有空行。在许多编程语言中&#xff0c;文件末尾的空行被认为是一种良好的编码习惯。这个警告是 PEP 8&#xff08;Python 编码风格指南&#xff09;的一部分&#xff0c;它建议在文件末尾添加一个空行。 …

MacOS使用brew如何下载Nginx

首先&#xff0c;第一步切换源&#xff1a; 切换 brew.git 仓库地址&#xff1a; cd "$(brew --repo)" git remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git 替换 homebrew-core.git 仓库地址: cd "$(brew --repo)/Library/Taps/home…

LabVIEW 开发在不确定路况下自动速度辅助系统

LabVIEW 开发在不确定路况下自动速度辅助系统 智能驾驶辅助系统是汽车行业最先进的升级和尖端技术&#xff0c;智能交通系统依靠智能驾驶辅助系统在公共交通部门工作。该智能驾驶辅助系统技术包括自适应巡航控制&#xff0c;防抱死制动系统&#xff0c;安全气囊展开&#xff0…

【机器学习】编码、创造和筛选特征

在机器学习和数据科学领域中&#xff0c;特征工程是提取、转换和选择原始数据以创建更具信息价值的特征的过程。假设拿到一份数据集之后&#xff0c;如何逐步完成特征工程呢&#xff1f; 文章目录 一、特性类型分析1.1 数值型特征1.2 类别型特征1.3 时间型特征1.4 文本型特征1.…

图像 检测 - RetinaNet: Focal Loss for Dense Object Detection (arXiv 2018)

图像 检测 - RetinaNet: Focal Loss for Dense Object Detection - 密集目标检测中的焦点损失&#xff08;arXiv 2018&#xff09; 摘要1. 引言2. 相关工作References 声明&#xff1a;此翻译仅为个人学习记录 文章信息 标题&#xff1a;RetinaNet: Focal Loss for Dense Obje…

Elasticsearch 快照和恢复

文章目录 简介快照存储库说明创建或更新存储库接口说明路径参数查询参数请求正文 使用 fs 方式创建存储库验证储存库获取存储库信息删除存储库清理储存库 快照创建快照路径参数查询参数请求正文示例 获取快照查询参数示例 克隆快照查询参数示例 获取快照状态示例 恢复快照查询参…

为什么升级JDK 11后堆外内存使用增长了?

文章首发地址 JDK 11堆外使用增长的原因 JDK 11堆外使用增长的原因可能有以下几个&#xff1a; G1垃圾回收器的默认设置更改&#xff1a; JDK 11中的G1垃圾回收器默认开启了堆外内存分配&#xff0c;以减少Full GC时的STW时间。因此&#xff0c;如果应用程序使用了G1垃圾回收…

单例模式:保证一个类只有一个实例

单例模式&#xff1a;保证一个类只有一个实例 什么是单例模式&#xff1f; 在软件开发中&#xff0c;有些类只需要一个实例&#xff0c;比如数据库连接池、线程池等。单例模式就是一种设计模式&#xff0c;用于确保一个类只有一个实例&#xff0c;并提供一个全局访问点。 实…

Android中的RecyclerView 优化

Android中的RecyclerView 优化 在Android开发中&#xff0c;RecyclerView是一种用于展示大量数据列表的高效、灵活的控件。由于RecyclerView常用于展示复杂的数据集&#xff0c;特别是在数据项很多的情况下&#xff0c;对其进行优化非常重要&#xff0c;以提高性能和用户体验。…

使用Go语言生成Excel任务表依赖图(Markdown文件mermaid图)

一、前言 在游戏中&#xff0c;任务是非常常见的玩法&#xff0c;可能会有主线任务&#xff0c;支线任务以及其它一些类型的任务&#xff0c;各任务可能还会有前置任务&#xff0c;即需要完成某个任务之后&#xff0c;才能做当前任务。在游戏开发中&#xff0c;配置表可以使用…

CentOS 搭建 Harbor 镜像仓库(图文详解)

本文目录 1. 下载 Harbor 安装包2. 解压3. 修改配置文件4. 安装 Harbor5. 修改 docker 配置6. docker 登录方式7. 访问 Harbor Web 界面8. 创建证书9. 生成证书10. 更新配置11. 网页登录 说明&#xff1a;在搭建 Harbor 镜像仓库之前&#xff0c;虚拟机要先安装 docker 和 dock…

k8s部署nginx访问Tomcat

1.nginx打包镜像 #1、编写DockerFilemkdir /opt/my_nginx_dockerfilecd /opt/my_nginx_dockerfile cat >default.conf<<EOF server {listen 80;listen [::]:80;server_name localhost;#access_log /var/log/nginx/host.access.log main;location / {root …

数据安全治理5大关键技术实践分享

近年来&#xff0c;国内外对数据安全的重视程度持续提升&#xff0c;数据安全技术领域发展备受关注。从2017-2021年Gartner发布的“数据安全技术成熟度曲线”研究报告来看&#xff0c; 新兴数据安全技术呈逐年递增趋势&#xff0c;其中安全多方计算、同态加密、差分隐私等隐私增…

增强型Web安全网关在银行的应用

销售&#xff0c;绝不是降低身份去取悦客户&#xff0c;而是像朋友一样给予合理的建议。你刚好需要&#xff0c;我刚好专业&#xff01;仅此而已&#xff01; 乔.吉拉德 健康的安全体系&#xff0c;还可以更完善 浙江某商业银行股份有限公司是一家成立多年的商业银行&#xf…

linux 系统初始化基本yum命令

安装可能用到的系统工具 yum -y install vim telnet wget net-tools lrzsz unzip zip 安装常用工具和开发包 yum install -y which openssh-clients openssh-server less iproute bzip2 cmake gcc gcc-c gdb git libtool make man net-tools sysstat sudo psmisc nc net-t…

vue中transition动画的使用

1.vue文件 说明&#xff1a;加name属性 <transition name"sort"><div class"sort" v-show"show"><div class"all-sort-list2" click"goSearch"><div class"item bo" v-for"(item1, in…

windows系统的IP、路由、网关、内外网同时访问路由以及修改系统文件hosts的配置

当我们刚刚入职一家公司的时候、一般公司会给我下发一个ip地址和mac地址、还有访问一些公司的平台需要修改hosts之后的路由配置、以及第一次配置内网、如何内外网同时上网。 目录 一、ip的配置 1.1、IP的配置 1.2、mac地址的配置 1.3、内外网路由的配置&#xff08;w11系统需…

掌握Python的X篇_21_局部变量与全局变量

文章目录 1. python中的局部变量2. python中的全局变量3. 显式声明全局变量 1. python中的局部变量 函数内部定义的变量&#xff0c;是局部变量。局部变量只在当前函数中有效。 各个函数之间的局部变量是互相独立&#xff0c;互不影响的。 首先看一段代码&#xff1a; def f…

java基础复习(第五日)

java基础复习(五) 1.如何在Map中遍历删除指定的 key? 如何在List 中遍历删除指定的元素? 两个方法都使用iterator解决 过程&#xff1a; 获取 map/list的iterator whlie&#xff08;iterator.hasNext&#xff09;{ //获取下一个元素 entry iterator.next(); if(entr…