{"id":2258,"date":"2018-11-30T09:48:31","date_gmt":"2018-11-30T00:48:31","guid":{"rendered":"http:\/\/research.itplants.com\/?p=2258"},"modified":"2019-11-12T10:47:46","modified_gmt":"2019-11-12T01:47:46","slug":"ds3231-for-pi","status":"publish","type":"post","link":"https:\/\/research.itplants.com\/?p=2258","title":{"rendered":"DS3231 for pi"},"content":{"rendered":"<p>Raspberry Pi\u306b\u306f\u3001RTC\u304c\u4ed8\u3044\u3066\u3044\u306a\u3044\u306e\u3067\u3001\u96fb\u6e90\u8d77\u52d5\u6642\u306e\u6642\u8a08\u304c\u72c2\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u3002fake-hwclock\u3068\u3044\u3046\u3082\u306e\u304c\u3001Raspberry Pi\u306e\u7d42\u4e86\u6642\u306e\u6642\u523b\u3092\u8a18\u9332\u3057\u3066\u3001\u518d\u958b\u6642\u306b\u3001\u305d\u306e\u6642\u523b\u3092\u30bb\u30c3\u30c8\u3059\u308b\u3088\u3046\u3067\u3059\u304c\u3001\u505c\u6b62\u3057\u3066\u3044\u305f\u6642\u9593\u3060\u3051\u8aa4\u5dee\u304c\u751f\u3058\u307e\u3059\u3002\u901a\u5e38\u306f\u3001\u30a4\u30f3\u30bf\u30fc\u30cd\u30c3\u30c8\u306b\u63a5\u7d9a\u3057\u3066\u3044\u3066\u3001ntp\u3067\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u6642\u9593\u3092\u53d6\u5f97\u3059\u308b\u306e\u3067\u554f\u984c\u306f\u3042\u308a\u307e\u305b\u3093\u304c\u3001\u30a4\u30f3\u30bf\u30fc\u30cd\u30c3\u30c8\u306b\u63a5\u7d9a\u3067\u304d\u306a\u3044\u5834\u5408\u306b\u306f\u3001\u6642\u523b\u306e\u8a2d\u5b9a\u304c\u624b\u52d5\u3068\u306a\u308b\u305f\u3081\u306b\u9762\u5012\u3067\u3059\u3002<\/p>\n<p>DS3231 for pi\u306f\u3001Raspberry Pi\u306eGPIO\u306b\u633f\u3057\u3066\u4f7f\u3048\u308bRTC\u3067\u3059\u3002<a href=\"https:\/\/research.itplants.com\/wp\/wp-content\/uploads\/2018\/11\/SKU146934b.jpg\" data-rel=\"lightbox-image-0\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" class=\"aligncenter size-full wp-image-2259\" src=\"https:\/\/research.itplants.com\/wp\/wp-content\/uploads\/2018\/11\/SKU146934b.jpg\" alt=\"\" width=\"600\" height=\"600\" srcset=\"https:\/\/research.itplants.com\/wp\/wp-content\/uploads\/2018\/11\/SKU146934b.jpg 600w, https:\/\/research.itplants.com\/wp\/wp-content\/uploads\/2018\/11\/SKU146934b-150x150.jpg 150w, https:\/\/research.itplants.com\/wp\/wp-content\/uploads\/2018\/11\/SKU146934b-300x300.jpg 300w, https:\/\/research.itplants.com\/wp\/wp-content\/uploads\/2018\/11\/SKU146934b-320x320.jpg 320w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<p>\u3053\u306e\u3088\u3046\u306b\u633f\u3057\u3066\u4f7f\u3044\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/research.itplants.com\/wp\/wp-content\/uploads\/2018\/11\/IMG_5715.jpg\" data-rel=\"lightbox-image-1\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" class=\"aligncenter size-full wp-image-2261\" src=\"https:\/\/research.itplants.com\/wp\/wp-content\/uploads\/2018\/11\/IMG_5715.jpg\" alt=\"\" width=\"640\" height=\"480\" srcset=\"https:\/\/research.itplants.com\/wp\/wp-content\/uploads\/2018\/11\/IMG_5715.jpg 640w, https:\/\/research.itplants.com\/wp\/wp-content\/uploads\/2018\/11\/IMG_5715-300x225.jpg 300w, https:\/\/research.itplants.com\/wp\/wp-content\/uploads\/2018\/11\/IMG_5715-320x240.jpg 320w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p>$i2cdetect -y 1<\/p>\n<p>\u3067\u300168\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>$ sudo vi <strong>\/boot\/config.txt<\/strong><\/p>\n<p><code>dtparam=i2c_arm=on<br \/>\ndtoverlay=i2c-rtc,ds3231<\/code><\/p>\n<p>\u3092\u8ffd\u52a0\u3057\u3066\u3001\u30ea\u30d6\u30fc\u30c8\u3057\u307e\u3059\u3002fake-hwclock\u306f\u3001\u4f7f\u308f\u306a\u3044\u306e\u3067\u505c\u6b62\u3057\u307e\u3059\u3002<\/p>\n<pre># sudo systemctl stop fake-hwclock\r\n# sudo systemctl disable fake-hwclock<\/pre>\n<p>RTC\u3092\u521d\u671f\u5316\u3057\u307e\u3059\u3002<\/p>\n<p>$<code>sudo hwclock --systohc<\/code><\/p>\n<p>\u30eb\u30fc\u30eb\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<p>$ sudo vi <strong>\/etc\/udev\/rules.d\/85-hwclock.rules<\/strong><\/p>\n<div>\n<pre><code># On the Raspberry Pi the RTC isn't available when systemd tries,\r\n# set the time from RTC now when it is available.\r\nKERNEL==\"rtc0\", RUN+=\"\/sbin\/hwclock --rtc=$root\/$name --hctosys\"<\/code><\/pre>\n<p>\u518d\u5ea6\u3001reboot\u5f8c\u306b\u306f\u3001RTC\u304c\u4f7f\u3048\u308b\u72b6\u614b\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002i2cdetect\u3067\u306f\u300168\u304cUU\u306b\u5909\u308f\u308a\u307e\u3059\u3002\u30b7\u30b9\u30c6\u30e0\u304c\u4f7f\u3063\u3066\u3044\u308b\u3068\u3044\u3046\u610f\u5473\u3067\u3057\u3087\u3046\u3002<\/p>\n<p><code><br \/>\n$ i2cdetect -y 1<br \/>\n0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f<br \/>\n00:          -- -- -- -- -- -- -- -- -- -- -- -- --<br \/>\n10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --<br \/>\n20: -- -- -- 23 -- -- -- -- -- -- -- -- -- -- -- --<br \/>\n30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --<br \/>\n40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --<br \/>\n50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --<br \/>\n60: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- --<br \/>\n70: -- -- -- -- -- -- 76 --<br \/>\n<\/code><br \/>\n<code>$ sudo hwclock -r<\/code><br \/>\n2018-11-30 09:44:35.560653+0900 \u6642\u523b\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u3002\u3053\u306e\u6642\u523b\u306f\u3001date\u30b3\u30de\u30f3\u30c9\u306e\u6642\u523b\u3068\u540c\u3058\u306b\u306a\u308a\u307e\u3059\u3002 \u518d\u5ea6\u3001\u30ea\u30d6\u30fc\u30c8\u3057\u3066\u304b\u3089\u3001RTC\u306e\u52d5\u4f5c\u3092\u78ba\u8a8d\u3057\u307e\u3059\u3002<br \/>\n<code>$ timedatectl<\/code><br \/>\n<code>Local time: \u6728 2019-05-09 08:50:35 JST<br \/>\nUniversal time: \u6c34 2019-05-08 23:50:35 UTC<br \/>\nRTC time:  \u6c34 2019-05-08 23:50:35<br \/>\nTime zone: Asia\/Tokyo (JST, +0900)<br \/>\nNetwork time on: yes<br \/>\nNTP synchronized: no<br \/>\nRTC in local TZ: no<\/code><\/p>\n<\/div>\n<h4>MacOSX\u3067\u3082sshfs\u3092\u4f7f\u3046<\/h4>\n<p><span class=\"Apple-converted-space\">brew\u3067\u4ee5\u4e0b\u306e\uff12\u3064\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308c\u3070\u4f7f\u3048\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002\u00a0<\/span><\/p>\n<p><span class=\"Apple-converted-space\">$\u00a0<\/span>brew cask install osxfuse<\/p>\n<p><span class=\"Apple-converted-space\">$\u00a0<\/span>brew install sshfs<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Raspberry Pi\u306b\u306f\u3001RTC\u304c\u4ed8\u3044\u3066\u3044\u306a\u3044\u306e\u3067\u3001\u96fb\u6e90\u8d77\u52d5\u6642\u306e\u6642\u8a08\u304c\u72c2\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u3002fake-hwclock\u3068\u3044\u3046\u3082\u306e\u304c\u3001Raspberry Pi\u306e\u7d42\u4e86\u6642\u306e\u6642\u523b\u3092\u8a18\u9332\u3057\u3066\u3001\u518d\u958b\u6642\u306b\u3001\u305d\u306e\u6642\u523b\u3092\u30bb\u30c3\u30c8\u3059\u308b\u3088\u3046\u3067\u3059\u304c&#8230;<\/p>\n<p><a class=\"more\" href=\"https:\/\/research.itplants.com\/?p=2258\"> Read more &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":2259,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/research.itplants.com\/index.php?rest_route=\/wp\/v2\/posts\/2258"}],"collection":[{"href":"https:\/\/research.itplants.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/research.itplants.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/research.itplants.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/research.itplants.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2258"}],"version-history":[{"count":12,"href":"https:\/\/research.itplants.com\/index.php?rest_route=\/wp\/v2\/posts\/2258\/revisions"}],"predecessor-version":[{"id":2649,"href":"https:\/\/research.itplants.com\/index.php?rest_route=\/wp\/v2\/posts\/2258\/revisions\/2649"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/research.itplants.com\/index.php?rest_route=\/wp\/v2\/media\/2259"}],"wp:attachment":[{"href":"https:\/\/research.itplants.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2258"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/research.itplants.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2258"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/research.itplants.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2258"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}