简介

点亮该屏幕的笔记,既然都能显示了,肯定要获取触摸位置啊,从实物图中可知该屏幕的触摸IC为XPT2046

Arduino IDE需配置esp32开发环境
开发板:ESP 32

触摸过程

这里实现的是触摸屏幕获取坐标

IO映射

TFT LCD ESP32
VCC 3V3
GND GND
CS P5
RESET P4
DC P17
MOSI P23
SCK P18
LED VIN(最好加一个电阻)
MISO P19
触摸接口 触摸接口
T_CLK P18
T_CS P5
T_DIN P23
T_DO P19
T_IRQ P21

这里可以看到复用部分接口,灵感来自于太极创客的一个视频(参考3)

代码

需要从库管理器下载的库:XPT2046_Touchscreen
工具-开发板- ESP32 Arduino - NodeMCU-32s

#include <XPT2046_Touchscreen.h>
#include <SPI.h>#define CS_PIN  8
// MOSI=11, MISO=12, SCK=13#define TIRQ_PIN  2
XPT2046_Touchscreen ts(5, 21);
void setup() {Serial.begin(9600);ts.begin();ts.setRotation(1);while (!Serial && (millis() <= 1000));
}int x = 0;
int y = 0;void loop() {if (ts.touched()) {TS_Point p = ts.getPoint();if(x != p.x || y != p.y) //过滤重复的点位{Serial.print("Pressure = ");  //按压的力度大小Serial.print(p.z);Serial.print(", x = ");      //坐标的x值Serial.print(p.x);Serial.print(", y = ");     //坐标的y值Serial.print(p.y);Serial.println();} x=p.x;y=p.y;delay(30);}
}

效果

指尖触摸屏幕,可以在串口监视器中看到一下内容

总结

或是是因为XPT2046过于廉价,获取到的触摸数据emmm,不堪入目,也可能是我没有校准???如何校准哦。。人傻了

花式点亮屏幕

这里不涉及触摸,但点亮的方式挺炫酷的

IO映射

TFT LCD ESP32
VCC 3V3
GND GND
CS P5
RESET P4
DC P17
MOSI P23
SCK P18
LED VIN(最好加一个电阻)
MISO P19(非必需,可以不接)

代码

需要下载库:Adafruit_ILI9341

#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"//Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);
Adafruit_ILI9341 tft = Adafruit_ILI9341(5, 17, 23, 18, 4, 19);    //esp32-nodemcu32svoid setup() {Serial.begin(9600);Serial.println("ILI9341 Test!"); tft.begin();// read diagnostics (optional but can help debug problems)uint8_t x = tft.readcommand8(ILI9341_RDMODE);Serial.print("Display Power Mode: 0x"); Serial.println(x, HEX);x = tft.readcommand8(ILI9341_RDMADCTL);Serial.print("MADCTL Mode: 0x"); Serial.println(x, HEX);x = tft.readcommand8(ILI9341_RDPIXFMT);Serial.print("Pixel Format: 0x"); Serial.println(x, HEX);x = tft.readcommand8(ILI9341_RDIMGFMT);Serial.print("Image Format: 0x"); Serial.println(x, HEX);x = tft.readcommand8(ILI9341_RDSELFDIAG);Serial.print("Self Diagnostic: 0x"); Serial.println(x, HEX); Serial.println(F("Benchmark                Time (microseconds)"));delay(10);Serial.print(F("Screen fill              "));Serial.println(testFillScreen());delay(500);Serial.print(F("Text                     "));Serial.println(testText());delay(3000);Serial.print(F("Lines                    "));Serial.println(testLines(ILI9341_CYAN));delay(500);Serial.print(F("Horiz/Vert Lines         "));Serial.println(testFastLines(ILI9341_RED, ILI9341_BLUE));delay(500);Serial.print(F("Rectangles (outline)     "));Serial.println(testRects(ILI9341_GREEN));delay(500);Serial.print(F("Rectangles (filled)      "));Serial.println(testFilledRects(ILI9341_YELLOW, ILI9341_MAGENTA));delay(500);Serial.print(F("Circles (filled)         "));Serial.println(testFilledCircles(10, ILI9341_MAGENTA));Serial.print(F("Circles (outline)        "));Serial.println(testCircles(10, ILI9341_WHITE));delay(500);Serial.print(F("Triangles (outline)      "));Serial.println(testTriangles());delay(500);Serial.print(F("Triangles (filled)       "));Serial.println(testFilledTriangles());delay(500);Serial.print(F("Rounded rects (outline)  "));Serial.println(testRoundRects());delay(500);Serial.print(F("Rounded rects (filled)   "));Serial.println(testFilledRoundRects());delay(500);Serial.println(F("Done!"));}void loop(void) {for(uint8_t rotation=0; rotation<4; rotation++) {tft.setRotation(rotation);testText();delay(1000);}
}unsigned long testFillScreen() {unsigned long start = micros();tft.fillScreen(ILI9341_BLACK);yield();tft.fillScreen(ILI9341_RED);yield();tft.fillScreen(ILI9341_GREEN);yield();tft.fillScreen(ILI9341_BLUE);yield();tft.fillScreen(ILI9341_BLACK);yield();return micros() - start;
}unsigned long testText() {tft.fillScreen(ILI9341_BLACK);unsigned long start = micros();tft.setCursor(0, 0);tft.setTextColor(ILI9341_WHITE);  tft.setTextSize(1);tft.println("Hello World!");tft.setTextColor(ILI9341_YELLOW); tft.setTextSize(2);tft.println(1234.56);tft.setTextColor(ILI9341_RED);    tft.setTextSize(3);tft.println(0xDEADBEEF, HEX);tft.println();tft.setTextColor(ILI9341_GREEN);tft.setTextSize(5);tft.println("Groop");tft.setTextSize(2);tft.println("I implore thee,");tft.setTextSize(1);tft.println("my foonting turlingdromes.");tft.println("And hooptiously drangle me");tft.println("with crinkly bindlewurdles,");tft.println("Or I will rend thee");tft.println("in the gobberwarts");tft.println("with my blurglecruncheon,");tft.println("see if I don't!");return micros() - start;
}unsigned long testLines(uint16_t color) {unsigned long start, t;int           x1, y1, x2, y2,w = tft.width(),h = tft.height();tft.fillScreen(ILI9341_BLACK);yield();x1 = y1 = 0;y2    = h - 1;start = micros();for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);x2    = w - 1;for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);t     = micros() - start; // fillScreen doesn't count against timingyield();tft.fillScreen(ILI9341_BLACK);yield();x1    = w - 1;y1    = 0;y2    = h - 1;start = micros();for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);x2    = 0;for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);t    += micros() - start;yield();tft.fillScreen(ILI9341_BLACK);yield();x1    = 0;y1    = h - 1;y2    = 0;start = micros();for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);x2    = w - 1;for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);t    += micros() - start;yield();tft.fillScreen(ILI9341_BLACK);yield();x1    = w - 1;y1    = h - 1;y2    = 0;start = micros();for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);x2    = 0;for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);yield();return micros() - start;
}unsigned long testFastLines(uint16_t color1, uint16_t color2) {unsigned long start;int           x, y, w = tft.width(), h = tft.height();tft.fillScreen(ILI9341_BLACK);start = micros();for(y=0; y<h; y+=5) tft.drawFastHLine(0, y, w, color1);for(x=0; x<w; x+=5) tft.drawFastVLine(x, 0, h, color2);return micros() - start;
}unsigned long testRects(uint16_t color) {unsigned long start;int           n, i, i2,cx = tft.width()  / 2,cy = tft.height() / 2;tft.fillScreen(ILI9341_BLACK);n     = min(tft.width(), tft.height());start = micros();for(i=2; i<n; i+=6) {i2 = i / 2;tft.drawRect(cx-i2, cy-i2, i, i, color);}return micros() - start;
}unsigned long testFilledRects(uint16_t color1, uint16_t color2) {unsigned long start, t = 0;int           n, i, i2,cx = tft.width()  / 2 - 1,cy = tft.height() / 2 - 1;tft.fillScreen(ILI9341_BLACK);n = min(tft.width(), tft.height());for(i=n; i>0; i-=6) {i2    = i / 2;start = micros();tft.fillRect(cx-i2, cy-i2, i, i, color1);t    += micros() - start;tft.drawRect(cx-i2, cy-i2, i, i, color2);yield();}return t;
}unsigned long testFilledCircles(uint8_t radius, uint16_t color) {unsigned long start;int x, y, w = tft.width(), h = tft.height(), r2 = radius * 2;tft.fillScreen(ILI9341_BLACK);start = micros();for(x=radius; x<w; x+=r2) {for(y=radius; y<h; y+=r2) {tft.fillCircle(x, y, radius, color);}}return micros() - start;
}unsigned long testCircles(uint8_t radius, uint16_t color) {unsigned long start;int           x, y, r2 = radius * 2,w = tft.width()  + radius,h = tft.height() + radius;start = micros();for(x=0; x<w; x+=r2) {for(y=0; y<h; y+=r2) {tft.drawCircle(x, y, radius, color);}}return micros() - start;
}unsigned long testTriangles() {unsigned long start;int           n, i, cx = tft.width()  / 2 - 1,cy = tft.height() / 2 - 1;tft.fillScreen(ILI9341_BLACK);n     = min(cx, cy);start = micros();for(i=0; i<n; i+=5) {tft.drawTriangle(cx    , cy - i, // peakcx - i, cy + i, // bottom leftcx + i, cy + i, // bottom righttft.color565(i, i, i));}return micros() - start;
}unsigned long testFilledTriangles() {unsigned long start, t = 0;int           i, cx = tft.width()  / 2 - 1,cy = tft.height() / 2 - 1;tft.fillScreen(ILI9341_BLACK);start = micros();for(i=min(cx,cy); i>10; i-=5) {start = micros();tft.fillTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,tft.color565(0, i*10, i*10));t += micros() - start;tft.drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,tft.color565(i*10, i*10, 0));yield();}return t;
}unsigned long testRoundRects() {unsigned long start;int           w, i, i2,cx = tft.width()  / 2 - 1,cy = tft.height() / 2 - 1;tft.fillScreen(ILI9341_BLACK);w     = min(tft.width(), tft.height());start = micros();for(i=0; i<w; i+=6) {i2 = i / 2;tft.drawRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(i, 0, 0));}return micros() - start;
}unsigned long testFilledRoundRects() {unsigned long start;int           i, i2,cx = tft.width()  / 2 - 1,cy = tft.height() / 2 - 1;tft.fillScreen(ILI9341_BLACK);start = micros();for(i=min(tft.width(), tft.height()); i>20; i-=6) {i2 = i / 2;tft.fillRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(0, i, 0));yield();}return micros() - start;
}

效果


参考

  • 点亮TFT LCD屏幕_ILI9341_SPI_240x320 https://blog.csdn.net/weixin_43031092/article/details/108007481
  • 数据手册 http://www.lcdwiki.com/zh/2.8inch_SPI_Module_ILI9341_SKU:MSP2807
  • 太极创客 https://www.bilibili.com/video/BV1C4411Z7pS?t=76
  • 配置esp32开发环境 https://blog.csdn.net/weixin_43031092/article/details/106860485
  • ESP32管脚 https://blog.csdn.net/weixin_43031092/article/details/108158407

用ESP学习单片机之Arduino_Esp-32s获取2.8‘‘TFT LCD屏幕的触摸数据_ILI9341_SPI_XPT2046相关推荐

  1. STM32:从菜鸟到牛人就是如此简单!为了学习单片机而去学习单片机的思路是不对的

    来源于知乎,版权归原作者所有 为了学习单片机而去学习单片机的思路是不对的 你问: 如何系统地入门学习stm32? 本身就是一个错误的问题 假如你会使用8051 会写C语言 那么STM32本身并不需要刻 ...

  2. 漫画版:如何学习单片机?

    作者:DBinary 地址:https://www.zhihu.com/question/311334042/answer/738607755 -END- 猜你喜欢该不该放弃单片机,嵌入式这条路? 学 ...

  3. 基于Proteus学习单片机系列(七)——实时时钟DS1302

    获取更多资源,请关注微信公众号:嵌入式基地 获取项目资源:公众号后台回复:单片机仿真 基于Proteus学习单片机系列(一)--点亮LED 基于Proteus学习单片机系列(二)--驱动数码管 基于P ...

  4. 基于Proteus学习单片机系列(二)——驱动数码管

    获取更多资源,请关注微信公众号:嵌入式基地 获取项目资源:公众号后台回复:单片机仿真 基于Proteus学习单片机系列(一)--点亮LED 基于Proteus学习单片机系列(二)--驱动数码管 基于P ...

  5. 《逆袭大学》文摘——7.1.2 中学生学习单片机的启示

    7.1 找寻失去的学习潜质 (主题)学习能力最强.进步最快的时期,是婴儿期.我们要像婴儿一般地去学习. 7.1.1 我们原本就有的学习潜质 引用台湾大学教授黄武雄先生的著作<童年与解放>, ...

  6. OpenHarmony学习笔记——Hi3861使用DHT11获取温湿度

    文章目录 前言 DHT11简介 通信流程 硬件连接 编程实现 GPIO API简介 复位总线 DHT11应答 数据读取 效果一览 总结 目录 前言 此文主要是使用Hi3861的GPIO口,模拟1-Wi ...

  7. 基于Proteus学习单片机系列(六)——I2C总线AT24C04

    获取更多资源,请关注微信公众号:嵌入式基地 获取项目资源:公众号后台回复:单片机仿真 基于Proteus学习单片机系列(一)--点亮LED 基于Proteus学习单片机系列(二)--驱动数码管 基于P ...

  8. 零基础学c语言要多久,零基础学习单片机编程需要多长时间?

    单片机自学要多长时间 学习单片机就是学习单片机的硬件结构,内部资源与外设的应用.在C语言中(极少量的汇编)掌握各种功能的初始化,启动与停止,实现各种功能函数的编写与调试. 下面咱们就来分步骤看一下对于 ...

  9. 蓝桥杯单片机国赛客观题_蓝桥杯单片机比赛历年试题获取

    蓝桥杯单片机比赛历年试题获取!!! 准备蓝桥杯蓝桥杯比赛除了对板子各个模块的熟悉外,还有一件事,那就是把它们综合起来运用.当你单独使用板子上的某一个模块时,可能不会有什么问题,甚至对已经反复练习过后的 ...

最新文章

  1. ggcor包的安装与绘图示例
  2. linux版azure应用服务,【应用服务 App Service】解决无法从Azure门户SSH登录问题
  3. 图解ArcGIS API for JavaScript开发环境搭建
  4. php api 实例maccms,苹果cmsV10API接口说明
  5. vanilla_如何在Vanilla JavaScript中操作DOM
  6. LeetCode 560. 和为K的子数组(前缀和差分)
  7. 利用Frame Animation实现动画效果,代码正确,就是达不到变换效果
  8. python bootstrap_Python-bootstrap
  9. 要成为一个 Java 架构师得学习哪些知识?
  10. TCP/IP五层模型(五层因特网协议栈)||| OSI参考模型|||数据的封装与解封装
  11. 卡尔曼滤波simulink例子,位移和速度2变量估计
  12. 【Spring】Spring Boot 和 Redis 常⽤操作
  13. sql server端口_SQL Server端口概述
  14. signature=daa3bbe3ad9a7c162ba9d98f8d9e7530,来用百度密语吧!!!
  15. 敏捷测试的方法和实践
  16. IBEACON 解析代码(C语言和LUA语言)
  17. 树莓派_配置邮件客户端
  18. 席绢言情系列书评总序
  19. A15.从零开始前后端react+flask - 将前后端联系起来
  20. CentOS7 安装cellranger-4.0.0

热门文章

  1. Linux系统与网络、磁盘参数和日志监控等命令详解二
  2. linux 跟踪命令执行过程,Linux的strace命令跟踪线程死锁
  3. 【小5聊】使用HBuilderX打包H5页面实现C#调个推接口,进行app消息推送和消息通知
  4. 与Apache ServiceComb一起玩开源-北邮站
  5. STM8S903K3T6C基于ST Visual Develop开发输入输出按键检测示例
  6. 挑战光纤?电话线上也能实现10Gbps宽带
  7. 对程序员来说CPU是什么?
  8. 攻防世界simple php,攻防世界 新手训练营 simple_php
  9. Nginx 限流方法
  10. C# Excel导入数据