1. keitasumiya

    Posted

    keitasumiya
Changes in title
+nfc raspberrypi felica servo: turn on/off light of a room
Changes in tags
Changes in body
Source | HTML | Preview
@@ -0,0 +1,59 @@
+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](https://qiita-image-store.s3.amazonaws.com/0/102253/882de38a-1c45-7fa1-e445-37719a3c0e9c.jpeg)
+
+
+![IMG_3578.jpg](https://qiita-image-store.s3.amazonaws.com/0/102253/06e5cee1-c1f1-d082-f4d4-305d28c0c6f3.jpeg)
+
+https://youtu.be/x625sLmCasE