打印
[UNO]

【UNO R3 SMD试用】+4.驱动OLED

[复制链接]
1806|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
本帖最后由 看看小小说 于 2018-3-29 08:42 编辑

ARDUINO UNO R3 SMD

1.SPI方式驱动
硬件依然借助的是MICOKIT的EXT板,库文件我是下载的Adafruit的,点击下载 Adafruit_SSD1306.rar (305.99 KB) ,还是将其解压到IDE安装路径下的library下

这里说明一下,该库默认是128*32的屏,需要手动修改Adafruit_SSD1306-master文件下的Adafruit_SSD1306.h,将pixel定义为128*64

编译运行ssd1306_128x64_spi该DEMO,部分截图显示如下:




2.I2C驱动,编译运行ssd1306_128x64_i2c该DEMO即可,该库IIC的引脚定义是A5是SCL,A4是SDA,然后还要注意的是IIC地址,有些是0x3C,有些是0x3D,按需修改就好。

编译运行,部分截图如下:



有库文件支持,还是非常方便的。

3.显示字符以及中文中文显示需要自己做字库,这里我用的16*16大小的。 字模提取V2.2.rar (256.55 KB)
打开软件,输入要显示的字符(不需要修改字体,不然像素点不好匹配),取模,生成即可,非常方便


我是基于IIC驱动的基础下做的,代码如下
#include <SPI.h>  
#include <Wire.h>  
#include <Adafruit_GFX.h>  
#include <Adafruit_SSD1306.h>  
  
#define OLED_RESET 4  
Adafruit_SSD1306 display(OLED_RESET);  
  
#define **16_GLCD_HEIGHT 16 //定义显示高度  
#define **16_GLCD_WIDTH  16 //定义显示宽度  
  
/*--  文字:  U  --*/
/*--  Fixedsys12;  此字体下对应的点阵为:宽x高=16x16   --*/
static const unsigned char PROGMEM str_1[] =
{   
0x00,0x00,0x00,0x00,0x00,0x00,0x66,0x00,0x66,0x00,0x66,0x00,0x66,0x00,0x66,0x00,
0x66,0x00,0x66,0x00,0x66,0x00,0x3C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};

/*--  文字:  N  --*/
/*--  Fixedsys12;  此字体下对应的点阵为:宽x高=16x16   --*/
static const unsigned char PROGMEM str_2[] =
{
0x00,0x00,0x00,0x00,0x00,0x00,0x63,0x00,0x63,0x00,0x73,0x00,0x7B,0x00,0x6F,0x00,
0x67,0x00,0x63,0x00,0x63,0x00,0x63,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};

/*--  文字:  O  --*/
/*--  Fixedsys12;  此字体下对应的点阵为:宽x高=16x16   --*/
static const unsigned char PROGMEM str_3[] =
{
0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x00,0x66,0x00,0x66,0x00,0x66,0x00,0x66,0x00,
0x66,0x00,0x66,0x00,0x66,0x00,0x3C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};

/*--  文字:     --*/
/*--  Fixedsys12;  此字体下对应的点阵为:宽x高=16x16   --*/
static const unsigned char PROGMEM str_4[] =
{
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,0x00,0x00
};

/*--  文字:  R  --*/
/*--  Fixedsys12;  此字体下对应的点阵为:宽x高=16x16   --*/
static const unsigned char PROGMEM str_5[] =
{
0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x00,0x66,0x00,0x66,0x00,0x66,0x00,0x7C,0x00,
0x6C,0x00,0x66,0x00,0x66,0x00,0x66,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};

/*--  文字:  3  --*/
/*--  Fixedsys12;  此字体下对应的点阵为:宽x高=16x16   --*/
static const unsigned char PROGMEM str_6[] =
{
0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x00,0x66,0x00,0x66,0x00,0x06,0x00,0x1C,0x00,
0x06,0x00,0x66,0x00,0x66,0x00,0x3C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};

/*--  文字:  试  --*/
/*--  Fixedsys12;  此字体下对应的点阵为:宽x高=16x16   --*/
static const unsigned char PROGMEM str_7[] =
{
0x00,0x28,0x20,0x24,0x10,0x24,0x10,0x20,0x07,0xFE,0x00,0x20,0xF0,0x20,0x17,0xE0,
0x11,0x20,0x11,0x10,0x11,0x10,0x15,0x10,0x19,0xCA,0x17,0x0A,0x02,0x06,0x00,0x02
};

/*--  文字:  用  --*/
/*--  Fixedsys12;  此字体下对应的点阵为:宽x高=16x16   --*/
static const unsigned char PROGMEM str_8[] =
{
0x00,0x00,0x3F,0xF8,0x21,0x08,0x21,0x08,0x21,0x08,0x3F,0xF8,0x21,0x08,0x21,0x08,
0x21,0x08,0x3F,0xF8,0x21,0x08,0x21,0x08,0x21,0x08,0x41,0x08,0x41,0x28,0x80,0x10
};

/*--  文字:  感  --*/
/*--  Fixedsys12;  此字体下对应的点阵为:宽x高=16x16   --*/
static const unsigned char PROGMEM str_10[] =
{
0x00,0x28,0x00,0x24,0x3F,0xFE,0x20,0x20,0x2F,0xA4,0x20,0x24,0x2F,0xA8,0x28,0x98,
0x28,0x92,0x4F,0xAA,0x40,0x46,0x80,0x82,0x01,0x00,0x48,0x84,0x48,0x12,0x87,0xF2
};

/*--  文字:  谢  --*/
/*--  Fixedsys12;  此字体下对应的点阵为:宽x高=16x16   --*/
static const unsigned char PROGMEM str_11[] =
{
0x01,0x08,0x42,0x08,0x27,0x88,0x24,0x88,0x07,0xBE,0x04,0x88,0xE7,0x88,0x24,0xC8,
0x24,0xA8,0x2F,0xA8,0x21,0x88,0x2A,0x88,0x34,0x88,0x28,0x88,0x02,0xA8,0x01,0x10
};

/*--  文字:  2  --*/
/*--  Fixedsys12;  此字体下对应的点阵为:宽x高=16x16   --*/
static const unsigned char PROGMEM str_12[] =
{
0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x00,0x66,0x00,0x66,0x00,0x06,0x00,0x0C,0x00,
0x18,0x00,0x30,0x00,0x60,0x00,0x7E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};

/*--  文字:  1  --*/
/*--  Fixedsys12;  此字体下对应的点阵为:宽x高=16x16   --*/
static const unsigned char PROGMEM str_13[] =
{
0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x1C,0x00,0x7C,0x00,0x0C,0x00,0x0C,0x00,
0x0C,0x00,0x0C,0x00,0x0C,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};

/*--  文字:  I  --*/
/*--  Fixedsys12;  此字体下对应的点阵为:宽x高=16x16   --*/
static const unsigned char PROGMEM str_14[] =
{
0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x00,0x18,0x00,0x18,0x00,0x18,0x00,0x18,0x00,
0x18,0x00,0x18,0x00,0x18,0x00,0x3C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};

/*--  文字:  C  --*/
/*--  Fixedsys12;  此字体下对应的点阵为:宽x高=16x16   --*/
static const unsigned char PROGMEM str_15[] =
{
0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x00,0x66,0x00,0x66,0x00,0x60,0x00,0x60,0x00,
0x60,0x00,0x66,0x00,0x66,0x00,0x3C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};

#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, 0x3C);  // initialize with the I2C addr 0x3D (for the 128x64)
  // init done

  display.clearDisplay();
  
  //英文字符显示
  display.setTextSize(1);             //设置字体大小
  display.setTextColor(WHITE);        //设置字体颜色白色
  display.setCursor(0,0);             //设置字体的起始位置
  display.println("Hello, world!");   //输出字符并换行
  
  display.setTextColor(BLACK, WHITE); // 设置字体黑色,字体背景白色
  display.println("3.141592");        // 输出数字并换行
  
  display.setTextSize(2);             // 设置字体大小
  display.setTextColor(WHITE);        // 设置字体白色
  display.print("0x");                // 输出字符
  display.println(0xDEADBEEF, HEX);   // 输出为ASCII编码的十六进制
  
  //中文字符显示
  display.drawBitmap(  0, 32, str_1, 16, 16, 1);  // 在坐标X:0  Y:32的位置显示中文字
  display.drawBitmap( 16, 32, str_2, 16, 16, 1);
  display.drawBitmap( 32, 32, str_3, 16, 16, 1);
  display.drawBitmap( 48, 32, str_4, 16, 16, 1);
  display.drawBitmap( 64, 32, str_5, 16, 16, 1);
  display.drawBitmap( 80, 32, str_6, 16, 16, 1);
  display.drawBitmap( 96, 32, str_7, 16, 16, 1);
  display.drawBitmap(112, 32, str_8, 16, 16, 1);

  display.drawBitmap( 16, 48, str_10, 16, 16, 1);
  display.drawBitmap( 32, 48, str_11, 16, 16, 1);
  display.drawBitmap( 48, 48, str_12, 16, 16, 1);
  display.drawBitmap( 64, 48, str_13, 16, 16, 1);
  display.drawBitmap( 80, 48, str_14, 16, 16, 1);
  display.drawBitmap( 96, 48, str_15, 16, 16, 1);
  
  display.display();  // 把缓存的都显示
}

void loop() {  

}
显示效果如下:


4.OVER






相关帖子

沙发
dirtwillfly| | 2018-3-7 21:07 | 只看该作者
你试用的什么东东?

使用特权

评论回复
板凳
看看小小说|  楼主 | 2018-3-8 15:07 | 只看该作者
dirtwillfly 发表于 2018-3-7 21:07
你试用的什么东东?

昨天发帖老是URL链接权限不够的问题,测试来着。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

7

主题

96

帖子

2

粉丝