当前位置:网站首页>Arduino框架下合宙ESP32C3 +1.8“tft 网络时钟
Arduino框架下合宙ESP32C3 +1.8“tft 网络时钟
2022-08-10 05:02:00 【perseverance52】
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 <Arduino.h>
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升级功能根据需求,是否启用该函数
}
}
platformio.ini
内容
由于VSCode PIO不带合宙ESP32C3,开发板型号是自己修改来的,需要根据自己的开发环境配置的修改型号.
- 参考文章《合宙ESP32C3基于VSCode PIO Arduino开发框架初探教程》有详细说明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
工程源码
链接:https://pan.baidu.com/s/1Q14rif9yRlXknzjKNGS9sA
提取码:qcse
- 本项目参考来自github地址:https://github.com/zhuhai-esp/ESP32-C3-LuatOS
边栏推荐
- 大佬们,运行cdc后oracle归档日志20分钟增长3G是正常现象吗
- 栈与队列 | 有效的括号、删除字符串中的所有相邻元素、逆波兰表达式求值、滑动窗口的最大值、前K个高频元素 | leecode刷题笔记
- 万字总结:分布式系统的38个知识点
- Stacks and Queues | Implementing Queues with Stacks | Implementing Stacks with Queues | Basic Theory and Code Principles
- 十年架构五年生活-06 离职的冲动
- 【Web3 系列开发教程——创建你的第一个 NFT(7)】创建一个 NFT DApp,给你的 NFT 赋予属性,例如图片
- LeetCode 6138. 最长理想子序列 动态规划
- LeetCode·301.删除无效的括号·BFS
- 线程(中):线程安全
- How cursors work in Pulsar
猜你喜欢
虚假新闻检测论文阅读(七):A temporal ensembling based semi-supervised ConvNet for the detection of fake news
How cursors work in Pulsar
2022 R2 transportable pressure vessel filling operation examination question bank simulation platform
网络层与数据链路层
【无标题】
2022G3 Boiler Water Treatment Exam Mock 100 Questions and Mock Exam
【LeetCode】41、 缺失的第一个正数
如何在不同场景下选择合适的示波器探头
【心理学·人物】第二期(学术X综艺)
2022年A特种设备相关管理(电梯)考试模拟100题及答案
随机推荐
webrtc学习--webrtc源码获取
[Web3 Series Development Tutorial - Create Your First NFT (7)] Create an NFT DApp and assign attributes to your NFT, such as pictures
智能锁控板的主要功能有哪些?如何使用?
JVM类加载机制
GP如何进行数据比对?
万字总结:分布式系统的38个知识点
转型做产品,考NPDP靠谱吗?
最强大脑(1)
成为黑客不得不学的语言,看完觉得你们还可吗?
栈与队列 | 有效的括号、删除字符串中的所有相邻元素、逆波兰表达式求值、滑动窗口的最大值、前K个高频元素 | leecode刷题笔记
十年架构五年生活-07 年轻气盛的蜕变
RK3568处理器体验小记
Acwing 59. 把数字翻译成字符串 计数类DP
深度学习——循环神经网络RNN 未完待续
添加路由的2种方式--router
Rpc接口压测
顺序表的删除,插入和查找操作
软考考生注意!2022年下半年报名详细流程来了!
关于rust的mongodb驱动count方法无法与near条件一同使用的问题
西门子Step7和TIA软件“交叉引用”的使用