Beispiel #1
0
def main(argv=sys.argv):
    pigpio.stop()
    time.sleep(0.5)
    pigpio.start()

    us = Ultrasonic()
    us.start()

    while True:
        time.sleep(1)
        print "Distance : %.1f" % (us.distance,)

    pigpio.stop()
    return 0
    def __init__(self):
        pigpio.start()
        scheduler = Scheduler()
        self.overhead = RelayChannel.RelayChannel(11, scheduler)
        self.overhead.turn_on_daily_at('10', '0')
        self.overhead.turn_off_daily_at('22', '0')
        self.overhead.off()

        self.basking = RelayChannel.RelayChannel(13, scheduler)
        self.basking.turn_on_daily_at('12', '0')
        self.basking.turn_off_daily_at('15', '0')
        self.basking.off()

        self.top_left_dht = DHT22.DHT22Sensor(14)
        self.top_right_dht = DHT22.DHT22Sensor(15)
        self.bottom_left_dht = DHT11.DHT11Sensor(18)
        self.bottom_right_dht = DHT11.DHT11Sensor(4)
        self.weather = Weather.Weather()
Beispiel #3
0
    c = t9cb.tally() - oc
    time.sleep(0.1)
    CHECK(9, 2, c, 201, 0, "run script/script status")

    oc = t9cb.tally()
    pigpio.run_script(s, [2000, GPIO])
    while True:
        e, p = pigpio.script_status(s)
        if e != pigpio.PI_SCRIPT_RUNNING:
            break
        if p[9] < 1900:
            pigpio.stop_script(s)
        time.sleep(0.1)
    c = t9cb.tally() - oc
    time.sleep(0.1)
    CHECK(9, 3, c, 110, 10, "run/stop script/script status")

    e = pigpio.delete_script(s)
    CHECK(9, 4, e, 0, 0, "delete script")


if pigpio.start(""):  # must run notification test on localhost
    print("Connected to pigpio daemon.")

    test = [t0, t1, t2, t3, t4, t5, t6, t7, t8, t9]

    for t in test:
        t()

    pigpio.stop()
Beispiel #4
0
            if self.in_code:

                self.in_code = False

                pigpio.set_watchdog(self.gpio, 0)

                if self.edges > 12:

                    self.callback(self.hash_val)


if __name__ == "__main__":

    import time
    import pigpio
    import ir_hasher

    def callback(hash):
        print("hash={}".format(hash))

    pigpio.start()

    ir = ir_hasher.hasher(7, callback, 5)

    print("ctrl c to exit")

    time.sleep(300)

    pigpio.stop()
Beispiel #5
0
      print("bits={} facility={} id={}".format(bits, facility, id_num))
      if (bits == 26):
         ident = str(facility) + str(id_num)
         if ident in cached_allows and cached_allows[ident] > utc.localize(datetime.utcnow()):
            print "Cached authorization is present and valid"
            open_door()
         else:
            url = 'http://rpiambulance.com/doorauth.php'
            values = {'facility_id': facility,
            'card_id': id_num}
            data = urllib.urlencode(values)
            req = urllib2.Request(url, data)
            response = urllib2.urlopen(req)
            html = response.read()
            vars = json.loads(html)
            print vars
            if vars['authorized'] == True:
               cached_allows[ident] = dateutil.parser.parse(vars['until']).astimezone(utc)
               open_door()
           
   pigpio.start()

   w = wiegand.decoder(23, 24, callback)

   time.sleep(300)

   w.cancel()

   pigpio.stop()

Beispiel #6
0
#!/usr/bin/python

import tornado.web
import tornado.websocket
import tornado.ioloop
import pigpio
from time import sleep
import os.path

pigpio.start(port='8889')
#
cam_value = 1400
#
pigpio.set_servo_pulsewidth(7,0)
pigpio.set_servo_pulsewidth(8,0)
pigpio.set_servo_pulsewidth(24,cam_value)

# This is our WebSocketHandler - it handles the messages
# from the tornado server
class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.render("index.html")

class WebSocketHandler(tornado.websocket.WebSocketHandler):
    cam_value = 1400
    # the client connected
    def open(self):
        print "New client connected"
        self.write_message("You are connected")

    # the client sent the message
Beispiel #7
0
#!/usr/bin/python
#---------------------------------------------------------------------------------------------------------+
#                                                cam.py							  |
# Handles the camera and pan/tilt servos 		                                                  |
# (c) 2014 F. Anderson ([email protected])                                                              |
#---------------------------------------------------------------------------------------------------------+

from termcolor import colored
import comms, os, time
import RPi.GPIO as GPIO
from pigpio import set_servo_pulsewidth as servo_mv
import pigpio

pigpio.start() # start pigpio

pan = 22 # pan servo pin
tilt = 27 # tilt servo pin

pan_var = 1500 # initially, pan centre
tilt_var = 1000 # initially, tilt forwards

GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)

Neutral = 1500
Backwards = Left = 2500
Forwards = Right = 500
headlights = 7

GPIO.setup(headlights, GPIO.OUT)
GPIO.output(headlights, False)
Beispiel #8
0
class motor:
    def __init__(self, pin, speed):
        self.pin = pin
        self.speed = speed


motor1 = motor(pin1,
               1210)  #front motor speed initialised at 1210 ms pulse width
motor2 = motor(pin2,
               1230)  #back motor speed initialised at 1230 ms pulse width
motors = []  #array of motors to be controlled
motors.append(motor1)
motors.append(motor2)

if pigpio.start(''):  # must run notification test on localhost
    print("Connected to pigpio daemon.")

    #initialisation
    pigpio.set_mode(pin1, pigpio.OUTPUT)
    pigpio.set_mode(pin2, pigpio.OUTPUT)
    pigpio.set_PWM_range(pin1, 255)
    pigpio.set_PWM_range(pin2, 255)
    pigpio.set_PWM_frequency(pin1, 50)
    pigpio.set_PWM_frequency(pin2, 50)
    pigpio.set_servo_pulsewidth(pin1, 0)
    pigpio.set_servo_pulsewidth(pin2, 0)

    #open the serial port rfcomm1 defined in rfcomm.conf file
    ser = serial.Serial('/dev/rfcomm1', 38400, timeout=.08)
Beispiel #9
0
def init_pin(pin):
	pigpio.start()
	pigpio.set_mode(PIN, pigpio.OUTPUT)
Beispiel #10
0
def init_pin(pin):
    pigpio.start()
    pigpio.set_mode(PIN, pigpio.OUTPUT)