• Arduino框架下合宙ESP32C3 +1.8“tft 网络时钟


    Arduino框架下合宙ESP32C3 +1.8"tft 网络时钟


    本项目是在VSCode PIO平台开发,基于Arduino框架
    在这里插入图片描述

    在这里插入图片描述

    功能实现模块

    • 可以手动配网+SmartConfig配网
    • 1.8" tft_OLED采用TFT_eSPI库驱动,同时兼容合宙的0.96" 80X160屏幕(目前esp32C3带屏幕的开发板已经下架了)
      在这里插入图片描述
      在这里插入图片描述
    • OTA升级功能根据需求,是否启用该函数

    不足之处

    设定的SmartConfig配网保存wifi信息的代码失效,以及通过nvs保存wifi信息也不起作用,暂时没查到是什么原因引起的。导致的后果:如果不是将wifi信息代码中写入的话,每次重启都需要一次SmartConfig配网一次。

    主程序代码

    #include "LuatOS_C3.h"
    #include 
    
    Preferences prefs; // 声明Preferences对象
    TFT_eSPI tft = TFT_eSPI();
    char buf[32] = {0};
    unsigned long lastMs = 0;
    long check1s = 0;
    TFT_eSprite drawBuf(&tft);
    
    void setup() {
      disableCore0WDT();
      Serial.begin(115200);
      delay(500);
      Serial.println("Hello ESP32C3!!");
      prefs.begin("wifi");// use "wifi" namespace,
    if(prefs.isKey("ssid")) { // 如果当前命名空间中有键名为"name"的元素
            Serial.printf("ssid: %s\n\n", prefs.getString("ssid").c_str());
      }
    if(prefs.isKey("password")) { // 如果当前命名空间中有键名为"name"的元素
            Serial.printf("ssid: %s\n\n", prefs.getString("password").c_str());
      }
    if(prefs.isKey("ssid") && prefs.isKey("password") ) WiFi.begin(prefs.getString("ssid").c_str(),prefs.getString("password").c_str());
    
    
      initTFT();
      initLEDs();
      tft.println("Start Config WiFi!");
      if (!AutoConfig())
      {
       autoConfigWifi();
      } 
     
      tft.println("Wifi Connected!");
      sprintf(buf, "IP: %s", WiFi.localIP().toString().c_str());
      tft.println(buf);
      configTime(TZ_SEC, DST_SEC, "ntp.ntsc.ac.cn", "ntp1.aliyun.com");
      delay(2000);
      drawBuf.createSprite(TFT_HEIGHT, TFT_WIDTH);
     // setupOTAConfig();OTA升级功能根据需求,是否启用该函数
      tft.fillScreen(TFT_BLACK);
    }
    
    inline void showCurrentTime() {
      struct tm info;
      getLocalTime(&info);
      strftime(buf, 32, "%T", &info);
      drawBuf.fillRect(0, 0, TFT_HEIGHT, TFT_WIDTH, TFT_BLACK);
      drawBuf.setTextColor(TFT_ORANGE);//TFT_CYAN
      drawBuf.setFreeFont(&FreeSerifBold18pt7b);
      drawBuf.drawCentreString(buf, 80, 10, 1);
      strftime(buf, 32, "%F", &info);
      drawBuf.setTextColor(TFT_GREEN);
      digitalWrite(PIN_LED1, HIGH);
      drawBuf.setFreeFont(&FreeSerifBold12pt7b);
      drawBuf.drawCentreString(buf, 80, 50, 1);
      digitalWrite(PIN_LED1, LOW);
      drawBuf.pushSprite(0, 0);
    }
    
    void loop() {
      auto ms = millis();
      if (ms - check1s > 1000) {
        check1s = ms;
        showCurrentTime();
       // ArduinoOTA.handle();//OTA升级功能根据需求,是否启用该函数
    
       
      }
    }
    
    • 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
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • platformio.ini内容

    由于VSCode PIO不带合宙ESP32C3,开发板型号是自己修改来的,需要根据自己的开发环境配置的修改型号.

    [env:esp32-c3-luat]
    platform = espressif32
    board = esp32-c3-luat
    ; esp32-c3-devkitm-1
    framework = arduino
    upload_speed = 921600
    monitor_speed = 115200
    ;board_build.partitions = partitions_16m.csv
    ; set frequency to 80MHz
    board_build.f_flash = 80000000L
    ; set frequency to 160MHz
    board_build.f_cpu = 160000000L
    board_build.flash_mode =dio
    ;upload_port = /dev/cu.SLAB_USBtoUART
    ;monitor_port = /dev/cu.SLAB_USBtoUART
    
    ; upload_protocol = espota
    ; upload_port = 192.168.50.122
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19

    工程源码

    链接:https://pan.baidu.com/s/1Q14rif9yRlXknzjKNGS9sA 
    提取码:qcse
    
    • 1
    • 2
    • 本项目参考来自github地址:https://github.com/zhuhai-esp/ESP32-C3-LuatOS
  • 相关阅读:
    芒果改进YOLOv5系列:首发结合最新NIPS2022华为诺亚的GhostNetV2 架构:长距离注意力机制增强廉价操作,打造高效轻量级检测器
    Java agent 使用详解
    LeetCode //C - 17. Letter Combinations of a Phone Number
    【数据结构】—交换排序之快速排序究极详解,手把手带你从简单的冒泡排序升级到排序的难点{快速排序}(含C语言实现)
    Matlab基础一、关于初始化数组,数据矩阵,三维数据,字符串数组
    Go语言用Resty库编写的音频爬虫代码
    nodejs+vue+ElementUi废品废弃资源回收系统
    vue3(h5适配)做个记录,避免自己以后忘了哈哈
    华为云云耀云服务器L实例评测|centos系统搭建git私服
    新药发明专利的专利权期限。
  • 原文地址:https://blog.csdn.net/weixin_42880082/article/details/126252481