Cov txheej txheem:

Ntse Tswb Tswb Siv Magicbit (Arduino): 10 Kauj Ruam
Ntse Tswb Tswb Siv Magicbit (Arduino): 10 Kauj Ruam

Video: Ntse Tswb Tswb Siv Magicbit (Arduino): 10 Kauj Ruam

Video: Ntse Tswb Tswb Siv Magicbit (Arduino): 10 Kauj Ruam
Video: Plab Plab Ntswg..(Pluav Pluav Ntswg) Maiv Twm New Song 2023-2024 2024, Hlis ntuj nqeg
Anonim
Image
Image

Phau ntawv qhia no qhia yuav ua li cas thiaj ua lub tswb ntse siv OLED zaub hauv Magicbit dev pawg thawj coj tsis tau siv ib qho qauv RTC.

Khoom siv

  • Magicbit
  • USB-A rau Micro-USB Cable

Kauj ruam 1: Zaj dab neeg

Hauv qhov kev qhia no peb yuav kawm paub yuav ua li cas thiaj ua tau lub tswb nrov siv Magicbit.

Kauj ruam 2: HARDWARE SETUP

Txuas koj Magicbit rau lub khoos phis tawj siv USB cable.

Kauj Ruam 3: SOFTWARE SETUP

Qhib koj Arduino IDE thiab teeb tsa pawg thawj coj nrog Arduino IDE. Qhov txuas hauv qab no hais txog yuav ua li cas. Yog li peb qhia koj rau qhov ntawd ua ntej mus rau qhov txuas thiab tau paub nrog Magic ntsis.

magicbit-arduino.readthedocs.io/en/latest/…

Tam sim no xaiv qhov tseeb pawg thawj coj saib thiab chaw nres nkoj. Hauv qhov xwm txheej no pawg thawj coj yog Magicbit. Cov tsev qiv ntawv twb tau teeb tsa thaum nyob hauv Magicbit cov tsev qiv ntawv.

Kauj Ruam 4: Txoj Kev Xav thiab Txoj Kev

Yog tias koj saib thawj daim vis dis aus, koj tuaj yeem pom cov zaub muaj 2 cov ntxaij vab tshaus.

  • moos tshuaj ntsuam uas qhia sijhawm nthuav dav
  • lub tswb ceeb toom uas qhia cov lus ceeb toom

Rau toggle ntawm ob lub vijtsam peb siv ib lub laub khawm ntawm ob hauv Magicbit. Cov nyees khawm no txuas nrog 35 (khawm sab laug) thiab 34 (txoj cai khawm) pins ntawm ESP32 hauv Magicbit. Txhawm rau qhia lub sijhawm thiab lwm yam ntsiab lus peb tau siv builtin OLED zaub hauv magicbit.

Cia tham txog seb cov ntxaij vab tshaus duab no ua haujlwm li cas.

Lub moos tshuaj ntsuam muaj lub moos sib xws, lub moos digital, hnub tim, hli thiab xyoo ntawv.

Txog kev tsim lub moos sib piv peb siv qee cov duab ua haujlwm uas muaj nyob hauv tsev qiv ntawv duab hu ua Adafriut GFX. Los ntawm kev siv lub voj voog ua haujlwm thiab kab ua haujlwm peb tsim lub ntsej muag zoo ib yam. Cov haujlwm yooj yim geometrical hu ua kev txhaum thiab cos yog siv rau txoj haujlwm ntawm lub moos tes. Yog li peb tsuas yog nkag lub kaum sab xis uas sib haum rau lub sijhawm rau tig tes. rau qhov ntawd peb xub hloov lub sijhawm mus rau kaum raws li hauv qab no.

  • kaum feeb tes = feeb*(360/60)
  • kaum teev tes = teev*(360/12)

Lub kaum sab xis ntsuas nrog txoj kab ntawm nruab nrab ntawm lub ntsej muag ntawm lub moos thiab tus lej 12 hauv lub ntsej muag lub ntsej muag. Ua haujlwm txhaum thiab cos peb tuaj yeem xam x thiab y qhov ua haujlwm ntawm qhov kawg ntawm teev thiab feeb kab. Daim duab hauv qab no piav qhia nws ua li cas.

Raws li kev tswj hwm peb luam teev thiab feeb ntawm txhais tes los ntawm kab kab. Kuj tseem muaj cov ntawv luam ua haujlwm hauv Adafruit GFX lub tsev qiv ntawv. Nws pab luam lwm cov ntsiab lus (hnub, hli thiab sijhawm qhia ua lej) ntawm cov khoom. Koj tuaj yeem hloov txoj haujlwm ntawm lub moos sib piv thiab cov ntawv sau los ntawm kev hloov pauv tsis hauv cov cai.

Raws li zoo li lub vijtsam moos peb siv cov ntawv luam ua haujlwm hauv Adafruit GFX lub tsev qiv ntawv rau luam tus lej ntawm OLED zaub ntawm qhov chaw tsim nyog.

Kauj Ruam 5: Tau Txais Lub Sijhawm Hauv Zos

Qhov tseem ceeb tshaj plaws ntawm lub moos yog yuav ua li cas peb tau txais lub sijhawm hauv zos kom raug. Rau lub hom phiaj ntawd koj tuaj yeem siv sab nraud RTC moos module lossis inbuilt RC moos hauv ESP32 hauv Magicbit. Hauv qhov haujlwm no peb siv txoj kev thib ob. Hauv txoj hauv kev no peb siv NTP (lub sijhawm siv sijhawm sib tham) cov neeg siv kom tau txais lub sijhawm hauv zos los ntawm internet. Txhawm rau nkag tau internet peb siv qhov chaw WIFI tsim nyob hauv ESP32. Yog li ntawm thawj theem peb siv WIFI txhawm rau nkag tau internet los ntawm kev muab SSID thiab tus lej nkag. Tom qab ntawd peb yuav tsum teeb tsa gmtOffset thiab daylightOffset hauv qhov hloov pauv hauv vib nas this. Qhov tseem ceeb ntawm cov kev hloov pauv no txawv ntawm ib cheeb tsam mus rau ib cheeb tsam hauv ntiaj teb. gmtOffset txhais tau tias tus naj npawb ntawm vib nas this koj txawv ntawm GMT.. Rau qhov feem ntau nruab hnub nruab hnub nrig yog 3600. Koj tuaj yeem pom nws hauv is taws nem. Tom qab peb tau txais lub sijhawm tam sim no hauv cheeb tsam peb tsis siv WIFI ntev dua. Vim tias tom qab ntawd peb suav lub sijhawm hauv zos los ntawm inbuilt RC moos hauv ESP32. Qhov no yog ua tiav los ntawm kev siv time.h lub tsev qiv ntawv. Muaj qhov piv txwv yooj yim hauv Arduino (Arduino> Piv txwv> ESP32> Sijhawm> yooj yim) rau koj kom kawm paub tias qhov no ua haujlwm ntxiv li cas. Tsis tas li cov kab ntawv txuas no koj tuaj yeem siv rau kev paub ntxiv txog NTP cov neeg siv khoom.

  • https://dronebotworkshop.com/esp32-intro/
  • https://lastminuteengineers.com/esp32-ntp-server-d…

Tom qab tau txais lub sijhawm hauv nroog raug, peb hloov peb lub sijhawm qhia cov ntawv thiab lub kaum sab xis raws li cov ntaub ntawv lub sijhawm ntawd hauv txhua lub voj.

Kauj Ruam 6: Teeb Tswb

Los ntawm txhaj rau sab laug thiab sab xis koj tuaj yeem hloov lub tswb hnub thiab xaiv sijhawm. Nco ntsoov tua lub tswb thaum koj hloov lub tswb thiab sijhawm. Tom qab teeb hnub thiab sijhawm qhib lub tswb. Vim tias yog lub tswb qhib thiab thaum lub sijhawm tswb sib npaug rau koj lub sijhawm tam sim no thaum koj teeb tsa nws, lub tswb nrov yuav nrov. Hauv lub voj loj ib txwm tshawb xyuas lub sijhawm tam sim no hauv zos thiab cov lus ceeb toom sib npaug. Yog tias cov ntawd sib npaug, tom qab ntawd lub suab nrov thiab ua rau ntsuab LED hauv Magicbit yuav ua haujlwm ib pliag.

Kauj Ruam 7: Teeb Lub Buzzer

Peb siv PWM mem tes los tsim lub suab nrov nrov los ntawm kev siv analogCwrite () ua haujlwm hauv txoj cai. Vim tias txhua lub tsev qiv ntawv ua haujlwm nyob hauv ESP32 siv tau rau Magicbit. Koj tuaj yeem hloov lub suab nrov ntawm lub suab nrov los ntawm kev hloov nws zaus thiab PWM tus nqi hauv txoj cai.

techtutorialsx.com/2017/06/15/esp32-arduin…

Nplooj ntawv no piav qhia txog yuav ua li cas buzzer ua haujlwm nrog ESP32.

Kauj Ruam 8: Teeb Cov Khawm

Txog kev hloov pauv txhua lub xeev peb tau siv ob qho ua hauv lub laub khawm hauv Magicbit. Lub voj loj ib txwm txheeb xyuas lub xeev ntawm ob lub khawm. Vim tias lawv rub tawm sab hauv, muaj lub xeev ib txwm yog lub teeb liab siab. Yog li koj tuaj yeem pom cov digital nyeem ntawm cov pins yog 1. Ntawm theem pib lub vijtsam qhia pom lub moos sib cuam tshuam. Lub sijhawm ntawd, thaum ib qho ntawm ob lub pob nyem, tom qab ntawd nws hloov lub vijtsam mus rau lub tswb tshuaj. Tsis tas li peb suav lub sijhawm hauv vib nas this los ntawm lub sijhawm kawg thaum nias lub pob. Yog tias qhov suav loj dua qee lub sijhawm tau teev tseg ua ntej ces cov zaub yuav pom lub vijtsam moos.

Cov cai tau sau los ntawm kev siv cov haujlwm yooj yim rau cov pib tshiab. Yog li txoj cai nkag siab yooj yim thiab koj tuaj yeem kawm paub txoj hauv kev nws ua haujlwm li cas los ntawm kev hais qhia txoj cai.

Kauj ruam 9: Teeb meem

Qee lub sij hawm lub moos pib me ntsis tom qab lossis nws tsis tso saib cov duab kom raug. Cov lus qhia hauv qab no pab daws qhov xwm txheej.

  • Nco ntsoov tias koj muab tus SSID raug thiab tus password
  • Hloov NTP server (koj tuaj yeem pom ntau lub server los ntawm internet uas cuam tshuam nrog koj cheeb tsam).
  • Hloov pauv kev sib txuas hauv is taws nem. (Mobile hotspot tseem tuaj yeem ua tau).

Tsis tas li koj tuaj yeem daws txhua yam los ntawm kev siv lub ntsuas saib. Ntxiv nrog rau OLED cov duab saib saib qhia pom lub sijhawm cov ntaub ntawv.

Kauj ruam 10: Arduino Code

// tsev qiv ntawv rau OLED zaub

#suav nrog

#suav nrog #suav nrog #define OLED_RESET 4 #suav nrog // wifi tsev qiv ntawv rau txuas #suav nrog "sijhawm.h" // tsev qiv ntawv siv RC moos // txheeb xyuas cov npe thiab cov lej tus lej pin #define RightButton 34 #define LeftButton 35 #define GreenLED 16 #define Buzzer 25 int preTime = 0; int suav = 0; int tam sim noTime = 0; txheej txheem tm sijhawm; const char* ssid = "KOJ SSID"; // wifi cov ntsiab lus tsim char* password = "KOJ PASSWORD"; int alarmDateTime [5] = {1, 1, 2020, 0, 0}; // tswb ceeb toom hloov pauv int dateIndex = 0; int timeIndex = 0; int selectIndex = -1; bool buzzerOn = 0; int rect [6] [4] = {{5, 0, 118, 16}, {1, 22, 30, 22}, {37, 22, 30, 22}, {73, 22, 55, 22}, {31, 44, 30, 20}, {67, 44, 30, 20}}; // xaiv lub duab plaub const char* ntpServer = "asia.pool.ntp.org"; // server detais const ntev gmtOffset_sec = 19800; const int daylightOffset_sec = 0; Adafruit_SSD1306 zaub (128, 64); // OLED loj txhais byte clockCenterY = (display.height () + 16)/2; // analog moos ntsej muag paub meej byte clockCenterX = (display.height () - 16)/2; byte clockRadius = 23; bool xeev = 0; // tshuaj ntsuam qhib lossis tawm boolean Tswb = 0; // tswb lub xeev tam sim no Txoj hlua alarmState = "Tswb ON"; // tswb rau lossis tawm // varibles khaws lub sijhawm cov ntaub ntawv char dayName [10]; tus naj npawb hnub [3]; hli hli [10]; char xyoo [5]; teev teev [3]; char feeb [3]; daim ntawv qhia hnub hli [3]; char vib nas this [3]; // khawm hloov pauv bool RightState = 1; bool LeftState = 1; // buzzer variables int channel = 0; int Zaus = 2000; PWM = 200; int daws teeb meem = 8; void teeb () {// teeb tsa cov tswv yim thiab ouputs pinMode (RightButton, INPUT); pinMode (LeftButton, INPUT); tus pinMode (GreenLED, OUTPUT); tus pinMode (Buzzer, OUTPUT); display.begin (SSD1306_SWITCHCAPVCC, 0x3C); // intialize zaub display.display (); ncua (3000); display.clearDisplay (); ledcSetup (0, Zaus, daws teeb meem); // teeb tsa pwm tsis ua ledcAttachPin (Buzzer, 0); Serial.begin (115200); // intilize serial communication // txuas mus rau WiFi Serial.printf ("Txuas rau %s", ssid); WiFi.begin (ssid, password); thaum (WiFi.status ()! = WL_CONNECTED) {ncua (500); Serial.print ("."); } Serial.println ("Txuas"); // init thiab tau txais lub sijhawm configTime (gmtOffset_sec, daylightOffset_sec, ntpServer); getTime (); // disconnect WiFi vim nws tsis xav tau WiFi.disconnect (muaj tseeb); WiFi.mode (WIFI_OFF); display.clearDisplay (); } void loop () {getTime (); // tau txais lub sijhawm tam sim no // khaws txoj cai thiab sab laug lub pob nyem lub xeev RightState = digitalRead (RightButton); LeftState = digitalRead (LeftButton); // chaeck lub pob tw raug nias yog tias (RightState == 0 || LeftState == 0) {ledcWrite (0, 200); // thaum khawm raug nias lub buzzer tso lub suab nrov nrov qeeb (100); yog tias (xeev == 0) {// hloov mus rau lub tswb ntsuas lub ntsej muag lub xeev = 1; // hloov lub xeev mus rau lub tswb xeev RightState = LeftState = 1; // peb tsuas xav tau kev hloov pauv sceern} suav = 0; // rov pib dua} yog (xeev == 1 && (suav) <5) {// yog nyob hauv lub tswb ceeb toom thiab tsis siv sijhawm suav suav suav nrog screen lub xeev = 0; display.clearDisplay (); clockFace (); // analog clock face printLocalTime (); // print time in clock face and print other details} onAlarm (); // sib piv lub tswb moos nrog lub sijhawm hauv zos thiab qhib lub tswb ncua (100); // ncua rau tswb rau thiab tawm} void clockFace () {// caalog moos lub ntsej muag display.drawCircle (clockCenterX, clockCenterY, clockRadius, WHITE); // luam tawm lub voj voog rau (int digit = 0; digit = 5) {// tsuas yog muaj 5 selctions.so rov pib dua rau -1 (-1 = yog nyob rau lossis tawm) selectIndex = -1; } dateAndTimeSelection (selectIndex); // hloov selction} void dateAndTimeSelection (int index) {yog (index == -1) {// tswb rau lossis tawm yog (RightState == 0) {// togle nruab nrab ntawm thiab tawm tswb yog (alarmState == "Tswb ON") {alarmState = "Tswb OFF"; } lwm tus {alarmState = "Tswb ON"; }}} lwm qhov {yog (RightState == 0) {// hauv lwm qhov kev txiav txim siab txheeb xyuas hnub tim lossis sijhawm nyob rau hauv array alarmDateTime [index] = alarmDateTime [index] + 1; // index yog qhov kev xaiv}} int sib piv [4] = {12, 2030, 23, 59}; // qhov txwv qis tshaj ntawm cov hnub thiab xyoo sib piv sib piv [12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; // sab limi ntawm lub hlis int resetValue [4] = {1, 2020, 0, 0}; // pib qhov tseem ceeb rau (int i = 1; kuv piv [i - 1]) {alarmDateTime = resetValue [i - 1]; }} yog (tswbDateTime [0]> sib piv lub hlis [tswbDateTime [1] - 1]) {// rov pib dua vlaues yog lub hlis loj dua lawv txwv tswbDateTime [0] = 1; }} tsis muaj dabtsis showAlarm () {// luam tawm cov ntsiab lus tswb String alarmDateTime0 = String (alarmDateTime [0]); // hloov cov hlua los qhia txoj hlua alarmDateTime1 = Txoj hlua (tswbDateTime [1]); String alarmDateTime2 = Txoj hlua (tswbDateTime [2]); String alarmDateTime3 = Txoj hlua (alarmDateTime [3]); String alarmDateTime4 = Txoj hlua (tswbDateTime [4]); // yog qhov muaj txiaj ntsig muaj ib 1 digita ntxiv "0" rau lawv. yog (alarmDateTime [0]

Pom zoo: