2021-08-16
Actuator, NFC, Python, Raspberrypi, Sensor
nfc raspberrypi felica servo: turn on/off light of a room
nfc raspberrypi felica servo: turn on/off light of a room
自分のsuicaの場合だけ, サーボを回す.
import nfcimport RPi.GPIO as GPIOimport timeGPIO.setmode(GPIO.BOARD)servo_pin = 3GPIO.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. 本当はドア鍵の開閉がやりたかったけど, 鍵が思いのほか固かったので断念. しかもガムテ実装. まあいっか.


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