×

TTGO网络手表开源分享

消耗积分:0 | 格式:zip | 大小:0.44 MB | 2022-11-15

李晓鹏

分享资料个

描述

这是一个 TTGO T1 板,它是一个 ESP32 供电的开发板,具有 ST7789V 1.14 英寸显示屏。

这是这个委员会的一个很酷的项目,一个“互联网时钟”。

我一直想做一个时钟项目,因为它需要在一个小巧紧凑的外形中塞满很多东西。

例如,要运行时钟,我们需要一个 LiPo 电池并为该电池充电,我们需要在其上使用某种充电电路。时钟还需要深度睡眠模式,以防止电池持续放电。

充电电路具有过充电和过放电功能,可以保护电池免受这两个问题的影响,此处可以使用的一种 IC 是 TP4056,它非常适合此类任务。

但是 TTGO T1 已经有一个电池管理 IC,所以我们真的不需要制作任何复杂的电路,我们也不需要在这个板上添加一个外部显示器,因为它已经有一个非常强大的板载显示器。

此外,此设置不需要 PCB。

即使是钟体,我也会制作一个定制的外壳,上面有腕带插槽。

无论如何,让我们开始这个小型构建的主要部分 - 编辑 ESP32 时钟示例草图。

但即使在此之前,这些都是你需要的这个小建筑的东西_

在开始这个项目之前,您需要在 Arduino IDE 上安装 ESP32 Boards 核心,这是必要的。从这里安装它们 - https://github.com/espressif/arduino-esp32

  • 所以首先,打开 SimpleTime 草图,它可以在Example>ESP32>Time>SimpleTime中找到

这是我们将用作基本草图的通用互联网时钟草图。

#include <WiFi.h>
#include "time.h"

const char* ssid       = "YOUR_SSID";
const char* password   = "YOUR_PASS";

const char* ntpServer = "pool.ntp.org";
const long  gmtOffset_sec = 3600;
const int   daylightOffset_sec = 3600;

void printLocalTime()
{
  struct tm timeinfo;
  if(!getLocalTime(&timeinfo)){
    Serial.println("Failed to obtain time");
    return;
  }
  Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S");
}

void setup()
{
  Serial.begin(115200);
  
  //connect to WiFi
  Serial.printf("Connecting to %s ", ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
      delay(500);
      Serial.print(".");
  }
  Serial.println(" CONNECTED");
  
  //init and get the time
  configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
  printLocalTime();

  //disconnect WiFi as it's no longer needed
  WiFi.disconnect(true);
  WiFi.mode(WIFI_OFF);
}

void loop()
{
  delay(1000);
  printLocalTime();
}

我们的目标是在 TTGO 的显示器上显示串行监视器中的时间,为此,我们必须在此草图中更改几行代码。

  • 我们首先在这个草图中添加我们的 SSID 和密码。
const char* ssid       = "YOUR_SSID";
const char* password   = "YOUR_PASS";
  • 现在我们必须添加可以从这里找到的 gmtOffset_sec。例如,我住在印度,这里的格林威治标准时间是 +5:30。
  • +5:30 秒是 19800 秒,所以我们在 GMT 偏移量中添加 19800
 
 
 
pYYBAGNxjTuAbE7CAAL4aME9jV0364.jpg
 
1 / 2
 
const long  gmtOffset_sec = 19800;

接下来是夏令时偏移设置,如果您所在的国家/地区有夏令时,则根据该时间(以秒为单位)进行设置,如果没有,则将其设置为零。

const int   daylightOffset_sec = 0;

从这里了解夏令时

这将是最终的草图(不完全是最终的,这只是用于串行打印的时间)

#include <WiFi.h>
#include "time.h"

const char* ssid       = "xxxxxx";
const char* password   = "pppppp";

const char* ntpServer = "pool.ntp.org";
const long  gmtOffset_sec = 19800;
const int   daylightOffset_sec = 0;

void printLocalTime()
{
  struct tm timeinfo;
  if(!getLocalTime(&timeinfo)){
    Serial.println("Failed to obtain time");
    return;
  }
  Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S");
}

void setup()
{
  Serial.begin(115200);
  
  //connect to WiFi
  Serial.printf("Connecting to %s ", ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
      delay(500);
      Serial.print(".");
  }
  Serial.println(" CONNECTED");
  
  //init and get the time
  configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
  printLocalTime();

  //disconnect WiFi as it's no longer needed
  WiFi.disconnect(true);
  WiFi.mode(WIFI_OFF);
}

void loop()
{
  delay(1000);
  printLocalTime();
}
  • 插入您的 TTGO 板
  • 在董事会经理中选择合适的董事会
  • 选择正确的端口
  • 点击上传
  • 现在打开串行监视器,您将看到当前时间以 1 秒的间隔重复打印。
 

如果您的时间不正确,那么这可能是因为 UTC 偏移量和夏令时偏移量错误。

现在,这是基本的互联网时间草图,为了在 TTGO T1 板上显示它,我们只需要使用一个简单的函数,让我们在 TTGO 的显示器上显示任何内容。

但在此之前,您需要安装此库,这是我们执行此任务所需的 TFT 显示库。

我们首先添加TFT_eSPI 库和在显示器上打印任何内容所需的其他重要代码行。

这是主要草图

#include  // Graphics and font library for ST7735 driver chip
#include 
#include 
#include "time.h"

const char* ssid       = "xxxxxx"; //add your WIFI Credentials
const char* password   = "pppppp";

const char* ntpServer = "pool.ntp.org";
const long  gmtOffset_sec = 19800;    //UTC Offset!
const int   daylightOffset_sec = 0;



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

#define TFT_BLACK 0x0000 // black

void setup(void) {
  tft.init();
  tft.setRotation(1);
  
  Serial.begin(115200);
  
  Serial.printf("Connecting to %s ", ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
      delay(500);
      Serial.print(".");
  }
  Serial.println(" CONNECTED");
  
  configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
  printLocalTime();

  WiFi.disconnect(true);
  WiFi.mode(WIFI_OFF);
 
}

void loop() {

delay(1000);
printLocalTime();
}


void printLocalTime()
{
  struct tm timeinfo;
  if(!getLocalTime(&timeinfo)){
    Serial.println("Failed to obtain time");
    return;
  }
  
  tft.fillScreen(TFT_BLACK);
  tft.setCursor(0, 0, 2);
  tft.setTextColor(TFT_WHITE,TFT_BLACK);  
  tft.setTextSize(1);
  tft.println(&timeinfo, "%A");

  tft.setCursor(0, 20, 2);
  tft.setTextColor(TFT_WHITE,TFT_BLACK);  
  tft.setTextSize(1);
  tft.println(&timeinfo, "%B %d %Y");

  tft.setCursor(0, 40, 2);
  tft.setTextColor(TFT_WHITE,TFT_BLACK);  
  tft.setTextSize(1);
  tft.println(&timeinfo,"%H:%M:%S");

}

将此草图上传到您的 TTGO 板上,这将是结果-

 
 
 
 
1 / 2
 

至于电池,我使用了一个 3.7V 500mA Lipo 电池,这是我从一个旧项目中抢救出来的。

 

此外,我们可以通过将这行代码从 1 更改为 2 来更改字体的大小。

tft.setTextColor(TFT_WHITE,TFT_BLACK);  
  tft.setTextSize(1); //Change it to 2
  tft.println(&timeinfo, "%A");
 

我必须将 LiPo 电池的连接线更改为 TTGO T1 板随附的较小连接线。

这是这个手表项目的基本设置。

接下来是为此设置设计一个主体。为此,我将使用 Fusion360。

定制车身概念

 
 
 
 
1 / 3
 

我为 TTGO 板设计了这个 Body,看起来像 M5StickC 板,这个 TTGO 板的 3D 模型是从grabcad 用户 MIMOSA下载的

目前,我还没有决定这个项目的腕带,我可能也会为这个项目购买通用皮革表带。

这是第 2 部分的全部内容,这个手表项目的基本设置是这样的,一个 TTGO T 显示板与一个 LiPo Cell 相连,它在其显示屏上显示当前时间和日期,这一切都很好地封装在一个 3D 打印体中.

结果

 

请继续关注这个手表项目的第 2 部分,我会回来的!


声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

评论(0)
发评论

下载排行榜

全部0条评论

快来发表一下你的评论吧 !