Cov txheej txheem:

Sijhawm Tiag Nrog Arduino: 3 Kauj Ruam
Sijhawm Tiag Nrog Arduino: 3 Kauj Ruam

Video: Sijhawm Tiag Nrog Arduino: 3 Kauj Ruam

Video: Sijhawm Tiag Nrog Arduino: 3 Kauj Ruam
Video: Computer Vision with Python! Resizing Images 2024, Kaum ib hlis
Anonim
Sijhawm Tiag Nrog Arduino
Sijhawm Tiag Nrog Arduino

Hauv txoj haujlwm no, peb yuav ua lub moos nrog kev pab ntawm Arduino thiab RTC module. Raws li peb paub Arduino tsis tuaj yeem tso saib lub sijhawm tiag tiag yog li peb yuav siv RTC module los tso saib lub sijhawm raug ntawm lub LCD. Nyeem tag nrho cov kauj ruam ua tib zoo nws yuav pab koj ntau heev kom ua tiav cov haujlwm.

DS3231 Arduino code zoo li DS1307 code thiab nws ua haujlwm nrog ob qho RTC chips.

Tus lej Arduino hauv qab tsis siv lub tsev qiv ntawv twg rau DS3231 RTC, Lub Tsev Qiv Hlau yog rau kev sib tham ntawm Arduino thiab DS3231 siv I2C cov rooj sib tham.

Yog! Ntau tus kws tsim khoom siv hluav taws xob vam khom nws rau lawv txoj haujlwm raws sijhawm tab sis RTC tsis ntseeg tau kiag li. Nws yog lub roj teeb ua haujlwm thiab yuav tsum tau hloov pauv sai lossis tom qab. Los rau IoT cov phiaj xwm nws tau txais txiaj ntsig zoo SPI (Serial Peripheral Interface) pins thiab cuam tshuam nrog cov xov hlau tangled ncig. Tshuaj…. Ntawm no yog peb tus phab ej NTP (Network lub sijhawm raws tu qauv). NTP yog qhov tseeb vim nws tau txais sijhawm los ntawm internet. Peb yuav ua haujlwm raws tu qauv no siv hom neeg siv-server. cov txheej txheem yog yooj yim heev uas peb Nodemcu ua raws li tus neeg siv khoom thiab thov NTP pob ntawv los ntawm server siv UDP. Rov qab los, tus neeg rau zaub mov xa pob ntawv mus rau tus neeg siv khoom uas txheeb xyuas cov ntaub ntawv. NTP yog lub sijhawm ua haujlwm thoob ntiaj teb synchronization raws tu qauv. Tam sim no cia peb teeb peb lub chaw ua haujlwm lab

Kauj Ruam 1: Cov Cheeb Tsam Xav Tau

  • Arduino pawg thawj coj saib
  • DS3231 RTC pawg thawj coj saib
  • 16x2 LCD npo
  • 2 x laub khawm
  • 10K ohm kuj sib txawv resistor (lossis potentiometer)
  • 330-ohm resistor
  • 3V npib cell roj teeb
  • Cov qhob cij
  • Jumper xov hlau

RTC mocule DS3231 Cov

Lub sijhawm yog qhov kev nkag siab tseem ceeb xav tau hauv ntiaj teb kev nrawm ntawm tib neeg. Hauv qhov project tiag tiag

Peb siv RTC (AK Lub Sijhawm Sijhawm Tiag)

RTC Lub Sij Hawm Tiag Tiag (RTC) yog kev sib koom ua ke (IC) uas taug qab lub sijhawm tam sim no. RTC saib xyuas lub sijhawm nyob rau hauv hom tiag. RTC feem ntau pom muaj nyob hauv khoos phis tawj motherboards thiab teeb tsa kab ke kom xav tau kev nkag mus raws sijhawm.

Kauj Ruam 2: Kev Sib Txuas ntawm Arduino Moos

Kev Sib Txuas ntawm Arduino Moos
Kev Sib Txuas ntawm Arduino Moos
  • Txuas SCL tus pin rau RTC module rau Arduino A5
  • Txuas SDA tus pin rau RTC module rau Arduino A4
  • Txuas VCC mus rau 5v thiab GND rau GND
  • Txuas lub laub khawm rau tus pin 8
  • Txuas lwm lub laub khawm rau tus pin 9
  • Txuas RS ntawm LCD rau tus pin 2 ntawm Arduino
  • Txuas E ntawm LCD rau tus pin 3 ntawm Arduino
  • Txuas D7 ntawm LCD rau tus pin 7 ntawm Arduino
  • Txuas D6 ntawm LCD rau tus pin 6 ntawm Arduino
  • Txuas D5 ntawm LCD mus rau tus pin 5 ntawm Arduino
  • Txuas D4 ntawm LCD rau tus pin 4 ntawm Arduino
  • Txuas VSS & K rau GND
  • Txuas VDD & A mus rau 5v
  • Txuas lub vo rau tus pin tus lej potentiometer

Kauj Ruam 3: Txoj Cai rau Arduino Moos Nrog RTC

Code rau Arduino Moos Nrog RTC
Code rau Arduino Moos Nrog RTC

DS3231 ua haujlwm nrog BCD hom nkaus xwb thiab hloov BCD mus rau zauv thiab vise sib piv Kuv siv 2 kab hauv qab no (piv txwv rau feeb): // Hloov BCD rau decimalminute = (feeb >> 4) * 10 + (feeb & 0x0F);

// Hloov cov lej los BCDminute = ((feeb / 10) << 4) + (feeb % 10); tsis muaj dab tsi DS3231_display (): qhia lub sijhawm thiab daim ntawv qhia hnub, ua ntej tso saib lub sijhawm thiab daim ntawv qhia hnub cov ntaub ntawv tau hloov pauv los ntawm BCD mus rau cov lej zauv.void blink_parameter ():

// Lub sijhawm tiag tiag thiab daim ntawv qhia hnub nrog teeb tsa khawm siv DS3231 thiab Arduino // suav nrog LCD lub tsev qiv ntawv code #include // suav nrog Cov xov tooj xov tooj (uas xav tau rau I2C raws tu qauv khoom siv) #suav nrog // LCD module sib txuas (RS, E, D4, D5, D6, D7) LiquidCrystal lcd (2, 3, 4, 5, 6, 7); teeb tsa tsis muaj dab tsi () {pinMode (8, INPUT_PULLUP); // button1 txuas nrog tus pin 8 pinMode (9, INPUT_PULLUP); // khawm 2 txuas nrog tus pin 9 // teeb tsa LCD tus lej ntawm kab thiab kab lcd.begin (16, 2); Hlau.begin (); // Koom nrog i2c npav} char Sijhawm = "SIJHAWM:::"; char Calendar = "HNUB: / / 20"; byte kuv, thib ob, feeb, teev, hnub tim, hli, xyoo; void DS3231_display () {// Hloov BCD mus rau decimal thib ob = (thib ob >> 4) * 10 + (thib ob & 0x0F); feeb = (feeb >> 4) * 10 + (feeb & 0x0F); teev = (teev >> 4) * 10 + (teev & 0x0F); hnub = (hnub tim >> 4) * 10 + (hnub tim & 0x0F); hli = (hli >> 4) * 10 + (hli & 0x0F); xyoo = (xyoo >> 4) * 10 + (xyoo & 0x0F); // Xaus Kev Hloov Sijhawm [12] = thib ob % 10 + 48; Sijhawm [11] = thib ob / 10 + 48; Sijhawm [9] = feeb % 10 + 48; Sijhawm [8] = feeb / 10 + 48; Sijhawm [6] = teev % 10 + 48; Sijhawm [5] = teev / 10 + 48; Calendar [14] = xyoo % 10 + 48; Calendar [13] = xyoo / 10 + 48; Calendar [9] = hli % 10 + 48; Calendar [8] = hli / 10 + 48; Calendar [6] = hnub % 10 + 48; Calendar [5] = hnub tim / 10 + 48; lcd.setCursor (0, 0); lcd.print (Sijhawm); // Zaub sijhawm lcd.setCursor (0, 1); lcd.print (Calendar); // Zaub daim calendar} tsis muaj dab tsi blink_parameter () {byte j = 0; thaum (j 23) // Yog teev> 23 ==> teev = 0 parameter = 0; yog (i == 1 && parameter> 59) // Yog feeb> 59 ==> feeb = 0 parameter = 0; yog (i == 2 && parameter> 31) // Yog hnub tim> 31 ==> date = 1 parameter = 1; yog (i == 3 && parameter> 12) // Yog hli> 12 ==> hli = 1 qhov ntsuas = 1; yog (i == 4 && parameter> 99) // Yog xyoo> 99 ==> xyoo = 0 parameter = 0; sprintf (ntawv, "%02u", parameter); lcd.setCursor (x, y); lcd.print (ntawv nyeem); ncua (200); // Tos 200ms} lcd.setCursor (x, y); lcd.print (""); // Zaub ob qhov chaw blink_parameter (); sprintf (ntawv, "%02u", parameter); lcd.setCursor (x, y); lcd.print (ntawv nyeem); blink_parameter (); yog (! digitalRead (8)) {// Yog tias khawm (tus pin #8) raug nias kuv ++; // Increament 'i' rau qhov ntsuas tom ntej rov qab ntsuas; // Rov qab qhov ntsuas tus nqi thiab tawm mus}}} void loop () {yog (! DigitalRead (8)) {// Yog tias khawm (tus lej #8) raug nias i = 0; teev = hloov kho (5, 0, teev); feeb = kho kom raug (8, 0, feeb); date = edit (5, 1, hnub tim); hli = kho (8, 1, hli); xyoo = hloov kho (13, 1, xyoo); // Hloov zauv zauv rau BCD feeb = ((feeb / 10) << 4) + (feeb % 10); teev = ((teev / 10) << 4) + (teev % 10); hnub tim = ((hnub tim / 10) << 4) + (hnub tim % 10); hli = ((hli / 10) << 4) + (hli % 10); xyoo = ((xyoo / 10) << 4) + (xyoo % 10); // Xaus kev hloov pauv // Sau cov ntaub ntawv rau DS3231 RTC Wire.beginTransmission (0x68); // Pib I2C raws tu qauv nrog DS3231 chaw nyob Wire.write (0); // Xa npe chaw nyob Wire.write (0); // Pib dua sesonds thiab pib oscillator Wire.write (feeb); // Sau feeb Wire.write (teev); // Sau teev Wire.write (1); // Sau hnub (tsis siv) Wire.write (hnub tim); // Sau hnub tim Wire.write (hli); // Sau hli Wire.write (xyoo); // Sau xyoo Wire.endTransmission (); // Nres kev xa mus thiab tso I2C ncua tsheb npav (200); // Tos 200ms} Wire.beginTransmission (0x68); // Pib I2C raws tu qauv nrog DS3231 chaw nyob Wire.write (0); // Xa npe chaw nyob Wire.endTransmission (cuav); // I2C rov pib dua Wire.requestFrom (0x68, 7); // Thov 7 bytes los ntawm DS3231 thiab tso I2C npav thaum kawg nyeem thib ob = Wire.read (); // Nyeem vib nas this los ntawm npe 0 feeb = Wire.read (); // Nyeem qhov tsawg los ntawm npe 1 teev = Wire.read (); // Nyeem teev los ntawm npe 2 Wire.read (); // Nyeem hnub los ntawm npe 3 (tsis siv) hnub = Wire.read (); // Nyeem hnub tim sau npe 4 lub hlis = Wire.read (); // Nyeem lub hlis los ntawm npe 5 xyoos = Wire.read (); // Nyeem xyoo los ntawm npe 6 DS3231_display (); // Diaplay lub sijhawm & ncua sijhawm (50); // Tos 50ms}

Pom zoo: