LoginSignup
0
2

More than 5 years have passed since last update.

nfc raspberrypi felica servo: turn on/off light of a room

Last updated at Posted at 2017-04-18

nfc raspberrypi felica servo: turn on/off light of a room

自分のsuicaの場合だけ, サーボを回す.

turn_servo.py
import nfc
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
servo_pin = 3
GPIO.setup(servo_pin, GPIO.OUT)
servo = GPIO.PWM(servo_pin, 50)
my_id = '01010501b00ac30b'

def connected (tag):
    return
    #time.sleep(1)

clf = nfc.ContactlessFrontend('usb')
servo.start(0)
status = 'opened'

while True:
    print('waiting...')
    tag = clf.connect(rdwr={'on-connect':connected})
    felica_id = str(tag.idm).encode("hex")
    if (my_id == felica_id):
        print('matched!!')
        #servo.start(0)
        if (status == 'opened'):
            #open the door
            servo.ChangeDutyCycle(2.0)
            status = 'closed'
        elif(status == 'closed'):
            #close the door
            servo.ChangeDutyCycle(5.0)
            status = 'opened'
        #servo.stop()
    else:
        print('invalid id!!')

    print(status)
    print('scaned')
    time.sleep(0.2)

servo.stop()
GPIO.cleanup()

サーボで部屋の電気をon/off.
本当はドア鍵の開閉がやりたかったけど, 鍵が思いのほか固かったので断念.
しかもガムテ実装.
まあいっか.

IMG_3579.jpg

IMG_3578.jpg

補足

ホントは
http://kousaku-kousaku.blogspot.jp/2008/06/arduino.html
http://qiita.com/kedtn/items/7174f5112d99f12ce0e7
http://kondo-robot.com/product-category/servomotor/krs
http://radenzaiku.blog.shinobi.jp/%E3%83%AD%E3%83%9C%E3%83%83%E3%83%88%E5%85%A8%E8%88%AC/futaba%E3%82%B3%E3%83%9E%E3%83%B3%E3%83%89%E3%82%B5%E3%83%BC%E3%83%9C%E3%81%AE%E8%A7%92%E5%BA%A6%E5%8F%96%E5%BE%97
のように, サーボの角度をとったり, 精度上げたりもやろうかと思ったけど, 面倒くさくなったのでまたいつか.
KRSのサーボだと角度取得もできる...らしい?

0
2
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
2