I have been following this tutorial Building a Model Smart Home with Raspberry PI and I have noticed that the Micro Servo part is not there. Could someone help me with it? I have written some code so far, but it is disastrous.
I only need to control one Micro servo, which I have connected to Power(3.3v), Ground, and (in BCM Mode) pin 17.
PS: Most of the code I've used is in this Gitub Repository.
I was thinking of doing it with Pigpio for more precise commands, but that would over-complicate it.
This is the code I have so far:
# Using PWM with RPi.GPIO
import RPi.GPIO as GPIO
import sys
from pubnub import Pubnub
GPIO.setmode(GPIO.BCM)
DOOR = 17
GPIO.setup(DOOR,GPIO.OUT)
door = GPIO.PWM(DOOR, 50)
door.start(0)
# PubNub
pubnub = Pubnub(publish_key='demo', subscribe_key='demo')
channel = 'pi-house'
def _callback(m, channel):
print(m)
dc = m['open']
if m['item'] == 'true':
door.ChangeDutyCycle(5)
elif m['item'] == 'false':
door.ChangeDutyCycle(7.5)
def _error(m):
print(m)
pubnub.subscribe(channels='pi-house', callback=_callback, error=_error)