Luat合宙ESP32C3教程-点亮ST7735驱动1.8寸TFT液晶屏

前段时间买了这款CORE-ESP32-C3开发板,相比ESP8266主频高不少,多了蓝牙功能。最近尝试用这块开发板驱动手上st7735芯片的tft屏幕,记录一下过程:

1.配置好platformio环境:选择开发板型号为airm2m_core_esp32c3,Arduino开发框架。

2.添加TFT_eSPI库:用来驱动屏幕的,添加完成后打开.pio\libdeps\airm2m_core_esp32c3\TFT_eSPI目录下的User_Setup.h

主要改以下地方:

#define TFT_WIDTH  128
#define TFT_HEIGHT 160
#define ST7735_GREENTAB2
#define TFT_INVERSION_OFF
#define TFT_BACKLIGHT_ON HIGH
#define TFT_MOSI 3 // In some display driver board, it might be written as "SDA" and so on.
#define TFT_SCLK 2
#define TFT_CS   7  // Chip select control pin
#define TFT_DC   6  // Data Command control pin
#define TFT_RST  10  // Reset pin (could connect to Arduino RESET pin)
#define SPI_FREQUENCY  27000000 //太高会出问题

测试程序:

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

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

uint32_t targetTime = 0; // for next 1 second timeout

byte omm = 99;
bool initial = 1;
byte xcolon = 0;
unsigned int colour = 0;

static uint8_t conv2d(const char *p)
{
  uint8_t v = 0;
  if ('0' <= *p && *p <= '9')
    v = *p - '0';
  return 10 * v + *++p - '0';
}

uint8_t hh = conv2d(__TIME__), mm = conv2d(__TIME__ + 3), ss = conv2d(__TIME__ + 6); // Get H, M, S from compile time

void setup(void)
{
  tft.init();
  tft.setRotation(1);
  tft.fillScreen(TFT_BLACK);

  tft.setTextColor(TFT_YELLOW, TFT_BLACK); // Note: the new fonts do not draw the background colour

  targetTime = millis() + 1000;
}

void loop()
{
  if (targetTime < millis())
  {
    targetTime = millis() + 1000;
    ss++; // Advance second
    if (ss == 60)
    {
      ss = 0;
      omm = mm;
      mm++; // Advance minute
      if (mm > 59)
      {
        mm = 0;
        hh++; // Advance hour
        if (hh > 23)
        {
          hh = 0;
        }
      }
    }

    if (ss == 0 || initial)
    {
      initial = 0;
      tft.setTextColor(TFT_GREEN, TFT_BLACK);
      tft.setCursor(8, 52);
      tft.print(__DATE__); // This uses the standard ADAFruit small font

      tft.setTextColor(TFT_BLUE, TFT_BLACK);
      tft.drawCentreString("It is windy", 120, 48, 2); // Next size up font 2

      // tft.setTextColor(0xF81F, TFT_BLACK); // Pink
      // tft.drawCentreString("12.34",80,100,6); // Large font 6 only contains characters [space] 0 1 2 3 4 5 6 7 8 9 . : a p m
    }

    // Update digital time
    byte xpos = 6;
    byte ypos = 0;
    if (omm != mm)
    { // Only redraw every minute to minimise flicker
      // Uncomment ONE of the next 2 lines, using the ghost image demonstrates text overlay as time is drawn over it
      tft.setTextColor(0x39C4, TFT_BLACK); // Leave a 7 segment ghost image, comment out next line!
      // tft.setTextColor(TFT_BLACK, TFT_BLACK); // Set font colour to black to wipe image
      //  Font 7 is to show a pseudo 7 segment display.
      //  Font 7 only contains characters [space] 0 1 2 3 4 5 6 7 8 9 0 : .
      tft.drawString("88:88", xpos, ypos, 7); // Overwrite the text to clear it
      tft.setTextColor(0xFBE0);               // Orange
      omm = mm;

      if (hh < 10)
        xpos += tft.drawChar('0', xpos, ypos, 7);
      xpos += tft.drawNumber(hh, xpos, ypos, 7);
      xcolon = xpos;
      xpos += tft.drawChar(':', xpos, ypos, 7);
      if (mm < 10)
        xpos += tft.drawChar('0', xpos, ypos, 7);
      tft.drawNumber(mm, xpos, ypos, 7);
    }

    if (ss % 2)
    { // Flash the colon
      tft.setTextColor(0x39C4, TFT_BLACK);
      xpos += tft.drawChar(':', xcolon, ypos, 7);
      tft.setTextColor(0xFBE0, TFT_BLACK);
    }
    else
    {
      tft.drawChar(':', xcolon, ypos, 7);
      colour = random(0xFFFF);
      // Erase the old text with a rectangle, the disadvantage of this method is increased display flicker
      tft.fillRect(0, 64, 160, 20, TFT_BLACK);
      tft.setTextColor(colour);
      tft.drawRightString("Colour", 75, 64, 4); // Right justified string drawing to x position 75
      String scolour = String(colour, HEX);
      scolour.toUpperCase();
      char buffer[20];
      scolour.toCharArray(buffer, 20);
      tft.drawString(buffer, 82, 64, 4);
    }
  }
}

烧录,观察屏幕是否正常显示,如果显示不正常可修改User_setup.h里的配置

 

引用\[1\]中的代码展示了在ESP32C3上使用sdmmc模块进行SD卡的挂载、写入和读取操作。代码中使用了sdmmc.init函数初始化SD卡,并通过io.writeFile函数将数据写入SD卡中的test.txt文件,然后通过io.readFile函数读取test.txt文件的内容。最后使用sdmmc.deinit函数卸载SD卡。 引用\[2\]提供了使用调试串口下载固件的方法。在ESP32C3上,可以使用ESP32C3的串口0进行连接,并使用乐鑫官方提供的flash_download_tool工具选择factory_MINI-1.bin进行下载。 引用\[3\]中的内容是关于树莓派(Raspberry Pi)的配置信息,与ESP32C3和SD卡无关。 综上所述,ESP32C3可以通过sdmmc模块进行SD卡的挂载、写入和读取操作,同时可以使用调试串口下载固件。 #### 引用[.reference_title] - *1* [【Luat-esp32c3】4.2 文件系统——sdmmc挂载tf卡](https://blog.csdn.net/qq_38091632/article/details/123905370)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [【ESP32C3系列】00-初识ESP32C3](https://blog.csdn.net/qq_14883963/article/details/128525894)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [树莓派串口2挂ESP32C3(推荐)](https://blog.csdn.net/weixin_42381351/article/details/120860722)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值