0

I just finished all of the prototyping of this project:, and I encountered 2 problems: https://www.pubnub.com/blog/2015-03-17-building-a-model-smart-home-with-raspberry-pi/

  1. I cant run all of the programs at once(Humidity and Temperature, LEDs, Micro Servo motors, etc...)
  2. I can't have more than three LED's (technically two)

What can I do to run everything at once, so it is all displayed in the WEB UI? How can I have more LED's, since the limit is 50mah which is about 2 LED's? (they can be three per 'room', so three per GPIO pin or just per GPIO). I dont see hoe it could work with such a power limit. Also, they need to be controlled with PWM. There simply isn't enough power on the Raspberry Pi!

the code for the DHT22 sensor is:

import time
import sys
from pubnub import Pubnub
import Adafruit_DHT as dht

pubnub = Pubnub(publish_key='demo', subscribe_key='demo')
channel = 'pi-house'

def callback(message):
print(message)

#published in this fashion to comply with Eon
while True:
    h,t = dht.read_retry(dht.DHT22, 4)
    temp='{0:0.1f}'.format(t)
    hum='{0:0.1f}'.format(h)
    message = {'temperature': temp, 'humidity': hum}
    print 'Temp={0:0.1f}*C Humidity={1:0.1f}%'.format(t, h)
    pubnub.publish(channel=channel, message=message, callback=callback, error=callback)  

the code for the led's is:

import RPi.GPIO as GPIO
import time
import sys
from pubnub import Pubnub

GPIO.setmode(GPIO.BCM)

PIN_LIVING = 22
PIN_PORCH = 17
PIN_FIREPLACE = 27

GPIO.setup(PIN_LIVING,GPIO.OUT)
GPIO.setup(PIN_PORCH,GPIO.OUT)
GPIO.setup(PIN_FIREPLACE,GPIO.OUT)

FREQ = 100 # frequency in Hz
FIRE_FREQ = 30 #  flickering effect

# Duty Cycle (0 <= dc <=100)

living = GPIO.PWM(PIN_LIVING, FREQ)
living.start(0)

porch = GPIO.PWM(PIN_PORCH, FREQ)
porch.start(0)

fire = GPIO.PWM(PIN_FIREPLACE, FIRE_FREQ)
fire.start(0)

# PubNub

pubnub = Pubnub(publish_key='demo', subscribe_key='demo')

channel = 'pi-house'

def _callback(m, channel):
    print(m)

    dc = m['brightness'] *10

    if m['item'] == 'light-living':
        living.ChangeDutyCycle(dc)

    elif m['item'] == 'light-porch':
        porch.ChangeDutyCycle(dc)

    elif m['item'] == 'fireplace':
        fire.ChangeDutyCycle(dc)

def _error(m):
  print(m)

pubnub.subscribe(channels='pi-house', callback=_callback, error=_error)

try:
    while 1:
        pass
except KeyboardInterrupt:
    GPIO.cleanup()
    sys.exit(1)

Thanks!

KnalexAlex
  • 11
  • 1
  • 3
  • 1
    Can you show your code/how you have set up and run these programs? It is perfectly possible to run multiple programs on the raspberry pi, it's about as powerful as a mid-range laptop was a few years ago. – Barnabus Apr 12 '16 at 16:57
  • *"How can I have more LED's, since the limit is 50mah which is about 2 LED's?"* Don't source power from the GPIO pins at all. Instead, use the GPIO signals to control a transistor, MOSFET or GPIO expander. Alternatively, get an arduino clone for a dollar online, connect the LEDs to that and control it from the Pi via a serial connection. – jDo Apr 12 '16 at 17:08
  • Thanks. How would I use a MOSFET to control the signlas from the GPIO pins and power it externally? – KnalexAlex Apr 16 '16 at 11:42
  • I have update the post and on it is the code – KnalexAlex Apr 16 '16 at 15:41

0 Answers0