×

带DS3231、BME280、BH1750和ESP01的LED矩阵NTP时钟

消耗积分:0 | 格式:zip | 大小:0.52 MB | 2022-12-01

vinww特烦恼

分享资料个

描述

这就是让我进入 Arduino 的原因。我遇到了尼克的 LED 字时钟,我想我想做那个。

自从下载了他的代码后,我对其进行了修改,加入了额外的传感器和按钮,并添加了一个 ESP01。

BH1750 用于根据光线条件自动调暗显示屏,并且可以在夜间关闭显示屏。BME280 显示温度、湿度和压力。ESP01 用于从 pool.ntp.org 获取时间。

额外的按钮可以轻松调整设置。您可以使用按钮调整光传感器设置,以及更改字体和 NTP/DST/UTC 设置。

我对字时钟做了相当多的改变,它现在有更多的字,并且已经移动了很多到 PROGMEM 以节省 RAM。

代码现在已经完成,除了一些未知的错误和这里和那里的调整之外,我会为它做一个案例。

您将需要调整光传感器代码以匹配您的光照条件,我在明亮的阳光下坐在窗户旁边进行了编码。

ESP01 用于通过 NTP 获取时间,ESP01 在不需要时被编码为睡眠(wifi 关闭),并通过串行唤醒以获取 UNIX 格式的时间。为了方便起见,SSID 名称和密码通过 Arduino 代码传递。

此版本还具有 DST/UTC 和 BST 计算。可以通过菜单调整或禁用这些设置。

设置保存到 EEPROM,这意味着如果您关闭电源并重新打开,您通过菜单所做的更改将被保存。

这些是 Github 上的代码文件:

Code on Github [https://github.com/Ratti3/miniclock]:
Arduino
    LEDClock32x8.ino
    ProgmemData.h
Arduino
    ESP-01_NTP.ino
    LEDClock32x8_ESP01-NTP.ino
    ProgmemData.h

当 ESP01 运行时,Arduino Serial 将显示:

Arduino : Sent NTP request to ESP01
ESP01 : NTP request received from Arduino
[attempt 1 of 3]
Connecting to SSID: TheInternets....connected
SSID: TheInternets, IP Address: 192.168.0.135
Signal Strength (RSSI): -42 dBm
Sending NTP packet to: 195.195.221.100 [attempt 1]
Sending NTP packet to: 195.195.221.100 [attempt 2]
UNIX1562848457
Disabling WiFi....ok

更多图片和说明来...

 

 

 

 

 
poYBAGOIHoKABDP3AAymzRTCK94171.jpg
ESP01 版本,ESP01 需要一个 3.3v 稳压器,可以提供足够的电流
 

 

 
poYBAGOIHoaAZq0RAAOKlyIjRsM044.jpg
仅 Arduino 版本
 

 

 
 
 
 
poYBAGOIHoyAfz5KAApZ7fHRTEM963.jpg
 
1 / 4
 

 

 
 
 
 
poYBAGOIHpKAA7niAAvpON5Ymc8802.jpg
 
1 / 2
 

 

 
 
 
 
poYBAGOIHpeAGYgTAAihLauLxXo285.jpg
 
1 / 3
 

把它们放在一起:

 
 
 
 
poYBAGOIHp2AHz6QAAsC_Dlqe-8291.jpg
 
1 / 10
 

 

 
 
 
 
pYYBAGOIHqSAPn2kABBuSNJmQ3A828.jpg
 
1 / 10
 

 

 
 
 
 
poYBAGOIHsOAe0SHAAzTk3_P-RI271.jpg
 
1 / 8
 

接线:

DS3231, BH1750 and BME280:
 SCL PINS = A5
 SDA PINS = A4
 VCC = 3.3v
LED Matrix:
 CLK = D11
 CS  = D10
 DIN = D12
 VCC = 5v
Switches:
 D2 - Menu
 D3 - Date / +
 D4 - Temp / -
 D5 - Display options
ESP01 - Optional
 D7 - TX pin of ESP01
 D6 - RX pin of ESP01

这些是您可以更改的全局变量:

// Global variables (changeable defaults), numbers in [] brackets are the EEPROM storage location for that value
// Clock settings
// [200] Default intensity/brightness (0-15), can be set via menu
byte intensity = 2;
// [201] Default clock mode. Default = 0 (basic_mode)
byte clock_mode = 0; 
// [206] Define random mode - changes the display type every few hours. Default = 0 (off)
bool random_mode = 0; 
// [207] Define font random mode - changes the font every few hours. 1 = random font on
bool random_font_mode = 0; 
// [208] Define 12 or 24 hour time. 0 = 24 hour. 1 = 12 hour
bool ampm = 0; 
// Light settings
// [202] Default display on/off mode, used by light sensor. 0 = normal, 1 = always on, 2 - always off, 3 - 5 = defined by hour_off_1,2,3
byte display_mode = 5; 
// [209] Default auto light intensity setting
bool auto_intensity = 1; 
// These three define the hour light sensor can turn off display if dark enough, format is 24 hours, the routine for
// this checks between 8.00 and one of these values
byte hour_off_1 = 21; 
byte hour_off_2 = 22; 
byte hour_off_3 = 23;
// Font settings - these are set via the setup Font menu, see set_font_case() routine for all default values:
// [203] Default clock large font style
byte font_style = 2; 
// [204] Default clock large font offset adjustment
byte font_offset = 1; 
// [205] Default clock large font columns adjustment
byte font_cols = 6; 
// DST NTP and UTC settings
// [210] Enable DST function, 1 = enable, 0 = disable
bool dst_mode = 1; 
// [211] Enable NTP function, 1 = enable, 0 = disable
bool ntp_mode = 1; 
// Number of seconds to adjust NTP value before applying to DS3231, takes a few hundred milliseconds to process the ESP01 data
byte ntp_adjust = 1; 
// [213] UTC offset adjustment, hours
int8_t utc_offset = 0; 
// The hour daily NTP/DST sync happens, should be left at 2am if using DST mode
byte ntp_dst_hour = 2; 
// Number of time to retry NTP request 1 = 35 seconds(ish) in total, values 1 - 9
byte ntp_max_retry = 3; 
// Used to calculate when to quit ntp() when it's not receiving data, value in seconds, it is multiplied by ntp_max_retry
byte ntp_timeout = 45; 
// Global constants - SSID and password for WiFi, passed to ESP01 via SoftwareSerial
// The combined SSID and password length cannot exceed 72 characters
// The length of your SSID name, e.g SSID = MyWifi, ssid_len = 6
const byte ssid_len = 8; 
// Your SSID name, e.g MyWifi
const char ssid[] = "YourSSID"; 
// The length of your SSID password, e.g password = password, pass_len = 8
const byte pass_len = 12; 
// Your SSID password, e.g password
const char pass[] = "YourPassword"; 

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

评论(0)
发评论

下载排行榜

全部0条评论

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