DS3231: saacada dhabta iyo kaalandarka Arduino-kaaga

DS3231

Mashruucyada qaarkood waa lagama maarmaan in la helo caddeyn waqtiga, saacadda, ama taariikhda. Sababtoo ah baahida loo qabo in la qabto shaqooyin gaar ah oo ku saleysan waqtiga, si loo ilaaliyo jadwalka dhacdooyinka ama diiwaangelinta, in waqtiga lagu hayo nidaam, ama si fudud loo abuuro saacad dijitaal ah la socda Arduino. Iyadoo DS3231 waad heli kartaa, mid kale oo ka mid ah qaybaha in aan ku darno liiska.

DS3231 waa moduleka aad raadineysay, halkan waxaad kaheleysaa wax walboo aad ugubaahantahay xakameyntiisa waxaanan sidoo kale ku tusi doonaa tusaale sida ku dhex dar Arduino oo leh tusaale wax ku ool ah ...

Waa maxay DS3231?

DS3231

Marka hore, waa inaad ogaataa waxa a RTC (Saacadda Waqtiga Real), ama saacadda waqtiga dhabta ah. Chips-yadaani waa kuwo aad u soo noqnoqda barnaamijyo fara badan, runtiina, PC-gaagu wuxuu leeyahay mid ka mid ah oo ku yaal boodhkaaga, sidoo kale waxaa ku shaqeeya a Batariga CR2032 sidoo kale. Waa midka ilaaliya waqtiga iyo qaabeynta BIOS / UEFI oo nidaamka hawlgalku ka qaato marka la bilaabayo in waqtiga la ilaaliyo (in kasta oo hadda, internetka, iswaafajinta server-yada loo adeegsan karo saxsanaanta weyn, laakiin tan waa sheeko kale…).

Waxa ay RTC sameyso waa helitaanka cabbiraadaha waqtiga, ee fudud. Farqiga u dhexeeya noocyada kale ee saacadaha elektiroonigga ah ayaa ah inay si fudud u yihiin qiyaas waqtiga. Waqtiga ka sokow, RTC wuxuu kaloo kuu oggolaanayaa inaad xisaabiso maalmo, toddobaadyo, bilo iyo sannado. Taasi waa, taariikhda buuxda ...

Si tan ay u suurta gasho, RTC waa inuu la socdaa a Xtal ama quartz crystal taas oo u shaqeyn doonta sidii resonator, kan bixiya soo noqnoqoshada. Intaa waxaa sii dheer, waxaad u baahan tahay wareeg elektiroonig ah oo awood u leh tirinta iyo keydinta taariikhda xusuusta. Wareeggu waa inuu ahaadaa mid awood u leh inuu tiriyo ilbiriqsiyo, daqiiqado, saacado, maalmo, toddobaadyo, bilo iyo sannado.

ESA xusuustu way isbedbeddelaysaaTaasi waa sababta ay ugu baahan tahay baytariga, inay yeelato awood joogto ah. Haddii aadan haysan batteri ama uu dhammaado, waa la tirtiri doonaa ... Taasi waa waxa ku dhaca kumbuyuutarrada marka uu batterigu dhammaado, waxay siiyaan waqti aan sax ahayn. Haddii aad isku hagaajiso inta PC-gu daaran yahay, waqtiga ayaa la hayaa, maadaama RTC-ga la shaqeynayo, laakiin waa inta lagu gudajiro howlaha inta uu xiran yahay marka batterigaas loo baahdo ...

Mashruucyada 'DIY', sameeyayaashu waxay badanaa isticmaalaan laba nooc oo RTC ah oo caadi ah, kuwaas oo ah DS1307 iyo DS3231. Labadaba waxaa sameeyay Maxim (oo horay loo oran jiray Dallas Semiconductor), DS3231-na waa ka saxsan yahay labadaba, maadaama aysan saameyn ku yeelan kala duwanaanta heerkulka sida tan hore ay u sameyso. Sidaa darteed, isma beddeleyso wax badan iyadoo ku xiran heerkulka, waxayna waqtiga ku sii haysaa si hufan.

Mararka qaarkood, kala duwanaanshaha heerkulka ee la ogaan karo, DS1307 wuxuu noqon karaa mid hoos u dhaca sida 1 ama 2 daqiiqo maalintii. Wax aan loo dulqaadan karin codsiyada qaarkood.

DS3231 maaha inuu saameynayo kala duwanaansho, laakiin waa inuu leeyahay qaab cabir heerkul ah iyo magdhow si loo hubiyo saxnaanta 2ppm, taas oo u dhiganta a dib u dhac oo ku saabsan 172ms maalintii, taas oo ah, in yar oo ka yar 1 ilbiriqsi ugu badnaan. Ficil ahaan, badiyaa waxay ku kala duwan yihiin kaliya 1 ama 2 ilbiriqsi bishii.

Sida wadada la xiriir RTC DS3131 si loo helo qiimaha taariikhda ay hesho, waxaa lagu sameeyaa iyada Baska I2C. Awood ahaan, waxaad u isticmaali kartaa 2.3 ilaa 5.5v DS3231, taas oo xoogaa ka hooseysa 4.5 ilaa 5.5v ee DS1307, sidaa darteed waxay noqon kartaa mid tamar badan oo batteriga ka dhigeysa mid sii dheereeya.

Sidoo kale, waa inaad ogaataa in qaababkani caadi ahaan leeyihiin a EEPROM dheeraad ah AT24C32 si loo kaydiyo diiwaanada qaar iyo cabbiraadihii hore, taas oo ah mid wax ku ool ah.

Aplicaciones

Marka la eego codsiyada, waxaan horeyba u soo sheegay qaar ka mid ah, sida in saacad laga hirgeliyo Arduino, si loo abuuro nidaam ku dhaqma Waqtiga Wax kasta ha noqotee, in waqtiga lagu hayo qalabka sida PC-yada iyo aalado kale oo elektaroonig ah iyo qalabyo waqti u leh, iwm.

Sidoo kale waa loo isticmaali karaa gudaha mashaariicda in la abuuro saacado nalal, nidaam waraab, xog-ururin iwm. Codsiyada waxay noqon karaan kuwa ugu badan ...

Iibso RTC DS3231

Module DS3131 waa raqiis, oo waxaad ka heli kartaa qaar ka mid ah dukaamada elektarooniga ah ee gaarka ah ama dukaamada waaweyn sida eBay, AliExpress, Amazon, iwm. Haddii aad xiiseyneyso inaad mid yeelato, waa kuwan qaar ka mid ah talooyinka:

DS3231 Arduino Isdhaxgalka

Muuqaalka shaashadda ee Arduino IDE

Haddii aad rabto ku dar DS3231-kaaga guddiga Arduino oo aad bilowdo abuurista mashruucyo "waqtiyeysan", waa inaad marka hore sameysid isku xirnaanta habboon. Si aad u awoodo inaad ku xirto, waa wax fudud sida:

  • Biinanka SLC ee guddiga DS3231 waa inuu ku xirnaadaa A5 kaaga Arduino UNO.
  • SDA ee DS3231 waxay kuxirantahay A4 ee Arduino.
  • Vcc oo ka socota moduleka ayaa aadaya 5V oo ka yimid Arduino.
  • GND ilaa GND.
Xusuusnow inaad rakibto maktabadda si aad ugu isticmaasho 'RTC DS3231' Arduino IDE-kaaga ama koodhku ma shaqeyn doono ...

Hadda waxaad leedahay nidaam ku xiran, waxa ku xiga waa inaad qorto koodhka isha si ay u barnaamij. Waad wax ka beddeli kartaa koodhadhka oo aad ula qabsan kartaa baahiyahaaga, laakiin waxaad ku bilaabi kartaa inaad si fudud uga hesho taariikhda RTC DS3231 ee ku xiran 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
}

Iyo si loogu isticmaalo taariikhda RTC ilaa jadwal hawl yar, sida shidida laydhadhka ama daminta, waraabinta otomaatiga ah, ama alaarmiga oo la maqlayo iwm Xusuusnow in si loo maareeyo aaladaha danab sare aad isticmaali karto transistors ama gudbinta:

#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);
}


Nuxurka maqaalka wuxuu u hogaansamayaa mabaadi'deena anshaxa tifaftirka. Si aad u soo sheegto khalad guji Halkan.

Noqo kuwa ugu horreeya ee faallo bixiya

Ka tag faalladaada

cinwaanka email aan la daabacin doonaa. Beeraha loo baahan yahay waxaa lagu calaamadeeyay la *

*

*

  1. Masuul ka ah xogta: Miguel Ángel Gatón
  2. Ujeedada xogta: Xakamaynta SPAM, maaraynta faallooyinka.
  3. Sharci: Oggolaanshahaaga
  4. Isgaarsiinta xogta: Xogta looma gudbin doono dhinacyada saddexaad marka laga reebo waajibaadka sharciga ah.
  5. Kaydinta xogta: Macluumaadka ay martigelisay Shabakadaha Occentus (EU)
  6. Xuquuqda: Waqti kasta oo aad xadidi karto, soo ceshan karto oo tirtiri karto macluumaadkaaga.