ESP32驱动 1.3寸OLED SH1106芯片)

news/2024/11/23 2:10:08/

使用U8g2lib库驱动 1.3寸OLED

驱动IC:SH1106
分辨率:128*64
支持电压3.3V/5.0V

#include <Arduino.h>
#include <U8g2lib.h>U8G2_SH1106_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0,  /*SCL*/  GPIO_NUM_5,  /*SDA*/  GPIO_NUM_18,   /*reset*/  U8X8_PIN_NONE);//构造typedef u8g2_uint_t u8g_uint_t;#define SECONDS 10
uint8_t flip_color = 0;
uint8_t draw_color = 1;void draw_set_screen(void) {// graphic commands to redraw the complete screen should be placed here  u8g2.setColorIndex(flip_color);u8g2.drawBox( 0, 0, u8g2.getWidth(), u8g2.getHeight() );
}void draw_clip_test(void) {u8g_uint_t i, j, k;char buf[3] = "AB";k = 0;u8g2.setColorIndex(draw_color);u8g2.setFont(u8g2_font_6x10_tf);for( i = 0; i  < 6; i++ ) {for( j = 1; j  < 8; j++ ) {u8g2.drawHLine(i-3, k, j);u8g2.drawHLine(i-3+10, k, j);u8g2.drawVLine(k+20, i-3, j);u8g2.drawVLine(k+20, i-3+10, j);k++;}}u8g2.setFontDirection(0);u8g2.drawStr(0-3, 50, buf);u8g2.setFontDirection(2);u8g2.drawStr(0+3, 50, buf);u8g2.setFontDirection(0);u8g2.drawStr(u8g2.getWidth()-3, 40, buf);u8g2.setFontDirection(2);u8g2.drawStr(u8g2.getWidth()+3, 40, buf);u8g2.setFontDirection(1);u8g2.drawStr(u8g2.getWidth()-10, 0-3, buf);u8g2.setFontDirection(3);u8g2.drawStr(u8g2.getWidth()-10, 3, buf);u8g2.setFontDirection(1);u8g2.drawStr(u8g2.getWidth()-20, u8g2.getHeight()-3, buf);u8g2.setFontDirection(3);u8g2.drawStr(u8g2.getWidth()-20, u8g2.getHeight()+3, buf);u8g2.setFontDirection(0);}void draw_char(void) {char buf[2] = "@";u8g_uint_t i, j;// graphic commands to redraw the complete screen should be placed here  u8g2.setColorIndex(draw_color);u8g2.setFont(u8g2_font_6x10_tf);j = 8;for(;;) {i = 0;for(;;) {u8g2.drawStr( i, j, buf);i += 8;if ( i > u8g2.getWidth() )break;}j += 8;if ( j > u8g2.getHeight() )break;}}void draw_pixel(void) {u8g_uint_t x, y, w2, h2;u8g2.setColorIndex(draw_color);w2 = u8g2.getWidth();h2 = u8g2.getHeight();w2 /= 2;h2 /= 2;for( y = 0; y < h2; y++ ) {for( x = 0; x < w2; x++ ) {if ( (x + y) & 1 ) {u8g2.drawPixel(x,y);u8g2.drawPixel(x,y+h2);u8g2.drawPixel(x+w2,y);u8g2.drawPixel(x+w2,y+h2);}}}
}void draw_line(void) {u8g2.setColorIndex(draw_color);u8g2.drawLine(0,0, u8g2.getWidth()-1, u8g2.getHeight()-1);
}// returns unadjusted FPS
uint16_t execute_with_fps(void (*draw_fn)(void)) {uint16_t FPS10 = 0;uint32_t time;time = millis() + SECONDS*1000;// picture loopdo {u8g2.clearBuffer();draw_fn();u8g2.sendBuffer();FPS10++;flip_color = flip_color ^ 1;} while( millis() < time );return FPS10;  
}const char *convert_FPS(uint16_t fps) {static char buf[6];strcpy(buf, u8g2_u8toa( (uint8_t)(fps/10), 3));buf[3] =  '.';buf[4] = (fps % 10) + '0';buf[5] = '\0';return buf;
}void show_result(const char *s, uint16_t fps) {// assign default color valueu8g2.setColorIndex(draw_color);u8g2.setFont(u8g2_font_8x13B_tf);u8g2.clearBuffer();u8g2.drawStr(0,12, s);u8g2.drawStr(0,24, convert_FPS(fps));u8g2.sendBuffer();
}void setup(void) {u8g2.begin();draw_color = 1;         // pixel on//u8g2.setBusClock(2000000);
}void loop(void) {uint16_t fps;fps = execute_with_fps(draw_clip_test);show_result("draw clip test", fps);delay(5000);fps = execute_with_fps(draw_set_screen);show_result("clear screen", fps);delay(5000);fps = execute_with_fps(draw_char);show_result("draw @", fps);delay(5000);  fps = execute_with_fps(draw_pixel);show_result("draw pixel", fps);delay(5000);fps = execute_with_fps(draw_line);show_result("draw line", fps);delay(5000);
}

在这里插入图片描述


http://www.ppmy.cn/news/447075.html

相关文章

ESP8266 驱动1.3寸SH1106 OLED屏幕显示库

ESP8266 驱动1.3寸SH1106 OLED屏幕显示库 Adafruit_SH110X 接线说明 SDA---D2(GPIO4) SCL---D1(GPIO5)驱动示例程序 /*********************************************************************This is an example for our Monochrome OLEDs based on SH110X driversThis …

macOS Monterey/BigSur 安装HP打印机驱动

打印机型号&#xff1a;HP LaserJet P1106 系统&#xff1a; macOS Monterey 12.1 1.下载适用于OS X的HP打印机驱动程序&#xff0c;HP官网和Apple均有提供 HP打印机驱动-HewlettPackardPrinterDrivershttps://support.apple.com/kb/DL1888?localezh_CN 不同来源的包…

STM32F103C8T6在Arduino框架下驱动SH1106 1.3“ IIC OLED显示

STM32F103C8T6在Arduino框架下驱动SH1106 1.3" IIC OLED显示 效果展示: 相关篇《STM32duino开发的底层驱动程序-bootloader》说明: 本示例不是采用的U8g2lib来驱动的,而是使用的Adafruit_SH1106如果接入的是ssd1306的 0.96"屏幕,也可以显示,只是边上会有没有清除…

linux移植1.3寸oled屏幕,芯片SH1106

之前移植过MPU6050(I2C协议)和0.96寸oled(SPI协议)&#xff0c;这次移植一个I2C协议的oled。 I2C的介绍 可以参考上一篇I2C的文章&#xff1a; linux移植MPU6050的I2C驱动 —— AURORA1997 注意&#xff1a;从机地址不是0x78&#xff0c;而是0x3c 驱动的编写 其实这个1.3寸的…

STM32F103VET6基于STM32CubeMX 配置硬件I2C驱动SH1106 OLED屏幕

STM32F103VET6基于STM32CubeMX 配置硬件I2C驱动SH1106 OLED屏幕 &#x1f4cc;相关篇《STM32F103VET6基于STM32CubeMX 配置硬件I2C驱动ssd1306 OLED屏幕》 &#x1f516;驱动1.3寸SH1106 OLED屏幕其实和驱动0.96寸ssd1306 OLED屏幕驱动代码差不多&#xff0c;只需要修改几个偏…

瑞芯微RV1126/1109开发流程之驱动升级

1、1126硬件参数读取 &#xff08;1&#xff09;CPU温度读取 46300和47100分别代表46.3、47.1 &#xff08;2&#xff09;查看1126的NPU &#xff08;3&#xff09;查询NPU驱动版本 dmesg | grep -i galcore 我的设备输入以上命令后没有任何输出&#xff0c;不知道为什么 …

ESP8266如何使用u8g2(I2C)驱动SH1106的OLED

u8g2是一款单色图形库&#xff0c;非常适合12864之类的显示屏&#xff0c;基本上支持了市面上的主流显示控制器。可是偏偏对SH1106不是那么友好&#xff0c;使用起来不是很方便。打开IDE的示例程序可以看到对SH1106列出来的几乎都SPI通信方式&#xff0c;仅仅只有一条是使用了硬…

IIC 驱动OLED

IIC总线可以驱动很多器件&#xff0c;比较常见的有OLED、EEPROM存储器&#xff08;AT24C02&#xff09;、温度传感器&#xff08;LM75A&#xff09;、温湿度传感器&#xff08;DHT11&#xff09;等。有关IIC总线协议的基本原理可以看我之前的文章介绍。这一次总结一下IIC驱动OL…