create account

WRITING DS3231 CLOCK MODULE SOFTWARE WITH ARDUINO [TUTORIAL LESSON 18] by sametceylan

View this thread on: hive.blogpeakd.comecency.com
· @sametceylan ·
$25.95
WRITING DS3231 CLOCK MODULE SOFTWARE WITH ARDUINO [TUTORIAL LESSON 18]
Hi there,
In this lesson we will deal with the use of the real time clock module. Our element links can be quite simple, but our software is a bit complicated and long. When I paste the code that I write here in my IDE program, the time will work fine. Where do we use this project? By using the real-time clock module, we can set it as a timer in our large systems, for example, we can make an alarm clock. Now let's start the software lesson

Herkese merhaba,
Bu dersimizde sizlerle gerçek zamanlı saat modülü kullanımını işleyeceğiz. Eleman bağlantılarımız oldukça basit olabilir ama yazılımımız biraz karmaşık ve uzun. Benim buraya yazdığım kodları IDE programımıza yapıştırdığınız zaman devremiz sorunsuz çalışacaktır. Peki bu projemizi nerede kullanırız?. Gerçek zamanlı saat modülünü kullanarak büyük sistemlerimizde zamanlayıcı olarak ayarlayabiliriz mesela çalar saat yapabiliriz. Şimdi yazılım dersine başlayalım.

https://www.gmelectronic.com/data/product/1024_1024/pctdetail.772-290.1.jpg

[ALINTI GORSEL](https://www.gmelectronic.com/data/product/1024_1024/pctdetail.772-290.1.jpg)
Gerçek zamanlı saat modülü malzememiz görselde bulunuyor. Saat modülü ilk enerji aldığıngda saatini set ediyo ve çalışmaya başlıyo 5v kesildiğinde içerisinde ki saati unutmuyor ve arka planda ki saati çalıştırmaya devam ediyor. Lakin bu şekilde çalışması için modülde pil takılı olmalıdır.Modüle ait 6 adet pin vardır bu pinler şu şekilde;
32K,SOW,SCL,SDA, VCC, GND bağlantıları tamamladıktan sonra Arduino IDE programıyla yazılıma geçebiliriz.

1.AŞAMA
Arduino kodumuzu bu dersten alıp kütüphanenize ekleyebileceğiniz için her aşamasını açıklamayacağım sadece gerekli kısımları anlatacağım. Kısaca geçersek eğer, wire h kütüphanemizi arduino programına çağırıyoruz. Devamına byte ve return komutlarını da ekliyoruz. 
KOD:
``` #include "Wire.h" ```
``` #define DS3231_I2C_ADDRESS 0x68 ```


``` byte decToBcd(byte val) ```
``` { ```
``` return( (val/10 * 16) + (val%10) ); ```
``` } ```
 
``` byte bcdToDec(byte val) ```
``` { ```
``` return( (val/16 * 10) + (val%16) ); ```
``` } ```
2.AŞAMA
Bu aşamada void setup kısmına başlıyoruz. Burada ilk ayarların kurulumunu yapacağız zaten iki satırlık kodumuz var bu aşamada hemen ekleyelim.
KOD:
``` Wire.begin(); ```
``` Serial.begin(9600); ```

3.AŞAMA
Void setup kısmına ekleyeceğimiz bir kod daha var. Bu kod sayesinde saatimizin başlangıç zamanını belirleyeceğiz yani yılın hangi ayının hangi gününün hangi saatinin hangi dakikasının ve hangi saniyesiyle başlayacağını kuracağız burada parantez içinde virgüllerle ayrılmış soldan sağa sayıların anlamları şu şekilde saniye,dakika,saat,haftanın kaçıncı günü(ingilizce alttabanlı olduğu için pazar 1. gün pazartesi 2. cumartesi 7.gündür),o ayın kaçıncı günü, yılın kaçıncı ayı, ve yıl
Ben bu kodu yazarken saniyeyi sıfır olarak ayarladım ve saat 12:52 günlerden pazartesi tarih ise 18.12.2017 olarak girdim sizler zaman ayarını istediğiniz şekilde değiştirebilirsiniz.
KOD:
``` setDS3231time(00,52,12,2,18,12,17); ```

4.AŞAMA
Bu aşamada kurulumunu yaptığımız saatin alabileceğimiz verilerini ve ekrana yazdırma komutlarını ekleyeceğiz uzunca bir algoritma olacak ancak sizler kolayca kopyala yapıştır yapabilirsiniz. Bu kodlar üzerinde kendinize göre değiştirmeniz gereken bir yer yok kodu buradan alıp kullanabilirsiniz.
KOD:

```  void setDS3231time ``` 
``` { ``` 
``` Wire.beginTransmission(DS3231_I2C_ADDRESS); ```
``` Wire.write(0);  ```
``` Wire.write(decToBcd(second));  ```
``` Wire.write(decToBcd(minute));  ```
``` Wire.write(decToBcd(hour));  ```
``` Wire.write(decToBcd(dayOfWeek));  ```
``` Wire.write(decToBcd(dayOfMonth));  ```
``` Wire.write(decToBcd(month));  ```
``` Wire.write(decToBcd(year));  ```
``` Wire.endTransmission(); ```
``` } ```
```void readDS3231time(byte *second, ```
``` byte *minute, ```
``` byte *hour, ```
 ``` byte *dayOfWeek, ```
 ``` byte *dayOfMonth, ```
``` byte *month, ```
``` byte *year) ```
``` { ```
``` Wire.beginTransmission(DS3231_I2C_ADDRESS); ```
``` Wire.write(0);  ```
``` Wire.endTransmission(); ```
``` Wire.requestFrom(DS3231_I2C_ADDRESS, 7); ```

``` *second = bcdToDec(Wire.read() & 0x7f); ```
``` *minute = bcdToDec(Wire.read()); ```
``` *hour = bcdToDec(Wire.read() & 0x3f); ```
``` *dayOfWeek = bcdToDec(Wire.read()); ```
``` *dayOfMonth = bcdToDec(Wire.read()); ```
``` *month = bcdToDec(Wire.read()); ```
``` *year = bcdToDec(Wire.read()); ```
``` } ```
``` void displayTime() ```
``` { ```
``` byte second, minute, hour, dayOfWeek, dayOfMonth, month, year; ```
``` readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, ```
``` &year); ```
``` Serial.print(hour, DEC); ```
``` Serial.print(":"); ```
``` if (minute<10) ```
``` { ```
``` Serial.print("0"); ```
``` } ```
``` Serial.print(minute, DEC); ```
``` Serial.print(":"); ```
``` if (second<10) ```
``` { ```
``` Serial.print("0"); ```
``` } ```
``` Serial.print(second, DEC); ```
``` Serial.print(" "); ```
``` Serial.print(dayOfMonth, DEC); ```
``` Serial.print("/"); ```
``` Serial.print(month, DEC); ```
``` Serial.print("/"); ```
``` Serial.print(year, DEC); ```
``` Serial.print(" Day of week: "); ```
``` switch(dayOfWeek){ ```
``` case 1: ```
``` Serial.println("Sunday"); ```
``` break; ```
``` case 2: ```
``` Serial.println("Monday"); ```
``` break; ```
``` case 3:```
``` Serial.println("Tuesday"); ```
``` break; ```
``` case 4: ```
``` Serial.println("Wednesday"); ```
``` break; ```
``` case 5: ```
``` Serial.println("Thursday"); ```
``` break; ```
``` case 6: ```
``` Serial.println("Friday"); ```
``` break; ```
``` case 7: ``` 
``` Serial.println("Saturday"); ```
``` break; ```
``` } ```
``` } ```





5.AŞAMA
Void loop döngüsü de dersimizin başında belirttiğim gibi kodumuzu kütüphane olarak kullanacağımız için sizler direk olarak buradan kodları alıp saati oluşturduktan sonra istediğiniz devreye zaman verisi giren cihaz olarak kullanabilirsiniz. Direk olarak loop döngüsünde ki kodlarıda ekliyorum.
KOD:
``` displayTime();  ```
``` delay(1000); ``` 

Yazılımımız burada son buldu hemen ekran görüntülerinide ekliyorum.

1.AŞAMA ![bandicam 2017-12-18 13-18-09-674.jpg](https://res.cloudinary.com/hpiynhbhq/image/upload/v1513592259/dkyuwumhxxnd4vlwcetl.jpg)
2 VE 3.AŞAMA ![bandicam 2017-12-18 13-18-26-274.jpg](https://res.cloudinary.com/hpiynhbhq/image/upload/v1513592291/rzaxsznp24z1xjzmldli.jpg)
4.AŞAMA ![bandicam 2017-12-18 13-18-40-649.jpg](https://res.cloudinary.com/hpiynhbhq/image/upload/v1513592341/apparqljgmrafkpbxnnq.jpg)
![bandicam 2017-12-18 13-18-50-753.jpg](https://res.cloudinary.com/hpiynhbhq/image/upload/v1513592351/pt4cdmnux1fgvupvza4j.jpg)

![bandicam 2017-12-18 13-18-55-883.jpg](https://res.cloudinary.com/hpiynhbhq/image/upload/v1513592360/lfh9kggjeizbfamyyfag.jpg)
5.AŞAMA
![bandicam 2017-12-18 13-19-00-904.jpg](https://res.cloudinary.com/hpiynhbhq/image/upload/v1513592376/qyyxw0aq8zam1gezaomq.jpg)



<br /><hr/><em>Posted on <a href="https://utopian.io/utopian-io/@sametceylan/writing-ds3231-clock-module-software-with-arduino-tutorial-lesson-18">Utopian.io -  Rewarding Open Source Contributors</a></em><hr/>
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
properties (23)
authorsametceylan
permlinkwriting-ds3231-clock-module-software-with-arduino-tutorial-lesson-18
categoryutopian-io
json_metadata"{"community":"utopian","app":"utopian/1.0.0","format":"markdown","repository":{"id":919161,"name":"Arduino","full_name":"arduino/Arduino","owner":{"login":"arduino","id":379109,"avatar_url":"https://avatars3.githubusercontent.com/u/379109?v=4","gravatar_id":"","url":"https://api.github.com/users/arduino","html_url":"https://github.com/arduino","followers_url":"https://api.github.com/users/arduino/followers","following_url":"https://api.github.com/users/arduino/following{/other_user}","gists_url":"https://api.github.com/users/arduino/gists{/gist_id}","starred_url":"https://api.github.com/users/arduino/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arduino/subscriptions","organizations_url":"https://api.github.com/users/arduino/orgs","repos_url":"https://api.github.com/users/arduino/repos","events_url":"https://api.github.com/users/arduino/events{/privacy}","received_events_url":"https://api.github.com/users/arduino/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/arduino/Arduino","description":"open-source electronics prototyping platform","fork":false,"url":"https://api.github.com/repos/arduino/Arduino","forks_url":"https://api.github.com/repos/arduino/Arduino/forks","keys_url":"https://api.github.com/repos/arduino/Arduino/keys{/key_id}","collaborators_url":"https://api.github.com/repos/arduino/Arduino/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/arduino/Arduino/teams","hooks_url":"https://api.github.com/repos/arduino/Arduino/hooks","issue_events_url":"https://api.github.com/repos/arduino/Arduino/issues/events{/number}","events_url":"https://api.github.com/repos/arduino/Arduino/events","assignees_url":"https://api.github.com/repos/arduino/Arduino/assignees{/user}","branches_url":"https://api.github.com/repos/arduino/Arduino/branches{/branch}","tags_url":"https://api.github.com/repos/arduino/Arduino/tags","blobs_url":"https://api.github.com/repos/arduino/Arduino/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/arduino/Arduino/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/arduino/Arduino/git/refs{/sha}","trees_url":"https://api.github.com/repos/arduino/Arduino/git/trees{/sha}","statuses_url":"https://api.github.com/repos/arduino/Arduino/statuses/{sha}","languages_url":"https://api.github.com/repos/arduino/Arduino/languages","stargazers_url":"https://api.github.com/repos/arduino/Arduino/stargazers","contributors_url":"https://api.github.com/repos/arduino/Arduino/contributors","subscribers_url":"https://api.github.com/repos/arduino/Arduino/subscribers","subscription_url":"https://api.github.com/repos/arduino/Arduino/subscription","commits_url":"https://api.github.com/repos/arduino/Arduino/commits{/sha}","git_commits_url":"https://api.github.com/repos/arduino/Arduino/git/commits{/sha}","comments_url":"https://api.github.com/repos/arduino/Arduino/comments{/number}","issue_comment_url":"https://api.github.com/repos/arduino/Arduino/issues/comments{/number}","contents_url":"https://api.github.com/repos/arduino/Arduino/contents/{+path}","compare_url":"https://api.github.com/repos/arduino/Arduino/compare/{base}...{head}","merges_url":"https://api.github.com/repos/arduino/Arduino/merges","archive_url":"https://api.github.com/repos/arduino/Arduino/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/arduino/Arduino/downloads","issues_url":"https://api.github.com/repos/arduino/Arduino/issues{/number}","pulls_url":"https://api.github.com/repos/arduino/Arduino/pulls{/number}","milestones_url":"https://api.github.com/repos/arduino/Arduino/milestones{/number}","notifications_url":"https://api.github.com/repos/arduino/Arduino/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/arduino/Arduino/labels{/name}","releases_url":"https://api.github.com/repos/arduino/Arduino/releases{/id}","deployments_url":"https://api.github.com/repos/arduino/Arduino/deployments","created_at":"2010-09-17T19:10:36Z","updated_at":"2017-12-18T09:28:38Z","pushed_at":"2017-12-16T16:14:06Z","git_url":"git://github.com/arduino/Arduino.git","ssh_url":"git@github.com:arduino/Arduino.git","clone_url":"https://github.com/arduino/Arduino.git","svn_url":"https://github.com/arduino/Arduino","homepage":"http://www.arduino.cc/","size":1358686,"stargazers_count":7495,"watchers_count":7495,"language":"C","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5935,"mirror_url":null,"archived":false,"open_issues_count":928,"license":{"key":"other","name":"Other","spdx_id":null,"url":null},"forks":5935,"open_issues":928,"watchers":7495,"default_branch":"master","score":106.11644},"pullRequests":[],"platform":"github","type":"tutorials","tags":["utopian-io","utopian-io","tr","tutorial","software"],"links":["https://www.gmelectronic.com/data/product/1024_1024/pctdetail.772-290.1.jpg","https://res.cloudinary.com/hpiynhbhq/image/upload/v1513592259/dkyuwumhxxnd4vlwcetl.jpg","https://res.cloudinary.com/hpiynhbhq/image/upload/v1513592291/rzaxsznp24z1xjzmldli.jpg","https://res.cloudinary.com/hpiynhbhq/image/upload/v1513592341/apparqljgmrafkpbxnnq.jpg","https://res.cloudinary.com/hpiynhbhq/image/upload/v1513592351/pt4cdmnux1fgvupvza4j.jpg","https://res.cloudinary.com/hpiynhbhq/image/upload/v1513592360/lfh9kggjeizbfamyyfag.jpg","https://res.cloudinary.com/hpiynhbhq/image/upload/v1513592376/qyyxw0aq8zam1gezaomq.jpg"],"image":["https://res.cloudinary.com/hpiynhbhq/image/upload/v1513592259/dkyuwumhxxnd4vlwcetl.jpg","https://res.cloudinary.com/hpiynhbhq/image/upload/v1513592291/rzaxsznp24z1xjzmldli.jpg","https://res.cloudinary.com/hpiynhbhq/image/upload/v1513592341/apparqljgmrafkpbxnnq.jpg","https://res.cloudinary.com/hpiynhbhq/image/upload/v1513592351/pt4cdmnux1fgvupvza4j.jpg","https://res.cloudinary.com/hpiynhbhq/image/upload/v1513592360/lfh9kggjeizbfamyyfag.jpg","https://res.cloudinary.com/hpiynhbhq/image/upload/v1513592376/qyyxw0aq8zam1gezaomq.jpg"]}"
created2017-12-18 10:20:48
last_update2017-12-18 10:20:48
depth0
children3
last_payout2017-12-25 10:20:48
cashout_time1969-12-31 23:59:59
total_payout_value18.211 HBD
curator_payout_value7.734 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length7,098
author_reputation13,315,067,546,486
root_title"WRITING DS3231 CLOCK MODULE SOFTWARE WITH ARDUINO [TUTORIAL LESSON 18]"
beneficiaries
0.
accountutopian.pay
weight2,500
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id24,001,849
net_rshares5,164,443,158,287
author_curate_reward""
vote details (60)
@damla ·
Thank you for the contribution. It has been approved.

You can contact us on [Discord](https://discord.gg/UCvqCsx).
**[[utopian-moderator]](https://utopian.io/moderators)**
properties (22)
authordamla
permlinkre-sametceylan-writing-ds3231-clock-module-software-with-arduino-tutorial-lesson-18-20171220t224545004z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"community":"utopian","app":"utopian/1.0.0"}
created2017-12-20 22:45:51
last_update2017-12-20 22:45:51
depth1
children0
last_payout2017-12-27 22:45:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length172
author_reputation87,558,484,358,792
root_title"WRITING DS3231 CLOCK MODULE SOFTWARE WITH ARDUINO [TUTORIAL LESSON 18]"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id24,424,895
net_rshares0
@minnowsupport ·
<p>Congratulations!  This post has been upvoted from the communal account, @minnowsupport, by sametceylan from the Minnow Support Project.  It's a witness project run by aggroed, ausbitbank, teamsteem, theprophet0, someguy123, neoxian, followbtcnews/crimsonclad, and netuoso.  The goal is to help Steemit grow by supporting Minnows and creating a social network.  Please find us in the <a href="https://discord.gg/HYj4yvw">Peace, Abundance, and Liberty Network (PALnet) Discord Channel</a>.  It's a completely public and open space to all members of the Steemit community who voluntarily choose to be there.</p>

<p>If you would like to delegate to the Minnow Support Project you can do so by clicking on the following links: <a href="https://v2.steemconnect.com/sign/delegateVestingShares?delegator=&amp;delegatee=minnowsupport&amp;vesting_shares=102530.639667%20VESTS">50SP</a>, <a href="https://v2.steemconnect.com/sign/delegateVestingShares?delegator=&amp;delegatee=minnowsupport&amp;vesting_shares=205303.639667%20VESTS">100SP</a>, <a href="https://v2.steemconnect.com/sign/delegateVestingShares?delegator=&amp;delegatee=minnowsupport&amp;vesting_shares=514303.639667%20VESTS">250SP</a>, <a href="https://v2.steemconnect.com/sign/delegateVestingShares?delegator=&amp;delegatee=minnowsupport&amp;vesting_shares=1025303.639667%20VESTS">500SP</a>, <a href="https://v2.steemconnect.com/sign/delegateVestingShares?delegator=&amp;delegatee=minnowsupport&amp;vesting_shares=2053030.639667%20VESTS">1000SP</a>, <a href="https://v2.steemconnect.com/sign/delegateVestingShares?delegator=&amp;delegatee=minnowsupport&amp;vesting_shares=10253030.639667%20VESTS">5000SP</a>.  <strong>Be sure to leave at least 50SP undelegated on your account.</strong></p>
properties (22)
authorminnowsupport
permlinkre-sametceylan-writing-ds3231-clock-module-software-with-arduino-tutorial-lesson-18-20171218t114116715z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"cosgrove/0.0.2"}
created2017-12-18 11:41:15
last_update2017-12-18 11:41:15
depth1
children0
last_payout2017-12-25 11:41:15
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,749
author_reputation148,902,805,319,183
root_title"WRITING DS3231 CLOCK MODULE SOFTWARE WITH ARDUINO [TUTORIAL LESSON 18]"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id24,011,047
net_rshares0
@utopian-io ·
### Hey @sametceylan I am @utopian-io. I have just upvoted you!
#### Achievements
- You have less than 500 followers. Just gave you a gift to help you succeed!
- Seems like you contribute quite often. AMAZING!
#### Suggestions
- Contribute more often to get higher and higher rewards. I wish to see you often!
- Work on your followers to increase the votes/rewards. I follow what humans do and my vote is mainly based on that. Good luck!
#### Get Noticed!
- Did you know project owners can manually vote with their own voting power or by voting power delegated to their projects? Ask the project owner to review your contributions!
#### Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. <a href="https://discord.gg/zTrEMqB">Participate on Discord</a>. Lets GROW TOGETHER!
- <a href="https://v2.steemconnect.com/sign/account-witness-vote?witness=utopian-io&approve=1">Vote for my Witness With SteemConnect</a>
- <a href="https://v2.steemconnect.com/sign/account-witness-proxy?proxy=utopian-io&approve=1">Proxy vote to Utopian Witness with SteemConnect</a>
- Or vote/proxy on <a href="https://steemit.com/~witnesses">Steemit Witnesses</a>

[![mooncryption-utopian-witness-gif](https://steemitimages.com/DQmYPUuQRptAqNBCQRwQjKWAqWU3zJkL3RXVUtEKVury8up/mooncryption-s-utopian-io-witness-gif.gif)](https://steemit.com/~witnesses)

**Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x**
properties (22)
authorutopian-io
permlinkre-sametceylan-writing-ds3231-clock-module-software-with-arduino-tutorial-lesson-18-20171221t002606101z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"community":"utopian","app":"utopian/1.0.0"}
created2017-12-21 00:26:06
last_update2017-12-21 00:26:06
depth1
children0
last_payout2017-12-28 00:26:06
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,509
author_reputation152,955,367,999,756
root_title"WRITING DS3231 CLOCK MODULE SOFTWARE WITH ARDUINO [TUTORIAL LESSON 18]"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id24,435,266
net_rshares0