Arduino环境下ESP32+1.8'128X160 RGB_TFT(ST7735S)三种库的配置及示例程序效果

1.硬件信息

1.1.屏幕

分辨率:128X160

Driver IC:ST7735S

1.2.主控ESP32引脚图

image

2.Ucglib库示例代码

2.1.SPI接线定义

ESP32 IO TFT 说明
VIN VIN VIN VIN
GND GND GND GND
D22 22 SCL 时钟线
D21 21 SDA 数据线
D25 25 RST 复位线
D14 14 DC 数据命令选择线
D15 15 CS 片选
VIN VIN BLK 背光

2.2.效果图

image

2.3.示例代码

/*

  FPS.ino
  
  Do some speed measurements.

  Universal uC Color Graphics Library
  
  Copyright (c) 2014, olikraus@gmail.com
  All rights reserved.

  Redistribution and use in source and binary forms, with or without modification, 
  are permitted provided that the following conditions are met:

  * Redistributions of source code must retain the above copyright notice, this list 
    of conditions and the following disclaimer.
    
  * Redistributions in binary form must reproduce the above copyright notice, this 
    list of conditions and the following disclaimer in the documentation and/or other 
    materials provided with the distribution.

  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 
  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  

  1 Feb 2014
  SSD1351, Arduino Due, HW SPI	Text: 13.2  	Box: 28.6		Gradient: 17.9
  SSD1351, Arduino Due, SW SPI	Text: 11.1  	Box: 17.3		Gradient: 12.9		1 May 2014: this has been reduced to get better signal quality
  SSD1351, Arduino Uno, HW SPI	Text:  2.6  	Box: 12.8		Gradient:  4.6
  SSD1351, Arduino Uno, SW SPI	Text:  1.6  	Box:  3.4		Gradient:  2.2

  8 Feb 2014
  SSD1351, Arduino Uno, HW SPI	Text:  5.0  	Box: 15.2		Gradient:  5.3
  SSD1351, Arduino Uno, SW SPI	Text:  2.7  	Box:  3.4		Gradient:  2.2
  ILI9325, Arduino Uno, Port D		Text:  5.8		Box: 17.5		Gradient:  5.5
  ILI9341, Arduino Due, SW SPI		Text: 10.6		Box: 16.5		Gradient: 12.9		1 May 2014: this has been reduced to get better signal quality
  
  28 Feb 2014
  PCF8833, Arduino Uno, HW SPI	Text:  3.3  	Box: 5.6		Gradient:  3.2
  PCF8833, Arduino Due, SW SPI	Text:  1.3  	Box: 1.3		Gradient:  1.2  (display errors)
  
  27 Apr 2014, Issue 14 (SW SPI improvement)
  ST7735, Arduino Uno, SW SPI		Text:  2.2  	Box: 3.4		Gradient:  2.4
  
  1 May 2014, (SW SPI speed reduced for Due)
  ST7735, Arduino Due, SW SPI		Text:  4.9  	Box: 4.9		Gradient:  4.4

  11 Sep 2014
  ILI9341, Arduino Due, HW SPI	Text: 12.4		Box: 22.4		Gradient: 16.5	
  ILI9341, Arduino Due, SW SPI		Text: 4.7		Box: 4.7		Gradient: 4.4

  12 Sep 2014
  ILI9341, Arduino Due, HW SdSpi	Text: 13.9		Box: 30.5		Gradient: 20.2		no multibyte transfer	
  ILI9341, Arduino Due, HW SdSpi	Text: 13.9		Box: 38.0		Gradient: 19.7		with multibyte transfer	

  1 mar 2015
  LD50T6160, Arduino Due, 6Bit	Text: 6.4		Box: 13.1		Gradient: 10.5

  23 May 2015, new font procedures
  ILI9341, Arduino Uno, SW SPI		Text:  1.9  	Box: 3.4		Gradient:  2.4
  ST7735, Arduino Uno, SW SPI		Text:  2.0  	Box: 3.4		Gradient:  2.4
  ST7735, Arduino Uno, HW SPI	Text:  3.1  	Box: 13.1		Gradient:  5.3

  19 Jul 2015
  SSD1331, Arduino Uno, SW SPI	Text:  3.8  	Box: 6.3		Gradient:  4.2
  SSD1331, Arduino Uno, HW SPI	Text:  6.0  	Box: 27.3		Gradient:  8.8

  21 Jul 2015
  SEPS225, Arduino Uno, SW SPI	Text:  1.8  	Box: 4.5		Gradient:  2.7
  SEPS225, Arduino Uno, HW SPI	Text:  2.5  	Box: 14.0		Gradient:  4.9


  25 Jul 2015 (improved speed for SEPS225)
  SEPS225, Arduino Uno, SW SPI	Text:  2.6  	Box: 5.0		Gradient:  2.9
  SEPS225, Arduino Uno, HW SPI	Text:  3.8  	Box: 17.8		Gradient:  5.3
  
*/

#include <SPI.h>
#include "Ucglib.h"

/*
  Hardware SPI Pins:
    Arduino Uno		sclk=13, data=11
    Arduino Due		sclk=76, data=75
    Arduino Mega	sclk=52, data=51
    
  >>> Please uncomment (and update) one of the following constructors. <<<  
*/
//Ucglib8BitPortD ucg(ucg_dev_ili9325_18x240x320_itdb02, ucg_ext_ili9325_18, /* wr= */ 18 , /* cd= */ 19 , /* cs= */ 17, /* reset= */ 16 );
//Ucglib8Bit ucg(ucg_dev_ili9325_18x240x320_itdb02, ucg_ext_ili9325_18, 0, 1, 2, 3, 4, 5, 6, 7, /* wr= */ 18 , /* cd= */ 19 , /* cs= */ 17, /* reset= */ 16 );
Ucglib_ST7735_18x128x160_SWSPI ucg(/*sclk=*/ 22, /*data=*/ 21, /*cd=*/ 14, /*cs=*/ 15, /*reset=*/ 25);
//Ucglib4WireSWSPI ucg(ucg_dev_ili9325_18x240x320_itdb02, ucg_ext_ili9325_18, /*sclk=*/ 13, /*data=*/ 11, /*cd=*/ 9 , /*cs=*/ 10, /*reset=*/ 8);	// not working
//Ucglib4WireSWSPI ucg(ucg_dev_ili9325_spi_18x240x320, ucg_ext_ili9325_spi_18, /*sclk=*/ 13, /*data=*/ 11, /*cd=*/ 9 , /*cs=*/ 10, /*reset=*/ 8);	// not working
//Ucglib3WireILI9325SWSPI ucg(ucg_dev_ili9325_spi_18x240x320, ucg_ext_ili9325_spi_18, /*sclk=*/ 13, /*data=*/ 11, /*cs=*/ 10, /*reset=*/ 8);	// not working
//Ucglib3WireILI9325SWSPI ucg(ucg_dev_ili9325_18x240x320_itdb02, ucg_ext_ili9325_18, /*sclk=*/ 13, /*data=*/ 11, /*cs=*/ 10, /*reset=*/ 8);	// not working

//Ucglib_ST7735_18x128x160_SWSPI ucg(/*sclk=*/ 13, /*data=*/ 11, /*cd=*/ 9, /*cs=*/ 10, /*reset=*/ 8);
//Ucglib_ST7735_18x128x160_HWSPI ucg(/*cd=*/ 9, /*cs=*/ 10, /*reset=*/ 8);

//Ucglib_ILI9163_18x128x128_SWSPI ucg(/*sclk=*/ 7, /*data=*/ 6, /*cd=*/ 5, /*cs=*/ 3, /*reset=*/ 4);
//Ucglib_ILI9163_18x128x128_HWSPI ucg(/*cd=*/ 9, /*cs=*/ 10, /*reset=*/ 8);	/* HW SPI Adapter */

//Ucglib_ILI9341_18x240x320_SWSPI ucg(/*sclk=*/ 7, /*data=*/ 6, /*cd=*/ 5, /*cs=*/ 3, /*reset=*/ 4);
//Ucglib_ILI9341_18x240x320_SWSPI ucg(/*sclk=*/ 13, /*data=*/ 11, /*cd=*/ 9, /*cs=*/ 10, /*reset=*/ 8);
//Ucglib_ILI9341_18x240x320_HWSPI ucg(/*cd=*/ 9, /*cs=*/ 10, /*reset=*/ 8);
//Ucglib_ILI9341_18x240x320_SWSPI ucg(/*sclk=*/ 4, /*data=*/ 3, /*cd=*/ 6, /*cs=*/ 7, /*reset=*/ 5);	/* Elec Freaks Shield */

//Ucglib_HX8352C_18x240x400_SWSPI ucg(/*sclk=*/ 7, /*data=*/ 6, /*cd=*/ 5, /*cs=*/ 3, /*reset=*/ 4);
//Ucglib_HX8352C_18x240x400_HWSPI ucg(/*cd=*/ 9, /*cs=*/ 10, /*reset=*/ 8);

//Ucglib_ILI9486_18x320x480_SWSPI ucg(/*sclk=*/ 7, /*data=*/ 6, /*cd=*/ 5, /*cs=*/ 3, /*reset=*/ 4);
//Ucglib_ILI9486_18x320x480_HWSPI ucg(/*cd=*/ 9, /*cs=*/ 10, /*reset=*/ 8);

//Ucglib_SSD1351_18x128x128_SWSPI ucg(/*sclk=*/ 13, /*data=*/ 11, /*cd=*/ 9, /*cs=*/ 10, /*reset=*/ 8);
//Ucglib_SSD1351_18x128x128_HWSPI ucg(/*cd=*/ 9, /*cs=*/ 10, /*reset=*/ 8);
//Ucglib_SSD1351_18x128x128_FT_SWSPI ucg(/*sclk=*/ 13, /*data=*/ 11, /*cd=*/ 9, /*cs=*/ 10, /*reset=*/ 8);
//Ucglib_SSD1351_18x128x128_FT_HWSPI ucg(/*cd=*/ 9, /*cs=*/ 10, /*reset=*/ 8);

//Ucglib_PCF8833_16x132x132_SWSPI ucg(/*sclk=*/ 13, /*data=*/ 11, /*cs=*/ 9, /*reset=*/ 8);	/* linksprite board */
//Ucglib_PCF8833_16x132x132_HWSPI ucg(/*cs=*/ 9, /*reset=*/ 8);	/* linksprite board */

//Ucglib_LD50T6160_18x160x128_6Bit ucg( /*d0 =*/ d0, /*d1 =*/ d1, /*d2 =*/ d2, /*d3 =*/ d3, /*d4 =*/ d4, /*d5 =*/ d5, /*wr=*/ wr, /*cd=*/ cd, /*cs=*/ cs, /*reset=*/ reset);
//Ucglib_LD50T6160_18x160x128_6Bit ucg( /*d0 =*/ 16, /*d1 =*/ 17, /*d2 =*/ 18, /*d3 =*/ 19, /*d4 =*/ 20, /*d5 =*/ 21, /*wr=*/ 14, /*cd=*/ 15); /* S
<think>嗯,用户想了解ST7735 LCD驱动芯片的使用说明、驱动示例代码。首先,我需要回忆一下之前提供的引用内容。引用1提到了ST7735-TFT屏幕的驱动代码,包括stm32、51单片机和Arduino示例。引用2和3则讨论了Linux下的驱动开发,特别是针对IMX6ULL平台的。用户可能需要跨不同平台的信息,所以得整理各个平台的驱动方法。 用户的问题涉及使用说明,得先介绍ST7735的基本特性,比如接口类型(SPI)、分辨率和颜色模式。然后分平台说明驱动步骤,比如硬件接线、代码移植和初始化流程。驱动部分需要提到不同平台下的,比如HALArduino的Adafruit,以及Linux的驱动框架。示例代码方面,可以引用已有的代码片段,比如stm32的初始化函数和Arduino示例。 需要注意的是,用户可能没有明确说明使用的平台,所以应该涵盖多个常见平台,如单片机、Arduino和Linux系统。同时,要确保LaTeX格式正确,数学表达式用$...$,独立公式用$$...$$,但在这个回答中可能数学公式不多,但需要检查是否有需要的地方。还要生成相关问题,可能涉及驱动开发中的常见问题,比如SPI配置、显示优化、汉字显示等。最后,引用部分要正确标注,确保每个引用来源对应正确的标记。</think>### ST7735 LCD驱动芯片技术说明 #### 一、基本特性 ST7735是128x160像素的TFT-LCD驱动芯片,支持262K色(18RGB)显示,采用SPI或8/9/16位并行接口[^1][^3]。其典型工作电压为2.4-3.3V,内置DC-DC升压电路,支持横竖屏切换。 #### 二、驱动开发流程 1. **硬件接线** 以SPI接口为例: ``` CS -> GPIO输出 DC -> GPIO输出(命令/数据切换) SCL -> SPI时钟线 SDA -> SPI数据线 RES -> 复位控制 BL -> 背光控制 ``` 2. **代码移植** - **STM32**:使用HALSPI接口,需实现`write_command`和`write_data`函数: ```c void ST7735_WriteCmd(uint8_t cmd) { DC_LOW(); HAL_SPI_Transmit(&hspi1, &cmd, 1, 100); } ``` - **Arduino**:使用Adafruit_ST7735: ```cpp Adafruit_ST7735 tft = Adafruit_ST7735(CS_PIN, DC_PIN, RST_PIN); tft.initR(INITR_BLACKTAB); // 初始化屏幕 ``` 3. **初始化序列** 需要按顺序发送以下命令: ```c /* 典型初始化流程 */ sendCmd(0x11); // Sleep out delay(120); sendCmd(0x3A); // 颜色模式设置 sendData(0x05); // 16位/pixel ``` #### 三、驱动推荐 1. **嵌入式平台** - STM32标准外设/STM32Cube HAL - Arduino的Adafruit_ST7735(支持ESP32) - Keil C51的硬件SPI驱动 2. **Linux平台** 使用`framebuffer`架构开发,需实现: ```c static struct fb_ops st7735s_fb_ops = { .fb_setcolreg = st7735s_setcolreg, .fb_fillrect = st7735s_fillrect, .fb_imageblit = st7735s_imageblit }; // 帧缓冲操作函数集[^3] ``` #### 四、示例代码解析 ```python # Arduino显示示例 tft.fillScreen(ST7735_BLACK); tft.setCursor(0, 0); tft.setTextColor(ST7735_WHITE); tft.print("Hello ST7735!"); // 文本输出 ``` ```c // STM32图像显示函数 void ST7735_DrawImage(uint16_t x, uint16_t y, const uint16_t *img) { Set_Address(x, y, x+IMG_WIDTH-1, y+IMG_HEIGHT-1); HAL_SPI_Transmit(&hspi1, (uint8_t*)img, IMG_SIZE*2, 1000); } // 需要预存图像为RGB565数组 ``` #### 五、技术要点 1. **显存管理**:无内置显存需双缓冲时,推荐使用`uint16_t buffer[128][160]`缓存 2. **颜色转换**:RGB888RGB565公式: $$ RGB565 = (R \gg 3) \ll 11 | (G \gg 2) \ll 5 | (B \gg 3) $$ 3. **刷新优化**:局部刷新时使用`CASET`/`RASET`指定更新区域[^2]
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值