I-DS3231: iwashi lesikhathi sangempela nekhalenda le-Arduino yakho

I-DS3231

Kwamanye amaphrojekthi kuyadingeka ukuba nobufakazi besikhathi, ihora, noma usuku. Kungaba ngenxa yesidingo sokwenza imisebenzi ethile ngokuya ngesikhathi, ukugcina ikhalenda yemicimbi noma ukubhaliswa, ukugcina isikhathi kohlelo, noma ukumane wakhe iwashi ledijithali no-Arduino. Nge i-DS3231 ungayithola, enye ye- izingxenye ukuthi sengeza ohlwini.

I-DS3231 iyimodyuli obukade uyifuna, futhi lapha uzothola konke okudingayo ngokulawulwa kwayo futhi ngizokubonisa nesibonelo sokuthi uyihlanganise ne-Arduino ngesibonelo esisebenzayo ...

Yini i-DS3231?

I-DS3231

Okokuqala, kufanele wazi ukuthi yini a I-RTC (Real Time Clock), noma iwashi lesikhathi sangempela. Lezi chips zivame kakhulu kunqwaba yezinhlelo zokusebenza, empeleni, i-PC yakho inenye yazo ebhodini lakho lomama, futhi inikwa amandla yi CR2032 ibhethri futhi. Yiyo egcina isikhathi nokucushwa ku-BIOS / UEFI futhi lapho isistimu yokusebenza ikuthatha khona lapho iqalisa ukufika ngesikhathi (yize manje, nge-Intanethi, ukuvumelanisa ngamaseva kungasetshenziselwa ukucacisa okukhulu, kepha lokhu kungenye indaba…).

Lokho okwenziwa yi-RTC ukuthola izilinganiso zesikhathi, lokho kulula. Umehluko ovela kwezinye izinhlobo zamawashi kagesi ukuthi zimane nje linganisa isikhathi, futhi ikwenza lokho ngokubala ama-pulses wesiginali yewashi, yazi ubude bayo nezikhathi zayo. Ngaphezu kwesikhathi, i-RTC futhi ikuvumela ukuthi ugcine i-akhawunti yezinsuku, amasonto, izinyanga neminyaka. Okusho ukuthi, usuku oluphelele ...

Ukuze lokhu kwenzeke, i-RTC kufanele ihambisane ne- a I-Xtal noma i-quartz crystal ezosebenza njenge-resonator, enikezela imvamisa. Ngokwengeziwe, udinga amasekethe we-elekthronikhi akwazi ukubala nokugcina usuku kwimemori. Isifunda kufanele sikwazi ukubala imizuzwana, imizuzu, amahora, izinsuku, amasonto, izinyanga neminyaka.

Lokho inkumbulo ayishintshiYingakho idinga ibhethri, ukuze ibe namandla njalo. Uma ungenayo ibhethri noma iphela, izosulwa ... Yilokho okwenzeka kuma-PC lapho ibhethri liphela, banikeza isikhathi esingalungile. Uma uyilungisa ngenkathi i-PC ivuliwe, isikhathi sizogcinwa, ngoba i-RTC isanikezwa amandla, kepha kuphakathi kwezinqubo lapho icishiwe khona lapho lelo bhethri lidingeka ...

Kumaphrojekthi we-DIY, abenzi bavame ukusebenzisa ama-chips amabili ajwayelekile e-RTC, angama- DS1307 futhi DS3231. Zombili zenziwa nguMaxim (owayekade eyiDallas Semiconductor), kanti i-DS3231 inembe kakhudlwana yalokhu, njengoba ingathinteki ngokwehluka kwamazinga okushisa njengangaphambili. Ngakho-ke, ayishintshi kakhulu kuye ngezinga lokushisa, futhi igcina isikhathi ngokunembile.

Ngezinye izikhathi, ngomehluko obonakalayo wokushisa, i-DS1307 ingahle ibambeke njenge-1 noma i-2 min ngosuku. Okuthile okungabekezeleleki kwezinye izinhlelo zokusebenza.

I-DS3231 akukhona ukuthi ayithinteki ngokuhlukahluka, kepha ukuthi inezinqubo zokulinganisa izinga lokushisa nezinhlelo zokunxephezela ukuqinisekisa ukunemba kwe-2ppm, engalingana ne isikhathi esisele cishe ngama-172ms ngosuku, okungukuthi, ngaphezulu kwesekhondi elilodwa ngesonto okungenani. Futhi ngokwenza, imvamisa ziyahlukahluka kuphela imizuzwana eyi-1 noma 1 ngenyanga.

Ngokuqondene nendlela ukuxhumana ne-RTC I-DS3131 ukuthola amanani wedethi ewatholayo, kwenziwa ngu I2C ibhasi. Futhi ukuthola amandla, ungasebenzisa u-2.3 kuye ku-5.5v we-DS3231, engaphansi kancane kuka-4.5 kuye ku-5.5v we-DS1307, ngakho-ke ingaba namandla kakhulu futhi yenze ibhethri lihlale isikhathi eside.

Futhi, kufanele wazi ukuthi lawa amamojula ngokuvamile ane- EEPROM eyengeziwe AT24C32 ukugcina amanye amarekhodi nezilinganiso zangaphambilini, okusebenzayo impela.

Aplicaciones

Ngokuqondene nezicelo, sengivele ngishilo ezinye, njengokusebenzisa iwashi nge-Arduino, ukwakha uhlelo olusebenza ngokuya Isikhathi Noma yini, ukugcina isikhathi kwimishini efana nama-PC namanye amadivayisi amaningi we-elekthronikhi nemishini enesikhathi, njll.

Ingasetshenziswa futhi ku- amaphrojekthi ukudala isikhathi sokukhanyisa, izinhlelo zokunisela, i-datalogger, njll. Izicelo zingaba ziningi kakhulu ...

Thenga i-RTC DS3231

Imodyuli I-DS3131 ishibhile, futhi ungayithola kwezinye izitolo ezikhethekile ze-elekthronikhi noma ezitolo ezinkulu ezifana ne-eBay, AliExpress, Amazon, njll. Uma unentshisekelo yokuba neyodwa, nazi izincomo:

DS3231 Arduino Ukuhlanganisa

Isithombe se-Arduino IDE

Uma ufuna hlanganisa i-DS3231 yakho nebhodi lakho le-Arduino bese uqala ukudala amaphrojekthi "aphelelwe yisikhathi", kufanele uqale wenze ukuxhumana okufanelekile. Ukuze ukwazi ukuyixhuma, ilula njenge:

  • Iphini le-SLC lebhodi le-DS3231 kumele lixhunywe ku-A5 yakho Arduino UNO.
  • I-SDA ye-DS3231 ixhunywe ku-A4 ye-Arduino.
  • IVcc kusuka module izoya ku-5V kusuka ku-Arduino.
  • GND kuya ku-GND.
Khumbula ukufaka umtapo wezincwadi ukuze usebenzise i-RTC DS3231 ku-Arduino IDE yakho noma ikhodi ngeke isebenze ...

Manje usuxhume uhlelo, into elandelayo ukubhala ifayela le- sketch ikhodi yomthombo ukuluhlela. Ungaguqula amakhodi bese uwavumelanisa nezidingo zakho, kepha ungaqala ngokuthola usuku kusuka ku-RTC DS3231 exhunywe ku-Arduino:

#include <Wire.h>
#include "RTClib.h"
 
// RTC_DS1307 rtc;
RTC_DS3231 rtc;
 
String daysOfTheWeek[7] = { "Domingo", "Lunes", "Martes", "Miércoles", "Jueves", "Viernes", "Sábado" };
String monthsNames[12] = { "Enero", "Febrero", "Marzo", "Abril", "Mayo",  "Junio", "Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre" };
 
void setup() {
   Serial.begin(9600);
   delay(1000); 
 
   if (!rtc.begin()) {
      Serial.println(F("No se encuentra el RTC"));
      while (1);
   }
 
   // Si se ha perdido el suministro eléctrico, fijar fecha y hora
   if (rtc.lostPower()) {
      // Fijar a fecha y hora (poner la de compilación del sketch)
      rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
      
      // Fijar a fecha y hora específica. En este ejemplo el 2021-01-01 a las 00:00:00
      // rtc.adjust(DateTime(2020, 1, 1, 0, 0, 0));
   }
}
//Imprimir completa obtenida la fecha en decimal
void printDate(DateTime date)
{
   Serial.print(date.year(), DEC);
   Serial.print('/');
   Serial.print(date.month(), DEC);
   Serial.print('/');
   Serial.print(date.day(), DEC);
   Serial.print(" (");
   Serial.print(daysOfTheWeek[date.dayOfTheWeek()]);
   Serial.print(") ");
   Serial.print(date.hour(), DEC);
   Serial.print(':');
   Serial.print(date.minute(), DEC);
   Serial.print(':');
   Serial.print(date.second(), DEC);
   Serial.println();
}
 
void loop() {
   // Obtener fecha actual y mostrar por Serial
   DateTime now = rtc.now();
   printDate(now);
 
   delay(3000);    //Espera 3 segundos
}

Futhi ukuze usebenzise usuku lwe-RTC ku- hlela umsebenzi othile, njengokucisha noma ukucisha amalambu, ukunisela okuzenzakalelayo, noma i-alamu ukukhala, njll. Khumbula ukuthi ukuphatha amadivayisi we-voltage aphezulu ungasebenzisa ama-transistors noma edluliselwe:

#include <Wire.h>
#include "RTClib.h"
 
const int outputPin = LED_BUILTIN;
bool state = false;
 
// RTC_DS1307 rtc;
RTC_DS3231 rtc;
 
void setup() {
   Serial.begin(9600);
   delay(1000);
 
   if (!rtc.begin()) {
      Serial.println(F("Couldn't find RTC"));
      while (1);
   }
 
   if (rtc.lostPower()) {
      rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
   }
}
 
// Se comprueba si está programado el encendido
bool isScheduledON(DateTime date)
{
   int weekDay = date.dayOfTheWeek();
   float hours = date.hour() + date.minute() / 60.0;
 
   // Configuración de horas de 08:30 a 9:30 y de 22:00 a 23:00 (usando decimal)
   bool hourCondition = (hours > 8.50 && hours < 9.50) || (hours > 22.00 && hours < 23.00);
 
   // Configuración del día Lunes, Sábado y Domingo con números (recuerda que en inglés comienza la semana en Domingo=0, Lunes=1,...
   bool dayCondition = (weekDay == 1 || weekDay == 6 || weekDay == 0); 
   if (hourCondition && dayCondition)
   {
      return true;
   }
   return false;
}
 
void loop() {
   DateTime now = rtc.now();
 
   if (state == false && isScheduledON(now))      // Apagado
   {
      digitalWrite(outputPin, HIGH);
      state = true;
      Serial.print("Activado");
   }
   else if (state == true && !isScheduledON(now))  // Encendido
   {
      digitalWrite(outputPin, LOW);
      state = false;
      Serial.print("Desactivado");
   }
 
   delay(3000);
}


Okuqukethwe yi-athikili kunamathela ezimisweni zethu ze izimiso zokuhlelela. Ukubika iphutha chofoza lapha.

Yiba ngowokuqala ukuphawula

Shiya umbono wakho

Ikheli lakho le ngeke ishicilelwe. Ezidingekayo ibhalwe nge *

*

*

  1. Ubhekele imininingwane: Miguel Ángel Gatón
  2. Inhloso yedatha: Lawula Ugaxekile, ukuphathwa kwamazwana.
  3. Ukusemthethweni: Imvume yakho
  4. Ukuxhumana kwemininingwane: Imininingwane ngeke idluliselwe kubantu besithathu ngaphandle kwesibopho esisemthethweni.
  5. Isitoreji sedatha: Idatabase ebanjwe yi-Occentus Networks (EU)
  6. Amalungelo: Nganoma yisiphi isikhathi ungakhawulela, uthole futhi ususe imininingwane yakho.