Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

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

More than 3 years have passed since last update.

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

https://youtu.be/x625sLmCasE

補足

ホントは
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のサーボだと角度取得もできる...らしい?

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away