arduino驱动oled
OLED一款小巧的显示屏,感觉可以做出很可爱的东西。
这次实验的这款是128X64的OLED屏幕 ,
芯片是SSD1306,请确认自家模块芯片型号,不然对不上号啊
使用IIC的方法,简单实验显示示例程序。
(请确认你手头上的模块可以IIC连接,若干不支持那只能SPI方式接线)
先实现连接与显示,之后再进行更深入的应用。
任意门:
编译的过程,可能会遇到以下问题:
①提示错误
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
错误信息意思是指:
高度不正确,请修正Adafruit_SSD1306.h!
进入Arduino安装文件夹的libraries文件夹的Adfruit_SSD1306-master 找到Adafruit_SSD1306.h
打开此文件,找到第70行左右
默认是定义 SSD1306_128_32 ,由于我们使用的是128*64的OLED,所以,把原来的#define SSD1306_128_32,前面加上//
把#define SSD_128_64 前面的//去掉
最后就如上面图例一样
②模块的IIC 地址问题
模块的地址修改在这个位置,示例程序的61行
这个模块地址我用的是这个,但每个模块可能不一样,具体请咨询购买的商家,又或者可以参考下面链接的,IIC搜索地址程序。
实验效果
BOM表
Arduino Uno *1
OLED 128*64 *1
跳线若干
针脚说明
VCC 接3.3v电源
GND 接地(GND)
SCL 时钟线
SDA 数据线
接线图
程序开源代码
在上代码之前,先下载两个库分别是
Adafruit SSD1306 Library:
https://github.com/adafruit/Adafruit_SSD1306
or
http://download.csdn.net/detail/ling3ye/9729179
Adafruit GFX Library:
https://github.com/adafruit/Adafruit-GFX-Library
or
http://download.csdn.net/detail/ling3ye/9729180
下载后把解压的文件放在 Arduino 安装目录里的 "libraries"
例如:C:\Program Files (x86)\Arduino\libraries
调出示例程序
或者复制以下代码,都是一样的:
- /*********************************************************************
- This is an example for our Monochrome OLEDs based on SSD1306 drivers
- Pick one up today in the adafruit shop!
- ------> http://www.adafruit.com/category/63_98
- This example is for a 128x64 size display using I2C to communicate
- 3 pins are required to interface (2 I2C and one reset)
- Adafruit invests time and resources providing this open source code,
- please support Adafruit and open-source hardware by purchasing
- products from Adafruit!
- Written by Limor Fried/Ladyada for Adafruit Industries.
- BSD license, check license.txt for more information
- All text above, and the splash screen must be included in any redistribution
- *********************************************************************/
- #include <SPI.h>
- #include <Wire.h>
- #include <Adafruit_GFX.h>
- #include <Adafruit_SSD1306.h>
- #define OLED_RESET 4
- Adafruit_SSD1306 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 (SSD1306_LCDHEIGHT != 64)
- #error("Height incorrect, please fix Adafruit_SSD1306.h!");
- #endif
- void setup() {
- Serial.begin(9600);
- // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
- display.begin(SSD1306_SWITCHCAPVCC, 0x3D); // 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 pixel
- display.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 lines
- testdrawline();
- display.display();
- delay(2000);
- display.clearDisplay();
- // draw rectangles
- testdrawrect();
- display.display();
- delay(2000);
- display.clearDisplay();
- // draw multiple rectangles
- testfillrect();
- display.display();
- delay(2000);
- display.clearDisplay();
- // draw mulitple circles
- testdrawcircle();
- display.display();
- delay(2000);
- display.clearDisplay();
- // draw a white circle, 10 pixel radius
- display.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 font
- testdrawchar();
- display.display();
- delay(2000);
- display.clearDisplay();
- // draw scrolling text
- testscrolltext();
- delay(2000);
- display.clearDisplay();
- // text display tests
- display.setTextSize(1);
- display.setTextColor(WHITE);
- display.setCursor(0,0);
- display.println("Hello, world!");
- display.setTextColor(BLACK, WHITE); // 'inverted' text
- display.println(3.141592);
- display.setTextSize(2);
- display.setTextColor(WHITE);
- display.print("0x"); display.println(0xDEADBEEF, HEX);
- display.display();
- delay(2000);
- display.clearDisplay();
- // miniature bitmap display
- display.drawBitmap(30, 16, logo16_glcd_bmp, 16, 16, 1);
- display.display();
- delay(1);
- // invert the display
- display.invertDisplay(true);
- delay(1000);
- display.invertDisplay(false);
- delay(1000);
- display.clearDisplay();
- // draw a bitmap icon and 'animate' movement
- testdrawbitmap(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];
- // initialize
- for (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 icon
- for (uint8_t f=0; f< NUMFLAKES; f++) {
- display.drawBitmap(icons[f][XPOS], icons[f][YPOS], bitmap, w, h, WHITE);
- }
- display.display();
- delay(200);
- // then erase it + move it
- for (uint8_t f=0; f< NUMFLAKES; f++) {
- display.drawBitmap(icons[f][XPOS], icons[f][YPOS], bitmap, w, h, BLACK);
- // move it
- icons[f][YPOS] += icons[f][DELTAY];
- // if its gone, reinit
- if (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();
- delay(1);
- }
- 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();
- delay(1);
- }
- }
- void testfillrect(void) {
- uint8_t color = 1;
- for (int16_t i=0; i<display.height()/2; i+=3) {
- // alternate colors
- display.fillRect(i, i, display.width()-i*2, display.height()-i*2, color%2);
- display.display();
- delay(1);
- 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();
- delay(1);
- }
- }
- 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();
- delay(1);
- }
- }
- 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();
- delay(1);
- }
- }
- 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();
- delay(1);
- }
- }
- 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();
- delay(1);
- }
- }
- void testdrawline() {
- for (int16_t i=0; i<display.width(); i+=4) {
- display.drawLine(0, 0, i, display.height()-1, WHITE);
- display.display();
- delay(1);
- }
- for (int16_t i=0; i<display.height(); i+=4) {
- display.drawLine(0, 0, display.width()-1, i, WHITE);
- display.display();
- delay(1);
- }
- 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();
- delay(1);
- }
- 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(1);
- }
- 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();
- delay(1);
- }
- 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(1);
- }
- 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();
- delay(1);
- }
- for (int16_t i=0; i<display.width(); i+=4) {
- display.drawLine(display.width()-1, 0, i, display.height()-1, WHITE);
- display.display();
- delay(1);
- }
- delay(250);
- }
- void testscrolltext(void) {
- display.setTextSize(2);
- display.setTextColor(WHITE);
- display.setCursor(10,0);
- display.clearDisplay();
- display.println("scroll");
- display.display();
- delay(1);
- 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驱动oled的更多相关文章
- arduino驱动安装
方法一:使用官方提供的一键安装程序安装 打开Arduino在你电脑上的位置如果你的电脑是32位系统,就运行dpinst-x86.exe如果是64位系统,就运行dpinst-amd64.exe然后在弹出 ...
- 使用Arduino驱动基于ST7533芯片的TFT屏
在合宙通信买了一个1.8寸的TFT屏,驱动芯片是ST7533,本来打算使用Air800直接驱动,但由于其他原因,放弃了.于是尝试使用arduino驱动,为了屏幕刷新速度更快,采用硬件SPI. 硬件连接 ...
- Raspberry Pi3驱动Oled ssh1106屏
Raspberry Pi3可以直接使用GPIO接口驱动OLED屏 一.接线 根据网上随便找的图可以看到树莓派3的GPIO接口引脚顺序 PS:26pin的GPIO为前26针 根据OLED屏的引脚说明,如 ...
- TPYBoard v202开发板通过I2C协议驱动oled
最近无聊的时候研究了一下TPYBoard v202开发板,发现网上TPYBoard开发驱动oled的这块资料比较少,本人测试成功后给大家分享一下经验 下面通过代码讲解一下 1.首先需要导包, 在网上下 ...
- Arduino+DS18b20+OLED Display
DS18b20获取到温度数值保存到变量中,然后和天气图标还有滚动字幕一起发送到OLED 屏幕上显示 需要用到的库均可在Arduino库管理器下载. 电路图: 图中屏幕接线已在代码中写出,温度传感器da ...
- win8.1环境下安装arduino驱动问题解决方案
1. Windows 键+ R, 输入 shutdown.exe /r /o /f /t 00 2.此时电脑会自动重启,进入一下画面,选择Troubleshoot (转载请注明原处:http://ww ...
- 最新 Arduino 驱动 12接口/户外 LED显示屏/LED点阵屏/LED单元板
起因 现有的驱动LED显示屏的资料,比较好的只有这个.但是它驱动的是08接口的室内显示屏,而我要驱动的是12接口的户外显示屏.两种屏幕的区别在于户外屏幕点阵比较稀疏,而且二者的扫描方式,驱动方式都不太 ...
- 精简版、GHOST版win7,arduino驱动安装失败的解决方法分享
arduino组件安装驱动不成功,总是提示系统找不到指定文件. 原因是因为精简版缺少了两个关键的系统文件,导致无法安装.mdmcpq.inf 和 usbser.sys 解决方案详见帖子http:// ...
- PMS5003ST+Arduino Nano OLED屏显示
整合OLED显示和PMS5003报数 #include <Arduino.h> #include <pms.h> /////////////////////////////// ...
随机推荐
- ZOJ 1454 dp
Employment Planning Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu S ...
- 从零开始入门 K8s | Kubernetes 存储架构及插件使用
本文整理自<CNCF x Alibaba 云原生技术公开课>第 21 讲. 导读:容器存储是 Kubernetes 系统中提供数据持久化的基础组件,是实现有状态服务的重要保证.Kubern ...
- centos7.4 测试CPU压力--命令搞定
直接输入命令CPU消耗增加: cat /dev/urandom | gzip - > /dev/null 停止: 直接Ctrl+c结束
- 黑客攻防技术宝典web实战篇:测试后端组件习题答案
随书答案. 某网络设备提供用于执行设备配置的 Web 界面.为什么这种功能通常易于受 到操作系统命令注入攻击? 用于配置网络设备的应用程序通常包含使用正常的 Web 脚本 API 无法轻松实 现的功能 ...
- bzoj4311向量(线段树分治+斜率优化)
第二道线段树分治. 首先设当前向量是(x,y),剩余有两个不同的向量(u1,v1)(u2,v2),假设u1>u2,则移项可得,若(u1,v1)优于(u2,v2),则-x/y>(v1-v2) ...
- 修改Oracle数据库的字符集
2019年6月,来到了新的环境工作,接触了新的项目. 新的项目需要用Oracle数据库,虽然以前没用过,但是边学边用呗,在安装Oracle数据库的时候完全没有注意到要选择UTF-8的字符集,直接就默认 ...
- Paper Review: Epigenetic Landscape, Cell Differentiation 01
Today, I'll share a review papers about Epigenetic Landscape, the Epigenetic Landscape is related to ...
- Python 模拟 Base64编码
Base64编码原理:https://blog.csdn.net/wo541075754/article/details/81734770 def Enbs64(s): # 编码后的结果 result ...
- Java线程(一)——创建线程的两种方法
Thread 和 Runnable Java程序是通过线程执行的,线程在程序中具有独立的执行路径.当多条线程执行时,它们之间的路径可以不同,例如,一条线程可能在执行switch的一个case语句,另一 ...
- 注册登录页面修订-Python使用redis-手机验证接口-发送短信验证
登录页面修订 views.Login.vue <template> <div class="login box"> <img src="@/ ...