Cov txheej txheem:
- Kauj Ruam 1: Qhia tawm
- Kauj ruam 2: Sib dhos
- Kauj Ruam 3: Sib dhos - Rooj
- Kauj Ruam 4: Adafruit GFX Library
- Kauj Ruam 5: Adafruit ST7735 Lub Tsev Qiv Ntawv
- Kauj Ruam 6: NTPClient Library
- Kauj ruam 7: ESP32_NTP.ino
- Kauj ruam 8: Cov ntaub ntawv
Video: Tsis Txhob Nkim Koj Lub Sijhawm: Siv NTP!: 8 Kauj Ruam
2024 Tus sau: John Day | [email protected]. Kawg hloov kho: 2024-01-30 09:27
Ua koj lub sijhawm suav! Nov yog cov ncauj lus sib tham nquag ntawm kuv cov neeg siv khoom, thiab yog vim li cas? Vim yog qhov yooj yim thiab qhov tsis tseem ceeb uas thaum koj ua cov ntaub ntawv teev npe, thiab rau txhua yam cuam tshuam nrog kev siv tshuab, koj xav tau lub sijhawm raug! Thiab muaj ntau txoj hauv kev los ntsuas sijhawm: moos nrog roj teeb, RTC (Lub Sijhawm Tiag), ntawm lwm tus. Tab sis qhov kuv xav qhia koj hnub no (uas qhia hnub tim, hnub ntawm lub lim tiam, thiab sijhawm) yog NTP (Network Time Protocol), uas yog online. Hauv cov vis dis aus no, peb yuav khaws cov ntaub ntawv hnub tim thiab sijhawm online, thiab qhia cov ntaub ntawv ntawm cov zaub.
Kauj Ruam 1: Qhia tawm
Kauj ruam 2: Sib dhos
Kauj Ruam 3: Sib dhos - Rooj
Kauj Ruam 4: Adafruit GFX Library
Hauv Arduino IDE, mus rau Sketch-> Xws li Tsev Kawm Ntawv-> Tswj Tsev Qiv Ntawv …
Nruab Adafruit GFX Library
Kauj Ruam 5: Adafruit ST7735 Lub Tsev Qiv Ntawv
Hauv Arduino IDE, mus rau Sketch-> Xws li Tsev Kawm Ntawv-> Tswj Tsev Qiv Ntawv …
Nruab Adafruit ST7735
Kauj Ruam 6: NTPClient Library
Mus rau https://github.com/taranais/NTPClient thiab rub taranais-hloov NTPClient tsev qiv ntawv.
Unzip thiab muab cov ntawv tais ceev tseg rau hauv C: / Users / Documents / Arduino / libraries
Kauj ruam 7: ESP32_NTP.ino
Suav nrog thiab txhais
#include #include // Biblioteca NTPClient modificada #include // Socket UDP #include // Display #include // Display #include // Pinos do display #define DISPLAY_DC 12 // A0 #define DISPLAY_CS 13 // CS #define DISPLAY_MOSI 14 // SDA #define DISPLAY_CLK 27 // SCK #define DISPLAY_RST 0 // Fuso Horário, tsis muaj caso horário de verão de Brasília int timeZone = -2; // Struct com os dados do dia e hora struct Date {int dayOfWeek; koj dag; hli muaj; int xyoo; int teev; feeb feeb; int vib nas this; }; // Socket UDP que a lib utiliza para recuperar dados sobre o horário WiFiUDP udp; // Objeto responsável por recuperar dados sobre horário NTPClient ntpClient (udp, // socket udp "0.br.pool.ntp.org", // URL do servwer NTP timeZone*3600, // Deslocamento do horário em relacão ao GMT 0 60000); // Intervalo entre verificações online // Nomes dos dias da semana char* dayOfWeekNames = {"Hnub Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; // Objeto responsável pelo display Adafruit_ST7735 zaub = Adafruit_ST7735 (DISPLAY_CS, DISPLAY_DC, DISPLAY_MOSI, DISPLAY_CLK, DISPLAY_RST);
Teeb
teeb tsa tsis muaj dab tsi () {Serial.begin (115200); setupDisplay (); txuasWiFi (); setupNTP (); // Cria uma nova tarefa no core 0 xTaskCreatePinnedToCore (wifiConnectionTask, // Função que será executada "wifiConnectionTask", // Nome da tarefa 10000, // Tamanho da memória disponível (em WORDs) NULL, // N vamo vamos passro nen parameter, // prioridade NULL, // Não precisamos de referência para a tarefa 0); // Tsis txhob ua core}
Teeb NTNT
tsis muaj dabtsis teeb tsa NTP () {// Inicializa o tus neeg siv NTP ntpClient.begin (); // Espera pelo primeiro hloov tshiab online Serial.println ("Tos rau thawj qhov hloov tshiab"); thaum (! ntpClient.update ()) {Serial.print ("."); ntpClient.forceUpdate (); ncua (500); } Serial.println (); Serial.println ("Thawj Qhov Hloov Tshiab Ua tiav"); }
WifiConnectionTask
// Tarefa que verifica se conexão caiu e tenta reconectarvoid wifiConnectionTask (void* param) {thaum (tseeb) {// Se WiFi tsis tau txuas nrog yog (WiFi.status ()! = WL_CONNECTED) {// Manda conectar connectWiFi (); } // Ncua de 100 zuam vTaskDelay (100); }}
ConnectWiFi
void connectWiFi () {Serial.println ("Txuas"); // Troque pelo nome e senha da sua rede WiFi WiFi.begin ("SSID", "12345678"); // Espera enquanto não estiver conectado thaum (WiFi.status ()! = WL_CONNECTED) {Serial.print ("."); ncua (500); } Serial.println (); Serial.print ("Txuas nrog"); Serial.println (WiFi. SSID ()); }
Teeb Teeb
void setupDisplay () {display.initR (INITR_BLACKTAB); // Inicializa o tso saib display.setRotation (3); // Rotaciona display.setTextSize (2); // Tamanho ua texto display.fillScreen (ST77XX_BLACK); // Preenche com a cor preta display.setCursor (0, 0); // Coloca o cursor no começo display.setTextColor (ST77XX_WHITE, ST77XX_BLACK); // Texto branco com fundo preto display.setTextWrap (tsis tseeb); // Tsis siv neeg lub tshuab hluav taws xob}
Loop
void loop () {// Recupera os dados sobre a data e horário Date date = getDate (); // Rov pib dua tus cursor display.setCursor (0, 0); // Exibe os dados no display display.printf (" %s / n / n %s / n / n %02d/ %02d/ %d / n / n %02d: %02d: %02d", WiFi. SSID ().c_str (), dayOfWeekNames [date.dayOfWeek], date.day, date.month, date.year, date.hours, date.minutes, date.seconds); ncua (100); }
GetDate
Date getDate () {// Recupera os dados de data e horário usando o client NTP char* strDate = (char*) ntpClient.getFormattedDate (). C_str (); // Passa os dados da string para a struct Hnub tim; sscanf (strDate, "%d-%d-%dT%d:%d:%dZ", & date.year, & date.month, & date.day, & date.hours, & date.minutes, & date.seconds); // Dia da semana de 0 a 6, sendo 0 o domingo date.dayOfWeek = ntpClient.getDay (); hnub rov tuaj; }
Kauj ruam 8: Cov ntaub ntawv
Rub tawm cov ntawv
INO
Pom zoo:
Lub Sijhawm Siv Lub Sijhawm Nco Ntsoov (tsuas Ua Haujlwm ntawm Windows, Ios Yuav Tsis Ua Haujlwm): 5 Kauj Ruam
Screen Time Usage Reminder (tsuas Ua Haujlwm ntawm Windows, Ios Yuav Tsis Ua Haujlwm): Taw Qhia Qhov no yog lub tshuab siv tau los ntawm Arduino, nws ceeb toom koj kom so los ntawm kev ua "biiii!" suab thiab ua rau koj lub khoos phis tawj rov qab xauv npo tom qab siv sijhawm 30 feeb ntawm lub sijhawm tshuaj ntsuam. Tom qab so rau 10 feeb nws yuav "b
Teeb DS3231 RTC (Lub Sijhawm Sijhawm) Kom raug, Ceev thiab Tsis Siv Neeg Siv Java (+-1s): 3 Kauj Ruam
Teeb DS3231 RTC (Lub Sijhawm Sijhawm) Kom raug, Ceev thiab Ceev Ceev Siv Java (+-1s): Cov lus qhia no yuav qhia koj yuav teev sijhawm li cas hauv DS3231 Lub Sijhawm Tiag Siv Arduino thiab daim ntawv thov Java me me uas siv qhov txuas txuas ntawm Arduino.Qhov laj thawj yooj yim ntawm txoj haujlwm no: 1. Arduino xa cov ntawv thov ua ntu zus
Siv DS1307 thiab DS3231 Lub Sijhawm Teev Sijhawm Sijhawm Nrog Arduino: 3 Kauj Ruam
Siv DS1307 thiab DS3231 Lub Sijhawm Caij Nyoog Sijhawm Nrog Arduino: Peb tseem tau txais kev thov yuav siv DS1307 thiab DS3231 lub sijhawm teev sijhawm nrog Arduino los ntawm ntau qhov chaw-yog li qhov no yog thawj ntawm ob ntu kev qhia yuav siv li cas. Txog qhov kev qhia Arduino no peb muaj ob lub sijhawm teev sijhawm ua haujlwm rau peb
Tsis txhob yuav GSM Module, Siv Koj Lub Xov Tooj Qub!: 6 Kauj Ruam
Tsis txhob Yuav GSM Module, Siv Koj Lub Xov Tooj Qub!: Yog li tsis ntev los no kuv tau ua ntau txoj haujlwm wireless, feem ntau yog nyob ib puag ncig ntawm Bluetooth module tab sis txij thaum ntawd los kuv tau xav txav mus thiab pib ua kuv cov phiaj xwm SMS lossis Kev hu xov tooj tswj uas yuav luag yooj yim nrog kev pab ntawm GSM module
Tsis txhob Sau Koj Tus Pin rau Koj Lub Suab Hu: 3 Kauj Ruam
Tsis txhob Sau Koj Tus Pin rau Koj Lub Suab Xov Tooj: Puas yog koj nkees nkees nkag mus rau koj lub suab xa ntawv txhua lub sijhawm koj tshuaj xyuas koj lub suab. Zoo kuv yog li kuv tau pom qhov dag rau qhov ntawd