{"id":1253,"date":"2021-12-07T21:49:44","date_gmt":"2021-12-07T12:49:44","guid":{"rendered":"https:\/\/okamoto3.com\/?p=1253"},"modified":"2023-03-01T19:03:18","modified_gmt":"2023-03-01T10:03:18","slug":"raspberry-pi-os-power-sw","status":"publish","type":"post","link":"https:\/\/okamoto3.com\/index.php\/2021\/12\/07\/raspberry-pi-os-power-sw\/1253\/","title":{"rendered":"Raspberry pi OS \u96fb\u6e90\u30b9\u30a4\u30c3\u30c1\u53d6\u4ed8 \u306f\u3093\u3060\u4ed8\u3051\u7121\u3057 gpiozero Python3 systemd"},"content":{"rendered":"<p>\u30a2\u30a4\u30cd\u30c3\u30af\u30b9 \u5b9f\u9a13\u7528\u30b9\u30a4\u30c3\u30c1\u30fbLED\u30bb\u30c3\u30c8 KM-01\u4f7f\u3048\u306f\u3001\u306f\u3093\u3060\u4ed8\u3051\u8981\u3089\u3093\u3053\u3068\u306b\u6c17\u304c\u3064\u3044\u305f\u3002\u96fb\u6e90\u30b9\u30a4\u30c3\u30c1\u7de8<\/p><p>Raspberry Pi OS\u306a\u306e\u3067\u3001\u305d\u308c\u3089\u3057\u304f<\/p><ul class=\"wp-block-list\"><li>gpiozero<\/li>\n\n<li>systemd<\/li>\n\n<li>Python3 <\/li><\/ul><p>\u3067\u3084\u3063\u3066\u307f\u3088\u3002<\/p><p class=\"has-text-align-center\">WiringPi\u3044\u307e\u307e\u3067\u3042\u308a\u304c\u3068\u3046\u3054\u3056\u3044\u307e\u3057\u305f\u3002<\/p><h2 class=\"wp-block-heading\">\u4f7f\u3046\u3082\u306e<\/h2><p><center><br \/>\n<iframe style=\"width:120px;height:240px;\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\" frameborder=\"0\" src=\"https:\/\/rcm-fe.amazon-adsystem.com\/e\/cm?ref=tf_til&amp;t=shigeki3-22&amp;m=amazon&amp;o=9&amp;p=8&amp;l=as1&amp;IS1=1&amp;detail=1&amp;asins=B000FHQADO&amp;linkId=1e44b2094bfe9eb3f3b9614ac39ccce1&amp;bc1=ffffff&amp;lt1=_top&amp;fc1=333333&amp;lc1=0066c0&amp;bg1=ffffff&amp;f=ifr\"><br \/>\n    <\/iframe><br \/>\n<\/center><\/p><p class=\"has-text-align-center\"><a href=\"https:\/\/amzn.to\/3rFz25q\">\u30a2\u30de\u30be\u30f3\u3067\u898b\u308b<\/a><\/p><div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"247\" height=\"453\" src=\"https:\/\/i0.wp.com\/okamoto3.com\/wp-content\/uploads\/2021\/12\/IMG_20211206_164551-01_copy_247x453.jpeg?resize=247%2C453&#038;ssl=1\" alt=\"\" class=\"wp-image-1251\" srcset=\"https:\/\/i0.wp.com\/okamoto3.com\/wp-content\/uploads\/2021\/12\/IMG_20211206_164551-01_copy_247x453.jpeg?w=247&amp;ssl=1 247w, https:\/\/i0.wp.com\/okamoto3.com\/wp-content\/uploads\/2021\/12\/IMG_20211206_164551-01_copy_247x453.jpeg?resize=164%2C300&amp;ssl=1 164w\" sizes=\"auto, (max-width: 247px) 100vw, 247px\" \/><figcaption class=\"wp-element-caption\">\u300c\u691c\u8a3c\u30de\u30cb\u30a2\u300d\u30a8\u30a8\u540d\u524d\u3058\u3083<\/figcaption><\/figure><\/div><figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"442\" height=\"294\" src=\"https:\/\/i0.wp.com\/okamoto3.com\/wp-content\/uploads\/2021\/12\/IMG_20211206_164639-01_copy_442x294.jpeg?resize=442%2C294&#038;ssl=1\" alt=\"\" class=\"wp-image-1252\" srcset=\"https:\/\/i0.wp.com\/okamoto3.com\/wp-content\/uploads\/2021\/12\/IMG_20211206_164639-01_copy_442x294.jpeg?w=442&amp;ssl=1 442w, https:\/\/i0.wp.com\/okamoto3.com\/wp-content\/uploads\/2021\/12\/IMG_20211206_164639-01_copy_442x294.jpeg?resize=300%2C200&amp;ssl=1 300w\" sizes=\"auto, (max-width: 442px) 100vw, 442px\" \/><figcaption class=\"wp-element-caption\">\u30ea\u30fc\u30c9\u7dda\u304c\u77ed\u3044\u304b\u3089Raspberry Pi\u306b\u30a8\u30a8<\/figcaption><\/figure><h2 class=\"wp-block-heading\">\u30b9\u30a4\u30c3\u30c1\u306e\u53d6\u4ed8<\/h2><p>Raspberry Pi\u306e\u30d4\u30f3\u306e\u3046\u3061\u3001GND\u30d4\u30f3\u306e\u96a3\u306eGPIO\u30d4\u30f3\u306b\u307e\u305f\u3044\u3067\u5dee\u305b\u3070OK\u3058\u3083\u3002<\/p><p>\u308f\u3057\u306f\u3001<strong>GPIO17(11\u756a\u30d4\u30f3)\u3068GND(9\u756a\u30d4<\/strong>\u30f3)\u306b\u5dee\u3057\u8fbc\u3093\u3060\u3002<\/p><figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"564\" src=\"https:\/\/i0.wp.com\/okamoto3.com\/wp-content\/uploads\/2021\/12\/IMG_20211206_202748-01_copy_980x737.jpeg?resize=750%2C564&#038;ssl=1\" alt=\"\" class=\"wp-image-1257\" srcset=\"https:\/\/i0.wp.com\/okamoto3.com\/wp-content\/uploads\/2021\/12\/IMG_20211206_202748-01_copy_980x737.jpeg?w=980&amp;ssl=1 980w, https:\/\/i0.wp.com\/okamoto3.com\/wp-content\/uploads\/2021\/12\/IMG_20211206_202748-01_copy_980x737.jpeg?resize=300%2C226&amp;ssl=1 300w, https:\/\/i0.wp.com\/okamoto3.com\/wp-content\/uploads\/2021\/12\/IMG_20211206_202748-01_copy_980x737.jpeg?resize=768%2C578&amp;ssl=1 768w, https:\/\/i0.wp.com\/okamoto3.com\/wp-content\/uploads\/2021\/12\/IMG_20211206_202748-01_copy_980x737.jpeg?resize=600%2C451&amp;ssl=1 600w\" sizes=\"auto, (max-width: 750px) 100vw, 750px\" \/><figcaption class=\"wp-element-caption\">\u3053\u308c\u3060\u3051<\/figcaption><\/figure><h2 class=\"wp-block-heading\">\u30c7\u30fc\u30e2\u30f3(\u30b5\u30fc\u30d3\u30b9)<\/h2><p>\u30b9\u30a4\u30c3\u30c1\u3092\u76e3\u8996\u3057\u3066\u3001\u3060\u3044\u305f\u30443\u79d2\u4ee5\u4e0a\u9577\u62bc\u3057\u3057\u305f\u3089\u3001halt\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3059\u308b\u3084\u3064\u3002Python3 \u3058\u3083\u3002<\/p><p>\u308f\u3057\u306f\u3001\/home\/pi\/shutdown\u306b\u4f5c\u3063\u305f\u3002<\/p><ul class=\"wp-block-list\"><li><strong>mkdir \/home\/pi\/shutdown<\/strong><\/li>\n\n<li><strong>nano \/home\/pi\/shutdown\/shutdown.py<\/strong><\/li><\/ul><p>\u65b0\u3057\u3044\u6d41\u5100<strong>gpiozero<\/strong><\/p><p class=\"has-text-align-center\"><a href=\"https:\/\/gpiozero.readthedocs.io\/en\/stable\/recipes.html\">\u53c2\u8003\u30b5\u30a4\u30c8<\/a><\/p><pre class=\"wp-block-preformatted\">from gpiozero import Button<br>from subprocess import check_call<br>from signal import pause<br><br>def shutdown():<br>    check_call(['sudo', 'poweroff'])<br>    shutdown_btn = Button(17, hold_time=3)<br>    shutdown_btn.when_held = shutdown<br><br>pause()<\/pre><p>ctrl+z\u3067\u4fdd\u5b58<\/p><p><strong>\u5b9f\u884c\u6a29<\/strong><\/p><ul class=\"wp-block-list\"><li><strong>sudo chmod 755 \/home\/pi\/shutdown\/shutdown.p<\/strong>y<\/li><\/ul><p><strong>\u30b5\u30fc\u30d3\u30b9\u306e\u767b\u9332\u3068\u8d77\u52d5<\/strong><\/p><ul class=\"wp-block-list\"><li><strong>sudo nano \/usr\/lib\/systemd\/system\/shutdown.service<\/strong><\/li><\/ul><p><strong>\u30e6\u30cb\u30c3\u30c8\u30d5\u30a1\u30a4\u30eb<\/strong><\/p><pre class=\"wp-block-preformatted\">[Unit]<br>Description=Shutdown Daemon<br><br>[Service]<br>ExecStart = \/home\/pi\/shutdown\/shutdown.py<br>Restart=always<br>Type=simple<br><br>[Install]<br>WantedBy=multi-user.target<\/pre><p>ctrl+z\u3067\u4fdd\u5b58<\/p><ul class=\"wp-block-list\"><li><strong>sudo systemctl enable shutdown.service<\/strong><\/li>\n\n<li><strong>sudo systemctl daemon-reload<\/strong><\/li><\/ul><p><strong>\u78ba\u8a8d<\/strong><\/p><ul class=\"wp-block-list\"><li><strong>sudo systemctl status shutdown.service<\/strong><\/li><\/ul><div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"162\" src=\"https:\/\/i0.wp.com\/okamoto3.com\/wp-content\/uploads\/2021\/12\/Screenshot_2021-12-12-08-46-58-710_com.sonelli.juicessh-01_copy_2891x624.jpeg?resize=750%2C162&#038;ssl=1\" alt=\"\" class=\"wp-image-1343\" srcset=\"https:\/\/i0.wp.com\/okamoto3.com\/wp-content\/uploads\/2021\/12\/Screenshot_2021-12-12-08-46-58-710_com.sonelli.juicessh-01_copy_2891x624-scaled.jpeg?resize=1024%2C221&amp;ssl=1 1024w, https:\/\/i0.wp.com\/okamoto3.com\/wp-content\/uploads\/2021\/12\/Screenshot_2021-12-12-08-46-58-710_com.sonelli.juicessh-01_copy_2891x624-scaled.jpeg?resize=300%2C65&amp;ssl=1 300w, https:\/\/i0.wp.com\/okamoto3.com\/wp-content\/uploads\/2021\/12\/Screenshot_2021-12-12-08-46-58-710_com.sonelli.juicessh-01_copy_2891x624-scaled.jpeg?resize=768%2C166&amp;ssl=1 768w, https:\/\/i0.wp.com\/okamoto3.com\/wp-content\/uploads\/2021\/12\/Screenshot_2021-12-12-08-46-58-710_com.sonelli.juicessh-01_copy_2891x624-scaled.jpeg?resize=1536%2C332&amp;ssl=1 1536w, https:\/\/i0.wp.com\/okamoto3.com\/wp-content\/uploads\/2021\/12\/Screenshot_2021-12-12-08-46-58-710_com.sonelli.juicessh-01_copy_2891x624-scaled.jpeg?resize=2048%2C442&amp;ssl=1 2048w, https:\/\/i0.wp.com\/okamoto3.com\/wp-content\/uploads\/2021\/12\/Screenshot_2021-12-12-08-46-58-710_com.sonelli.juicessh-01_copy_2891x624-scaled.jpeg?resize=1568%2C338&amp;ssl=1 1568w, https:\/\/i0.wp.com\/okamoto3.com\/wp-content\/uploads\/2021\/12\/Screenshot_2021-12-12-08-46-58-710_com.sonelli.juicessh-01_copy_2891x624-scaled.jpeg?resize=600%2C130&amp;ssl=1 600w, https:\/\/i0.wp.com\/okamoto3.com\/wp-content\/uploads\/2021\/12\/Screenshot_2021-12-12-08-46-58-710_com.sonelli.juicessh-01_copy_2891x624-scaled.jpeg?w=2250&amp;ssl=1 2250w\" sizes=\"auto, (max-width: 750px) 100vw, 750px\" \/><figcaption class=\"wp-element-caption\">\u30a8\u30e9\u30fc\u304c\u7121\u3044\u3053\u3068\u3092\u78ba\u8a8d<\/figcaption><\/figure><\/div><p><strong>\u30a8\u30e9\u30fc\u304c\u3042\u308c\u306f\u30ed\u30b0\u898b\u3066\u307f\u3002<\/strong><\/p><ul class=\"wp-block-list\"><li><strong>less \/var\/log\/syslog<\/strong><\/li><\/ul><p><strong>\u505c\u6b62<\/strong><\/p><ul class=\"wp-block-list\"><li><strong>sudo systemctl <strong>disable <\/strong>shutdown.service<\/strong><\/li><\/ul><p>\u4ee5\u4e0a\uff01<\/p><hr class=\"wp-block-separator has-css-opacity\"\/><figure class=\"wp-block-embed is-type-wp-embed is-provider-sgg-039-s wp-block-embed-sgg-039-s\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"akn8NTHfYF\"><a href=\"https:\/\/okamoto3.com\/index.php\/2021\/12\/10\/gpiozero-pinout\/1321\/\">raspberry pi \u30d4\u30f3\u78ba\u8a8d pinout \u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;raspberry pi \u30d4\u30f3\u78ba\u8a8d pinout \u30a4\u30f3\u30b9\u30c8\u30fc\u30eb&#8221; &#8212; sGG&#039;s\" src=\"https:\/\/okamoto3.com\/index.php\/2021\/12\/10\/gpiozero-pinout\/1321\/embed\/#?secret=akn8NTHfYF\" data-secret=\"akn8NTHfYF\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><figcaption class=\"wp-element-caption\">\u52d5\u304b\u306a\u3044\u5834\u5408\u306e\u53c2\u8003<\/figcaption><\/figure><hr class=\"wp-block-separator has-css-opacity\"\/><div class=\"wp-block-image is-style-rounded\"><figure class=\"aligncenter size-thumbnail\"><a href=\"https:\/\/youtube.com\/user\/hishigeki3\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"150\" height=\"150\" src=\"https:\/\/i0.wp.com\/okamoto3.com\/wp-content\/uploads\/2021\/10\/Screenshot_2021-10-25-07-00-51-667_com.google.android.youtube-01_copy_270x246.jpeg?resize=150%2C150&#038;ssl=1\" alt=\"\" class=\"wp-image-658\" srcset=\"https:\/\/i0.wp.com\/okamoto3.com\/wp-content\/uploads\/2021\/10\/Screenshot_2021-10-25-07-00-51-667_com.google.android.youtube-01_copy_270x246.jpeg?resize=150%2C150&amp;ssl=1 150w, https:\/\/i0.wp.com\/okamoto3.com\/wp-content\/uploads\/2021\/10\/Screenshot_2021-10-25-07-00-51-667_com.google.android.youtube-01_copy_270x246.jpeg?resize=100%2C100&amp;ssl=1 100w\" sizes=\"auto, (max-width: 150px) 100vw, 150px\" \/><\/a><figcaption class=\"wp-element-caption\">\u3088\u308d\u3057\u3051\u308c\u3070\u30c1\u30e3\u30f3\u30cd\u30eb\u767b\u9332\u3088\u308d\u3057\u304f\u304a\u9858\u3044\u7533\u3057\u4e0a\u3052\u307e\u3059\uff01<\/figcaption><\/figure><\/div><hr class=\"wp-block-separator has-css-opacity\"\/><p><center><br \/>\n<iframe loading=\"lazy\" src=\"https:\/\/rcm-fe.amazon-adsystem.com\/e\/cm?o=9&amp;p=20&amp;l=ez&amp;f=ifr&amp;linkID=865d8e3440677383d9b2493a3354bc42&amp;t=shigeki3-22&amp;tracking_id=shigeki3-22\" width=\"120\" height=\"90\" scrolling=\"no\" border=\"0\" marginwidth=\"0\" style=\"border:none;\" frameborder=\"0\"><\/iframe><br \/>\n<\/center><\/p>","protected":false},"excerpt":{"rendered":"<p>\u30a2\u30a4\u30cd\u30c3\u30af\u30b9 \u5b9f\u9a13\u7528\u30b9\u30a4\u30c3\u30c1\u30fbLED\u30bb\u30c3\u30c8 KM-01\u4f7f\u3048\u306f\u3001\u306f\u3093\u3060\u4ed8\u3051\u8981\u3089\u3093\u3053\u3068\u306b\u6c17\u304c\u3064\u3044\u305f\u3002\u96fb\u6e90\u30b9\u30a4\u30c3\u30c1\u7de8 Raspberry Pi OS\u306a\u306e\u3067\u3001\u305d\u308c\u3089\u3057\u304f \u3067\u3084\u3063\u3066\u307f\u3088\u3002 WiringPi\u3044\u307e\u307e\u3067\u3042\u308a\u304c\u3068\u3046\u3054\u3056\u3044\u307e&hellip; <a class=\"more-link\" href=\"https:\/\/okamoto3.com\/index.php\/2021\/12\/07\/raspberry-pi-os-power-sw\/1253\/\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"screen-reader-text\">Raspberry pi OS \u96fb\u6e90\u30b9\u30a4\u30c3\u30c1\u53d6\u4ed8 \u306f\u3093\u3060\u4ed8\u3051\u7121\u3057 gpiozero Python3 systemd<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":1262,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[23,213,149],"tags":[126],"class_list":["post-1253","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-raspberry-pi","category-all-articles","category-production","tag-raspberry-pi","entry"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/okamoto3.com\/wp-content\/uploads\/2021\/12\/IMG_20211206_202748-01_copy_980x737-1.jpeg?fit=980%2C737&ssl=1","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/okamoto3.com\/index.php\/wp-json\/wp\/v2\/posts\/1253","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/okamoto3.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/okamoto3.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/okamoto3.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/okamoto3.com\/index.php\/wp-json\/wp\/v2\/comments?post=1253"}],"version-history":[{"count":39,"href":"https:\/\/okamoto3.com\/index.php\/wp-json\/wp\/v2\/posts\/1253\/revisions"}],"predecessor-version":[{"id":3089,"href":"https:\/\/okamoto3.com\/index.php\/wp-json\/wp\/v2\/posts\/1253\/revisions\/3089"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/okamoto3.com\/index.php\/wp-json\/wp\/v2\/media\/1262"}],"wp:attachment":[{"href":"https:\/\/okamoto3.com\/index.php\/wp-json\/wp\/v2\/media?parent=1253"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/okamoto3.com\/index.php\/wp-json\/wp\/v2\/categories?post=1253"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/okamoto3.com\/index.php\/wp-json\/wp\/v2\/tags?post=1253"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}