0

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)
halfer
  • 19,824
  • 17
  • 99
  • 186
KnalexAlex
  • 11
  • 1
  • 3
  • 1
    What problem are you having with it? – halfer Apr 21 '16 at 13:03
  • 3
    I guessed that, based on the fact that you have posted here. But that's probably not specific enough - what area are you working on? What small bit doesn't quite work? Do you get any errors? If you run it and you want it to do something, what exactly does not happen? What help can readers give you, bearing in mind that "finish it for me" is discouraged here? – halfer Apr 21 '16 at 14:03
  • Which part is not working? Does your servo works without PubNub connection? Just add `door.ChangeDutyCycle(10)` before `# PubNub`, and comment out everything after `# PubNub`. Does it work? – girlie_mac Apr 21 '16 at 16:44
  • Also, what type of servo are you using? stepper or regular one? – girlie_mac Apr 21 '16 at 23:06
  • the (regular) servo works perfectly, the problem is that I cant control it from the WEB UI. (the servo does not respond to the command pubnub/the Web UI sends it (open/close the door) – KnalexAlex Apr 23 '16 at 18:01
  • If the `door.ChangeDutyCycle()` calls are what are used to control the server, as they actually called in your web app? Is this a pub-sub listener or the web controller? – halfer Apr 24 '16 at 10:16
  • When I click the open door button on the web UI, it sends the data (to open the door) to pubnub, and that works fine. Then, pubnub sends the data to the Servo, which is supposed to move. This is what doesn't work; the servo does not react to the command pubnub send it. – KnalexAlex Apr 24 '16 at 11:04
  • I dont know if its because of the code or something else – KnalexAlex Apr 24 '16 at 11:04

0 Answers0