108个传感器之-tft屏(52)

108个传感器之-tft屏(52)

介绍

名称 参数
SKU MSP0961
尺寸 0.96(inch)
面板材质 IPS全视角
驱动芯片 ST7735S(注意库的驱动)
分辨率 160*80 (Pixel)
显示接口 4-line SPI interface
触摸类型 无触摸
有效显示区域(AA区) 10.80x21.70 (mm)
模块PCB底板尺寸 30.00x24.04 (mm)
工作温度 -10℃~60℃
功耗 TDB
产品重量(含包装) 8g

引脚连接

序号 引脚标号 说明
1 GND 液晶屏电源地
2 VCC 液晶屏电源正(3.3V)
3 SCL 液晶屏SPI总线时钟信号
4 SDA 液晶屏SPI总线写数据信号
5 RES 液晶屏复位控制信号(低电平复位)
6 DC 液晶屏寄存器/数据选择控制信号(低电平:寄存器,高电平:数据)
7 CS 液晶屏片选控制信号(低电平使能)
8 BLK 液晶屏背光控制信号(高电平点亮,如不需要控制,请接3.3V)

pin 引脚连接开发板的 gpio 接口即可:

DEV BOARD Sensor
GND GND
5 V VCC
D5 SCL
D7 SDA
D4 RES
D3 DC
D8 CS
3.3V BLK

TFT_eSPI 介绍

API 大全

//以下大多 API 对 Sprite 类也通用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//初始化
tft.init();
//填充全屏幕
tft.fillScreen(uint32_t color);
//屏幕旋转,参数为:0, 1, 2, 3,分别代表 0°、90°、180°、270°
tft.setRotation(uint8_t r);
//设置光标位置,font是可选参数
tft.setCursor(int16_t x, int16_t y, uint8_t font);
//设置字体颜色
tft.setTextColor(uint16_t color);
//设置文本颜色和背景色
tft.setTextColor(uint16_t fgcolor, uint16_t bgcolor);
//设置字体大小,文本大小范围为 1~7 的整数,特别注意: 字库7是仿7段数码屏的样式
tft.setTextSize(uint8_t size);
//加载字体
display.loadFont(Final_Frontier_28);
//括号中为示例,大小为28像素的平滑字体。
//使用平滑字体时最好用setTextColor同时设置好字体和背景颜色,否则可能会不平滑。
//卸载当前字体
display.unloadFont();
//打印
tft.print("Hello World!");
tft.println("Hello World!");

//绘制字符串
//居左
tft.drawString(String, int32_t x, int32_t y, uint8_t font);//font是可选参数
//居中
tft.drawCentreString(String, int32_t x, int32_t y, uint8_t font);//font是可选参数
//居右
tft.drawRightString(String, int32_t x, int32_t y, uint8_t font);//font是可选参数
//画点
tft.drawPixel(int32_t x, int32_t y, uint32_t color);
//画线
tft.drawLine(int32_t xs, int32_t ys, int32_t xe, int32_t ye, uint32_t color);
//画横线
tft.drawFastHLine(int32_t x, int32_t y, int32_t w, uint32_t color);
//画竖线
tft.drawFastVLine(int32_t x, int32_t y, int32_t h, uint32_t color);
//画圆
//空心圆
tft.drawCircle(int32_t x, int32_t y, int32_t r, uint32_t color);
//实心圆
tft.fillCircle(int32_t x, int32_t y, int32_t r, uint32_t color);
//空心椭圆
tft.drawEllipse(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color);
//实心椭圆
tft.fillEllipse(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color);
//画矩形
//空心矩形
tft.drawRect(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color);
//实心矩形
tft.fillRect(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color);
//空心圆角矩形
tft.drawRoundRect(int32_t x, int32_t y, int32_t w, int32_t h, int32_t radius, uint32_t color);
//实心圆角矩形
tft.drawRoundRect(int32_t x, int32_t y, int32_t w, int32_t h, int32_t radius, uint32_t color);
//画三角形
//空心三角形
tft.drawTriangle(int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t x3, int32_t y3, uint32_t color);
//实心三角形
tft.drawTriangle(int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t x3, int32_t y3, uint32_t color);
//显示图片
tft.pushImage(int32_t x, int32_t y, int32_t w, int32_t h, data);

代码示例

mai.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <Arduino.h>
// New background colour
#define TFT_BROWN 0x38E0

// Pause in milliseconds between screens, change to 0 to time font rendering
#define WAIT 1000

#include <TFT_eSPI.h> // Graphics and font library for ILI9341 driver chip
#include <SPI.h>
#include <Wire.h>
#include <User_Setup.h>

TFT_eSPI tft = TFT_eSPI(); // Invoke library, pins defined in User_Setup.h

unsigned long targetTime = 0; // Used for testing draw times

void setup(void) {
tft.init();
tft.setRotation(3);
}

void loop() {
targetTime = millis();

// First we test them with a background colour set
tft.setTextSize(1);
tft.fillScreen(TFT_BLACK);
tft.setTextColor(TFT_GREEN, TFT_BLACK);

tft.drawString(" !\"#$%&'()*+,-./0123456", 0, 0, 2);
tft.drawString("789:;<=>?@ABCDEFGHIJKL", 0, 16, 2);
tft.drawString("MNOPQRSTUVWXYZ[\\]^_`", 0, 32, 2);
tft.drawString("abcdefghijklmnopqrstuvw", 0, 48, 2);
int xpos = 0;
xpos += tft.drawString("xyz{|}~", 0, 64, 2);
tft.drawChar(127, xpos, 64, 2);
delay(WAIT);
}

userSetup.h

主要更改以下几个地方

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
........
// Only define one driver, the other ones must be commented out
// #define ILI9341_DRIVER // Generic driver for common displays
//#define ILI9341_2_DRIVER // Alternative ILI9341 driver, see https://github.com/Bodmer/TFT_eSPI/issues/1172
#define ST7735_DRIVER // Define additional parameters below for this display
//#define ILI9163_DRIVER // Define additional parameters below for this display
//#define S6D02A1_DRIVER
//#define RPI_ILI9486_DRIVER // 20MHz maximum SPI
//#define HX8357D_DRIVER
//#define ILI9481_DRIVER
//#define ILI9486_DRIVER
//#define ILI9488_DRIVER // WARNING: Do not connect ILI9488 display SDO to MISO if other devices share the SPI bus (TFT SDO does NOT tristate when CS is high)
//#define ST7789_DRIVER // Full configuration option, define additional parameters below for this display
//#define ST7789_2_DRIVER // Minimal configuration option, define additional parameters below for this display
//#define R61581_DRIVER
//#define RM68140_DRIVER
//#define ST7796_DRIVER
//#define SSD1351_DRIVER
//#define SSD1963_480_DRIVER
//#define SSD1963_800_DRIVER
//#define SSD1963_800ALT_DRIVER
//#define ILI9225_DRIVER
//#define GC9A01_DRIVER

// Some displays support SPI reads via the MISO pin, other displays have a single
// bi-directional SDA pin and the library will try to read this via the MOSI line.
// To use the SDA line for reading data from the TFT uncomment the following line:

// #define TFT_SDA_READ // This option is for ESP32 ONLY, tested with ST7789 and GC9A01 display only

// For ST7735, ST7789 and ILI9341 ONLY, define the colour order IF the blue and red are swapped on your display
// Try ONE option at a time to find the correct colour order for your display

#define TFT_RGB_ORDER TFT_RGB // Colour order Red-Green-Blue
// #define TFT_RGB_ORDER TFT_BGR // Colour order Blue-Green-Red

// For ST7789, ST7735, ILI9163 and GC9A01 ONLY, define the pixel width and height in portrait orientation
// #define TFT_WIDTH 80
#define TFT_WIDTH 128
// #define TFT_WIDTH 172 // ST7789 172 x 320
// #define TFT_WIDTH 170 // ST7789 170 x 320
// #define TFT_WIDTH 240 // ST7789 240 x 240 and 240 x 320
#define TFT_HEIGHT 160
// #define TFT_HEIGHT 128
// #define TFT_HEIGHT 240 // ST7789 240 x 240
// #define TFT_HEIGHT 320 // ST7789 240 x 320
// #define TFT_HEIGHT 240 // GC9A01 240 x 240
.......

小结

待完善…

参考

http://www.lcdwiki.com/zh/0.96inch_IPS_Module

使用tft屏幕全踩坑指南

108个传感器之-tft屏(52)

https://blog.jzxer.cn/20250124/20250124-tft/

作者

dev

发布于

2025-01-24

更新于

2025-11-01

许可协议

评论

Your browser is out-of-date!

Update your browser to view this website correctly.&npsb;Update my browser now

×