Cov txheej txheem:

NODEMCU Lua ESP8266 Nrog Lub Sijhawm Tiag (RTC) & EEPROM: 7 Kauj Ruam
NODEMCU Lua ESP8266 Nrog Lub Sijhawm Tiag (RTC) & EEPROM: 7 Kauj Ruam

Video: NODEMCU Lua ESP8266 Nrog Lub Sijhawm Tiag (RTC) & EEPROM: 7 Kauj Ruam

Video: NODEMCU Lua ESP8266 Nrog Lub Sijhawm Tiag (RTC) & EEPROM: 7 Kauj Ruam
Video: NodeMCU V3 ESP8266 - обзор, подключение и прошивка в Arduino IDE 2024, Kaum ib hlis
Anonim
NODEMCU Lua ESP8266 Nrog Sijhawm Sijhawm (RTC) & EEPROM
NODEMCU Lua ESP8266 Nrog Sijhawm Sijhawm (RTC) & EEPROM

Tau txais lub sijhawm raug yog qhov tseem ceeb yog tias koj xav khaws cov ntaub ntawv teev cia. Muaj ntau txoj hauv kev kom tau sijhawm los ntawm cov peev txheej hauv Is Taws Nem.

Koj yuav nug tias vim li cas ho tsis siv ESP8266 los khaws sijhawm rau koj? Zoo koj tuaj yeem, nws muaj nws tus kheej sab hauv RTC (Lub Sijhawm Sijhawm), tab sis ESP8266 muaj 3 lub sijhawm ua haujlwm sib txawv - 52MHz thaum nws khau raj, 80MHz thaum ua haujlwm ib txwm muaj, thiab 160MHz yog txhawb nqa. Yog tias koj xav tau sijhawm khaws cia kom raug, tshwj xeeb tshaj yog lub sijhawm ntev dua, tom qab ntawd RTC sab nraud tuaj yeem muab kev daws teeb meem. Cov qauv no tseem muaj roj teeb thaub qab thaum lub zog poob. RTC tsis yog qhov txaus ntshai vim nws suav lub sijhawm dhau los txij li nws tau teeb tsa thiab txawm hais tias nws yuav ua rau feem ntau daim ntawv thov, nws yuav tsis zoo txaus rau lub sijhawm tseem ceeb. Nws muaj peev xwm kom tau txais lub sijhawm raug los ntawm SNTP lub sijhawm server los ntawm qhov RTC tuaj yeem hloov kho tshiab ib ntus yog tias xav tau.

DS1307 Me Me RTC I2C Module (saum toj no) yog piv txwv ntawm cov khoom no thiab tuaj yeem xaj yuav ntawm Ebay thiab lwm tus neeg muag khoom rau tsawg dua £ 2. Kuj tseem muaj lwm tus zoo li DS1302 thiab DS3231 uas ua haujlwm zoo ib yam thiab raug nqi los ntawm 99p nce mus.

DS1307 module siv I2C interface thiab rau ESP-01 yuav tsum txuas nrog ua:

Vcc - 3.3v, Gnd - Gnd, SDA - D3, SCL - D4

SDA thiab SCL tuaj yeem txuas nrog ib qho ntawm I/O pins ntawm qhov loj ESP8266's (hloov txoj cai raws li). Tsuas yog sab laug sab tes yuav tsum tau txuas nrog ntawm tus qauv no.

Kauj ruam 1: Google Sijhawm

Google Sijhawm
Google Sijhawm

Muaj ntau qhov piv txwv ntawm kev tau txais sijhawm los ntawm Google thiab saib qee yam zoo li no. Thaum koj khiav GoogleTime.lua program koj tau txais txiaj ntsig zoo li no:

dofile ("GoogleTime.lua")> Sijhawm: Friday, 15 Kaum Ob Hlis 2017 11:19:45 GMT

Qhov teeb meem nrog txoj hauv kev no yog tias koj tau txais lub sijhawm nyob rau hauv txoj hlua thiab koj yuav tsum faib txoj hlua rau hauv nws tus kheej cov khoom rau teev, feeb, vib nas this thiab lwm yam. Hauv tus neeg hais lus qhov no yog tus naj npawb ntawm cov vib nas this uas tau dhau mus txij hnub Thursday 1st Lub Ib Hlis 1970 txog rau tam sim no thiab sijhawm. UNIX Epoch (1970/01/01 00:00:00) yog siv los ntawm cov khoos phis tawj feem ntau thiab lub sijhawm dhau los yog khaws cia raws li kos npe 32 ntsis. Qhov no txhais tau tias cov txheej txheem no yuav ua haujlwm txog hnub tim 19 Lub Ib Hlis 2038 thaum tus lej yuav loj heev los khaws cia li no. Ib qho kev daws teeb meem yog khaws tus lej li 64 khoom, tab sis tam sim no txoj kev 32 ntsis yuav txaus.

Txhawm rau teem sijhawm rau 2015 Lub Xya Hli 9, 18:29:49 ntawm RTC sab hauv koj yuav siv kab kab ntawv no:

rtctime.set (1436430589, 0)

Qhov 2 tsis yog vib nas this thiab micro vib nas this.

Koj tuaj yeem nrhiav cov ntaub ntawv ntau ntxiv nyeem NodeMCU Cov Ntaub Ntawv.

Kauj Ruam 2: SNTP Cov Sijhawm Ua Haujlwm

SNTP Cov Sijhawm Ua Haujlwm
SNTP Cov Sijhawm Ua Haujlwm

Cov Txheej Txheem Sijhawm Yooj Yim Network (SNTP) tau muab los ntawm ntau qhov chaw hauv Is Taws Nem, thiab ntau lub tebchaws thoob plaws ntiaj teb muaj cov kev pabcuam no.

Qhov kev zov me nyuam, SNTPTime2.lua teev lub sijhawm ntawm RTC sab hauv. Koj yuav tsum muaj rtctime & sntp cov qauv hauv koj tsim thaum koj nyem koj ESP8266. Qhov kev zov me nyuam tau txais lub sijhawm los ntawm cov neeg rau zaub mov hauv vib nas this thiab micro vib nas this thiab teeb tsa sab hauv RTC nrog rtctime.set (sec, usec).

Qhov kev zov me nyuam qhia hnub thiab sijhawm nyob hauv ntau hom ntawv.

Muaj ntau tus SNTP Servers thoob ntiaj teb thiab qee qhov muaj raws li hauv qab no:

  • sntp.sync ({"216.239.35.0"},
  • sntp.sync ({"0.uk.pool.ntp.org", "0.uk.pool.ntp.org"},
  • sntp.sync ({"3.uk.pool.ntp.org", "143.210.16.201"},
  • sntp.sync ({"0.uk.pool.ntp.org", "1.uk.pool.ntp.org", "3.uk.pool.ntp.org"},

Txhua txoj kab saum toj no ntawm cov cai tuaj yeem hloov pauv rau hauv SNTPTime2.lua program.

Muaj ntau tus SNTP Servers ntawm cov chaw nyob hauv qab no uas rov tuaj yeem siv tau hauv qhov haujlwm.

93.170.62.252, 130.88.202.49, 79.135.97.79, ntp.exnet.com

Google tseem muab cov sijhawm siv sijhawm ntawm cov chaw nyob no:

216.239.35.0, 216.239.35.4, 216.239.35.8, 216.239.35.12

Koj yuav tsum nco ntsoov kom tau lub sijhawm los ntawm lub tebchaws koj nyob lossis koj yuav tau hloov kho nws rau thaj tsam ntiaj teb sib txawv. Tsis tas li qee lub tebchaws muaj lub sijhawm nruab hnub nrig, yog li koj kuj yuav tsum tau ua nrog qhov ntawd ib yam.

Kauj Ruam 3: Tau Txais Sijhawm Los ntawm RTC Module

Tau Txais Sijhawm Los ntawm RTC Module
Tau Txais Sijhawm Los ntawm RTC Module

Qhov program GetRTCTime.lua nyeem lub sijhawm los ntawm sab hauv RTC.

Thawj ntu nyeem lub sijhawm thiab qhia nws hauv vib nas this thiab microseconds.

Qhov thib ob hloov nws mus rau hauv tib neeg nyeem tau ntau dua.

thaum hu tm = rtctime.epoch2cal (rtctime.get ()) nws rov qab:

  • xyoo - 1970 ~ 2038
  • hli - hli 1 ~ 12 hauv xyoo tam sim no
  • hnub - hnub 1 ~ 31 hauv lub hlis tam sim no
  • teev
  • min
  • sec
  • hnub - hnub 1 ~ 366 hauv xyoo tam sim no
  • wday - hnub 1 ~ 7 hauv lub lim tiam tam sim no (Hnub Sunday yog 1)

Txhua qhov khoom tuaj yeem nkag tau raws li tm ["hnub"], tm ["xyoo"] …

Koj tuaj yeem nrhiav cov ntaub ntawv ntau ntxiv nyeem NodeMCU Cov Ntaub Ntawv.

DisplaySNTPtime.lua yog txoj hauv kev nthuav dav ntxiv los qhia hnub thiab sijhawm ntawm LCD 128 x 64 OLED zaub, vim nws yooj yim txuas thiab tuaj yeem siv nrog cov haujlwm no.

Kauj Ruam 4: RTC Tus Neeg Siv Nco

Kev hloov me ntsis ntawm lub sijhawm khaws cia yog RTC sab hauv ntawm ESP8266 muaj 128 x 32 ntsis chaw nyob nco uas tuaj yeem nkag los ntawm tus programmer. Lawv muaj txiaj ntsig tshwj xeeb vim tias lawv tuaj yeem muaj sia nyob tsaug zog tsaug zog ntawm ESP8266. Nws yog nyob ntawm tus programmer los tswj lawv cov kev siv thiab xyuas kom meej tias lawv tsis raug sau dua yam yuam kev.

Kuv tau suav nrog RTCmem.lua, ib txoj haujlwm yooj yim uas qhia tau tias nws siv li cas. Koj yuav tsum muaj rtcmem module hauv koj tsim.

Kauj Ruam 5: Sab Nraud RTC Cov Qauv

Sab Nraud RTC Cov Qauv
Sab Nraud RTC Cov Qauv

Cov txheej txheem RTC sab nraud txuas rau ESP8266 los ntawm I2C interface, uas tsuas yog siv ob tus I/O tus pin thiab yog li ua haujlwm nrog ESP-01 ntxiv rau feem ntau ntawm lwm yam ESP8266 khoom siv.

RTC qhov chaw nyob yog 0x68 thiab nkag mus siv qhov qub I2C cov lus txib. Txawm li cas los xij, muaj qee yam yuav tsum nco ntsoov, cov ntaub ntawv hauv RTC cov ntawv sau cia yog khaws cia hauv BCD hom (hauv paus 16), yog li koj cov haujlwm yuav tsum ua nrog qhov no. Lub sijhawm thiab hnub tim tau muab khaws cia rau hauv 7 daim ntawv sau npe hauv RTC. Ntawm sab hauv RTC, BCD kev hloov pauv tau saib xyuas los ntawm rtctime module.

SetExtRTC.lua hloov cov ntaub ntawv rau BCD thiab teev sijhawm.

ReadExtRTC.lua nyeem cov ntaub ntawv sijhawm thiab luam tawm nws. NCO TSEG: cov ntaub ntawv raug luam tawm hauv hexadecimal.

Kuv tsis tau siv sijhawm ntau los tsim cov zaub raws li koj yuav muaj koj tus kheej lub tswv yim txog yam koj xav ua nrog hnub thiab sijhawm. Nov yog lub cav yooj yim hauv nws daim ntawv yooj yim tshaj plaws, yog li koj tuaj yeem txhim kho nws ntxiv yog tias koj xav tau.

Kauj Ruam 6: Txheeb Cov Ntaub Ntawv

Cov Ntaub Ntawv Teev Npe
Cov Ntaub Ntawv Teev Npe

Yog tias koj saib ze ntawm RTC cov qauv, koj yuav pom tias lawv muaj AT24C32 EEPROM IC lossis zoo sib xws ua rau lawv, lossis koj tuaj yeem siv 24C256 pawg thawj coj saib zoo li saum toj no. Feem ntau ntawm EEPROM ICs no muaj tus pin zoo ib yam li saum toj no. Lawv tuaj nrog ntau qhov chaw khaws cia, tab sis lawv txhua tus tau nkag mus ib yam nkaus. Raws li AT24C32 twb tau muab muag rau ntawm lub rooj tsavxwm, nws tuaj yeem siv ncaj qha los ntawm I2C ntawm sab nraud RTC.

Yog tias koj tsuas muaj 24C256 IC lossis zoo sib xws, koj tuaj yeem teeb nws hauv lub rooj mov ci, txuas A1, A2 thiab A3 rau Gnd, Vcc mus rau 3.3V thiab SDA THIAB SCL rau I2C, WP tuaj yeem sab laug. Qee qhov EEPROM ICs tsuas yog ua haujlwm ntawm 5V, yog li tshawb xyuas cov ntaub ntawv cuam tshuam ua ntej.

ByteWR.lua sau 1 byte ntawm cov ntaub ntawv rau qhov chaw nco 0x00 ntawm EEPROM thiab nyeem nws rov qab.

Desiderata.lua sau ob peb kab ntawm cov ntawv nto moo mus rau EEPROM.

eeRead.lua nyeem cov ntaub ntawv los ntawm EEPROM thiab luam tawm nws.

NCO TSEG: Cov haujlwm no yuav tsum ua haujlwm nrog lwm EEPROM cov laug cam ib yam.

Kauj Ruam 7: Xaus

Kuv tau sim qhia pom li cas RTC thiab EEPROM ua haujlwm rau kev txiav cov ntaub ntawv. Qhov no tsuas yog pib rau koj txhawm rau txhim kho ntxiv. Koj tuaj yeem txuas ntau yam khoom siv rau I2C tsheb npav xws li lub teeb pom kev zoo, ntsuas ntsuas lub ntsuas pa, ntsuas kub thiab av noo thiab sau cov ntaub ntawv ntawm EEPROM.

Pom zoo: