Arduino +合宙ESP32C3 +1.8/1.44 寸TFT液晶屏驱动显示


  • Arduino IDE找不到ESP32C3的请看我前面那篇文章《合宙ESP32C3 Arduino 初探教程》,当然也可以参考其他优秀的文章,来搭建esp32C3

合宙ESP32C3配合合宙的1.8寸TFT液晶屏屏幕


引脚定义

#define TFT_SCLK 2  // Clock out
#define TFT_MOSI 3  // Data out
#define TFT_RST  10
#define TFT_DC   6
#define TFT_CS   7
#define TFT_BL   11  (可不接)
  • 从上面的两张图的引脚分布和LCD屏幕引脚定义正好是相对应的。可以直接对插。
  • 如果是买的合体的,那么只需要修改setup函数中的屏幕初始化函数:tft.initR(INITR_144GREENTAB);启用这个,注释掉原1.8的屏幕的初始化函数tft.initR(INITR_BLACKTAB); 即可点亮。

所需库

  • Adafruit_GFX

  • Adafruit_BusIO

  • Adafruit_ST7735_and_ST7789_Library

驱动代码

/*所需库点击这里会自动打开管理库页面: http://librarymanager/All#Adafruit_BusIO* This is an example sketch that shows how to toggle the display
* on and off at runtime to avoid screen burn-in.
*
* The sketch also demonstrates how to erase a previous value by re-drawing the
* older value in the screen background color prior to writing a new value in
* the same location. This avoids the need to call fillScreen() to erase the
* entire screen followed by a complete redraw of screen contents.
*
* Originally written by Phill Kelley. BSD license.
* Adapted for ST77xx by Melissa LeBlanc-Williams
*/#include <Adafruit_GFX.h>    //点击这里会自动打开管理库页面: http://librarymanager/All#Adafruit_GFX
#include <Adafruit_ST7735.h> // 点击这里会自动打开管理库页面: http://librarymanager/All#Adafruit_ST7735
//#include <Adafruit_ST7789.h> // Hardware-specific library for ST7789
#include <SPI.h>#ifdef ADAFRUIT_HALLOWING#define TFT_CS        7 // Hallowing display control pins: chip select#define TFT_RST       10 // Display reset#define TFT_DC        6 // Display data/command select#define TFT_BACKLIGHT  11 // Display backlight pin#elif defined(ARDUINO_FEATHER_ESP32) // Feather Huzzah32#define TFT_SCLK 2  // Clock out
#define TFT_MOSI 3  // Data out
#define TFT_RST  10
#define TFT_DC   6
#define TFT_CS   7
#define TFT_BL   11  #elif defined(ESP8266)#define TFT_CS         4#define TFT_RST        16                                            #define TFT_DC         5#else// For the breakout board, you can use any 2 or 3 pins.// These pins will also work for the 1.8" TFT shield.#define TFT_CS        7#define TFT_RST        10 // Or set to -1 and connect to Arduino RESET pin#define TFT_DC         6
#endif#define SerialDebugging true// OPTION 1 (recommended) is to use the HARDWARE SPI pins, which are unique
// to each board and not reassignable. For Arduino Uno: MOSI = pin 11 and
// SCLK = pin 13. This is the fastest mode of operation and is required if
// using the breakout board's microSD card.// For 1.44" and 1.8" TFT with ST7735 (including HalloWing) use:
//Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);// For 1.3", 1.54", and 2.0" TFT with ST7789:
//Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);// OPTION 2 lets you interface the display using ANY TWO or THREE PINS,
// tradeoff being that performance is not as fast as hardware SPI above.
#define TFT_MOSI 3  // Data out
#define TFT_SCLK 2  // Clock out
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);// connect a push button between ground and...
const uint8_t   Button_pin              = 4;// color definitions
const uint16_t  Display_Color_Black        = 0x0000;    //黑色
const uint16_t  Display_Color_Red          = 0x001F;    //红色
const uint16_t  Display_Color_Blue         = 0xF800;    //蓝色
const uint16_t  Display_Color_Green        = 0x07E0;    //绿色
const uint16_t  Display_Color_Yellow       = 0x07FF;    //黄色
const uint16_t  Display_Color_Magenta      = 0xF81F;    //洋红
const uint16_t  Display_Color_Cyan         = 0xFFE0;    //青色
const uint16_t  Display_Color_White        = 0xFFFF;    //白色// The colors we actually want to use
uint16_t        Display_Text_Color         = Display_Color_Black;
uint16_t        Display_Backround_Color    = Display_Color_Yellow;// assume the display is off until configured in setup()
bool            isDisplayVisible        = false;// declare size of working string buffers. Basic strlen("d hh:mm:ss") = 10
const size_t    MaxString               = 16;// the string being displayed on the SSD1331 (initially empty)
char oldTimeString[MaxString]           = { 0 };// the interrupt service routine affects this
volatile bool   isButtonPressed         = false;// interrupt service routine
void senseButtonPressed() {if (!isButtonPressed) {isButtonPressed = true;}
}void displayUpTime() {// calculate seconds, truncated to the nearest whole secondunsigned long upSeconds = millis() / 1000;// calculate days, truncated to nearest whole dayunsigned long days = upSeconds / 86400;// the remaining hhmmss areupSeconds = upSeconds % 86400;// calculate hours, truncated to the nearest whole hourunsigned long hours = upSeconds / 3600;// the remaining mmss areupSeconds = upSeconds % 3600;// calculate minutes, truncated to the nearest whole minuteunsigned long minutes = upSeconds / 60;// the remaining ss areupSeconds = upSeconds % 60;// allocate a bufferchar newTimeString[MaxString] = { 0 };// construct the string representationsprintf(newTimeString,"%lu %02lu:%02lu:%02lu",days, hours, minutes, upSeconds);// has the time string changed since the last tft update?if (strcmp(newTimeString,oldTimeString) != 0) {// yes! home the cursortft.setCursor(10,80);   //(列,行)// change the text color to the background colortft.setTextColor(Display_Backround_Color);// redraw the old value to erasetft.print(oldTimeString);// home the cursortft.setCursor(10,80);// change the text color to foreground colortft.setTextColor(Display_Text_Color);// draw the new time valuetft.print(newTimeString);// and remember the new valuestrcpy(oldTimeString,newTimeString);}
}void setup() {// button press pulls pin LOW so configure HIGHpinMode(Button_pin,INPUT_PULLUP);// use an interrupt to sense when the button is pressedattachInterrupt(digitalPinToInterrupt(Button_pin), senseButtonPressed, FALLING);#if (SerialDebugging)Serial.begin(115200); while (!Serial); Serial.println();#endif// settling timedelay(250);// ignore any power-on-reboot garbageisButtonPressed = false;#ifdef ADAFRUIT_HALLOWING// HalloWing is a special case. It uses a ST7735R display just like the// breakout board, but the orientation and backlight control are different.tft.initR(INITR_HALLOWING);        // Initialize HalloWing-oriented screenpinMode(TFT_BACKLIGHT, OUTPUT);digitalWrite(TFT_BACKLIGHT, HIGH); // Backlight on#else// Use this initializer if using a 1.8" TFT screen:128x160tft.initR(INITR_BLACKTAB);      // Init ST7735S chip, black tab// OR use this initializer (uncomment) if using a 1.44" TFT://tft.initR(INITR_144GREENTAB); // Init ST7735R chip, green tab// OR use this initializer (uncomment) if using a 0.96" 180x60 TFT:// tft.initR(INITR_MINI160x80);  // Init ST7735S mini display// OR use this initializer (uncomment) if using a 1.54" 240x240 TFT://tft.init(240, 240);           // Init ST7789 240x240// OR use this initializer (uncomment) if using a 2.0" 320x240 TFT://tft.init(240, 320);           // Init ST7789 320x240// SPI speed defaults to SPI_DEFAULT_FREQ defined in the library, you can override it here// Note that speed allowable depends on chip and quality of wiring, if you go too fast, you// may end up with a black screen some times, or all the time.//tft.setSPISpeed(40000000);#endif// initialise the displaytft.setFont();tft.fillScreen(Display_Backround_Color);tft.setTextColor(Display_Text_Color);tft.setTextSize(1);// the display is now onisDisplayVisible = true;}void loop() {// unconditional display, regardless of whether display is visibledisplayUpTime();// has the button been pressed?if (isButtonPressed) {// yes! toggle display visibilityisDisplayVisible = !isDisplayVisible;// applytft.enableDisplay(isDisplayVisible);#if (SerialDebugging)Serial.print("button pressed @ ");Serial.print(millis());Serial.print(", display is now ");Serial.println((isDisplayVisible ? "ON" : "OFF"));#endif// confirm button handledisButtonPressed = false;}// no need to be in too much of a hurrydelay(100);}
  • 编译信息
使用 1.10.10  版本的库 Adafruit_GFX 在文件夹: C:\Users\Administrator\Documents\Arduino\libraries\Adafruit_GFX
使用 1.7.3  版本的库 Adafruit_ST7735_and_ST7789_Library 在文件夹: C:\Users\Administrator\Documents\Arduino\libraries\Adafruit_ST7735_and_ST7789_Library
使用 2.0.0  版本的库 SPI 在文件夹: C:\Users\Administrator\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\libraries\SPI
使用 1.11.6  版本的库 Adafruit_BusIO-master 在文件夹: C:\Program Files (x86)\Arduino\libraries\Adafruit_BusIO-master
使用 2.0.0  版本的库 Wire 在文件夹: C:\Users\Administrator\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\libraries\Wire
"C:\\Users\\Administrator\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.6/tools/riscv32-esp-elf/bin/riscv32-esp-elf-size" -A "d:\\arduino\\MyHexDir/luatos_LCD.ino.elf"
项目使用了 250174 字节,占用了 (19%) 程序存储空间。最大为 1310720 字节。
全局变量使用了11356字节,(3%)的动态内存,余留316324字节局部变量。最大为327680字节。

Arduino +合宙ESP32C3 +1.8/1.44 寸TFT液晶屏驱动显示相关推荐

  1. 树莓派驱动1.44寸TFT液晶并实时显示摄像头图像

    ** 需要什么 ** 一块lcd ,市面上大多数为spi ,i2c驱动的lcd,我这块是比赛剩下的模拟8080端口驱动.区别不大,仅需改动发送数据的函数 一个摄像头,我这里使用的是某宝17块钱买来的o ...

  2. 【雕爷学编程】Arduino动手做(136)---0.91寸OLED液晶屏模块

    37款传感器与执行器的提法,在网络上广泛流传,其实Arduino能够兼容的传感器模块肯定是不止这37种的.鉴于本人手头积累了一些传感器和执行器模块,依照实践出真知(一定要动手做)的理念,以学习和交流为 ...

  3. 【雕爷学编程】Arduino动手做(93)--- 0.96寸OLED液晶屏

    37款传感器与执行器的提法,在网络上广泛流传,其实Arduino能够兼容的传感器模块肯定是不止这37种的.鉴于本人手头积累了一些传感器和执行器模块,依照实践出真知(一定要动手做)的理念,以学习和交流为 ...

  4. esp32 cam 1.44寸TFT彩屏 ST7735S驱动 TFT_eSPI库驱动

    ESP32 CAM引脚与TFT1.44(ST7735S)引脚接线 ESP32 CAM TFT 1.44 5V VCC GND GND GND NC NC 5V BLC D14 SCL D15 SDA ...

  5. 合宙ESP32C3 Arduino 初探教程

    合宙ESP32C3 Arduino 初探教程 以为买回来一插上typeC接口就能通过Arduino IDE来个点灯,没想到:1.找不到对应的ESPC3型号,选择其他的点击烧录识别出问题. 到手回来没有 ...

  6. 实惠的Arduino开发板——合宙ESP32C3

    目录 1.0 ESP32C3单片机 2.0 使用方法: 3.0 其他注意事项: 4. 小结 esp32长期以来都是最具性价比的开发板,特别在当今的缺芯潮下,很多MCU价格已经上天,但esp32系列仍然 ...

  7. Arduino IDE搭建合宙ESP32C3开发环境(最简单) 附跑马灯代码

    Arduino IDE搭建合宙ESP32C3开发环境(最简单) 附跑马灯代码 一.安装Arduino IDE 二.搭建合宙简约版ESP32C3开发环境 1.产品示例&管脚定义&原理图 ...

  8. 合宙ESP32C3基于Arduino IDE框架下配置分区表

    合宙ESP32C3基于Arduino IDE框架下配置分区表 关于VSCode PIO配置分区表可以参考示例文章<合宙ESP32C3基于VSCode PIO开发初探教程> 有关Arduin ...

  9. 合宙ESP32C3 更换Flash调整lua固件教程分享

    合宙ESP32C3 更换Flash调整lua固件教程分享 合宙官方的固件编译指南:https://wiki.luatos.com/develop/compile/ESP32C3.html 合宙给出的更 ...

  10. 003.0.96‘OLED+合宙ESP32C3+和风天气预报

    合宙ESP32-C3+OLED天气预报 一.搭建开发框架 使用VScode platformio开发 1.oled显示 #include <Arduino.h> #include < ...

最新文章

  1. CF1398D Colored Rectangles (记忆化搜索DP)
  2. 转载/VMware Workstation环境下的Linux网络设置/适用于无线网络
  3. 去除Coding4Fun中MessagePrompt的边框(Border)
  4. 简单工厂模式、工厂方法模式、抽象工厂模式 之间的对比
  5. shell实例第7讲:awk命令
  6. 相移波束形成算法的MATLAB仿真
  7. java中path和classpath_java中的环境变量path和classpath的作用-Go语言中文社区
  8. Solr单集代码调用案例
  9. 如何使用Eclipse调试Maven构建
  10. 学习使用资源文件[2] - Ico
  11. Flutter InteractiveViewer 支持平移和缩放子Widget
  12. AndroidStudio安卓原生开发_UI高级_自定义主题和样式---Android原生开发工作笔记129
  13. js右下角广告[兼容]
  14. 關於GoogleUpdate.exe
  15. xp系统扫描仪服务器,xp系统扫描仪添加步骤全程的图文教程
  16. 小米8成功刷入Win11ARM64完整版系统
  17. Python-计算三角形边长和面积
  18. 博客做外链(可以发布外链的博客有哪些平台)
  19. 《Python编程:从入门到实践》第12章:武装飞船
  20. 抖音火了,但MCN却在毁掉整个行业

热门文章

  1. 微软商店安装包_闲着不如折腾,教你现在就尝鲜年底才发售的「微软双屏手机」...
  2. 判断网卡MAC地址前缀
  3. 6. Zigbee应用程序框架开发指南 - 应用程序框架Callback接口
  4. 多项式曲线拟合 c语言6,多项式曲线拟合
  5. 记Chrome崩溃解决方案
  6. 2021年声纹识别研究与应用学术研讨会笔记
  7. python pandas向已有excel添加新表sheet/添加数据
  8. Pytorch并行处理机制
  9. 随笔记录使用DNK时遇到的几个问题
  10. 蓝牙linux驱动源代码,基于Linux蓝牙无线模块USB驱动程序开发.pdf