LoginSignup
0
1

More than 5 years have passed since last update.

line monitor > 付随Tool > shutdownボタン機能 (v0.1)

Last updated at Posted at 2015-12-05

line monitor
http://qiita.com/7of9/items/028556c5a819a6a8de96

動作確認
Raspberry Pi2 + raspbian

shutdownボタン

line monitorをスタンドアローン(ネット未接続)で使用する時、終了処理をきちんと行いたい。

GPIOでスイッチ入力をとらえて、スイッチが押されたらshutdow -hを行うことにした。

参考
http://tomoyukim.hatenablog.com/entry/2015/05/27/131500
http://d.hatena.ne.jp/penkoba/20130925/1380129824

基盤

スイッチだけの基盤を作成した。材料は以下の通り。

  • ROCタクトスイッチ PT-6301A-3 : 20円
  • ユニーバサル基盤 : 100円
  • AWG28のケーブル

スイッチの一方はPin#39(GND)に接続して、もう一方はPin#37に接続した。
プルアップにしておいて、スイッチがおされたらGPIO.LOWになる。

以下の写真の左側がスイッチのみの基板 (右側はIPアドレス表示用基板)。

Qiita.JPG

以下のように実装した。

v0.1 @ github

shutdownButton.py
#!/usr/bin/env python

import RPi.GPIO as GPIO
import time
import os

swio=37
GPIO.setmode(GPIO.BOARD)
GPIO.setup(swio, GPIO.IN, pull_up_down=GPIO.PUD_UP)

chk1=GPIO.HIGH
chk2=GPIO.HIGH
chk3=GPIO.HIGH
while True:
    chk1=chk2
    chk2=chk3
    chk3=GPIO.input(swio)
    #print GPIO.input(swio)
    if chk1==GPIO.HIGH and chk2==GPIO.LOW and chk3==GPIO.LOW:
        print "start shutdown"
        os.system("/sbin/shutdown -h now")

    time.sleep(0.3)

上記の判断でチャタリングによる誤動作が起きないかは未確認。

これを/etc/rc.localに登録しておくことで、shutdownボタンが有効になる。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1