コード例 #1
0
    def __init__(self):
        """
        DC maps DragonBoard 410c GPIO pins for Debian to the L293N H-Bridge I/C, ready to receive control
        messages from Manager.py.

        Green wire : Pin 23 -> OpAmp Node 1 -> L298N h-bridge Input 2
        White wire : Pin 24 -> OpAmp Node 4 -> L298N h-bridge Enable A
        Yellow wire : Pin 26 -> OpAmp Node 3 -> L298N h-bridge Input 1

        Set Input 2 to Low, Input 1 to High for clockwise spin.
        """

        self.gp = GPIOProcessor()

        # h-bridge
        self.green = self.gp.getPin23()
        self.white = self.gp.getPin24()
        self.yellow = self.gp.getPin26()

        self.green.out()
        self.white.out()
        self.yellow.out()

        # clockwise
        self.green.low()  # Input 2
        self.yellow.high()  # Input 1

        self.isPropSpinning = False
コード例 #2
0
 def __init__(self, devices=1, intensity=5, scanlimit=7):
     '''Constructor
        ScanLimit set to 7
        Intensity set to 5 out of 0:15
        Uses GPIOs 23, 24 25 as DIN, CS, and CLK respectively'''
     GP = GPIOProcessor()
     global DIN
     global CS
     global CLK
     DIN = GP.getPin34()  # Gpio 
     CS  = GP.getPin33()  # Gpio 
     CLK = GP.getPin32()  # Gpio 
     DIN.out()
     CS.out()
     CLK.out()
     global numOfDevices
     numOfDevices = devices
     for i in range(0,numOfDevices):
         self.shutDown(False,i+1)
     for i in range(0,numOfDevices):
         self.setScanLimit(scanlimit,i+1)
     for i in range(0,numOfDevices):
         self.setIntensity(intensity,i+1)
     self.clearDisplays()
     global Characters
     Characters = AL()
コード例 #3
0
 def __enter__(self):
     self.GP = GPIOProcessor()
     self.forward_pin = self.GP.getPin25()
     self.forward_pin.out()
     self.right_high = self.GP.getPin26()
     self.right_high.out()
     self.right_low = self.GP.getPin27()
     self.right_low.out()
     self.left_high = self.GP.getPin29()
     self.left_high.out()
     self.left_low = self.GP.getPin30()
     self.left_low.out()
     return self
コード例 #4
0
    def __init__(self):
        self.speed = 343  # metres per second (m/s) through Air
        # self.speed = 1464  # metres per second (m/s) through Water
        self.depth = 0

        """
        Trig (blue wire) : Pin 33 -> OpAmp Node 2 -> Ultra-sonic sensor Trig
        Echo (red wire) : Ultra-sonic sensor Echo -> Pin 30
        """
        self.gp = GPIOProcessor()

        self.trig = self.gp.getPin33()
        self.echo = self.gp.getPin34()

        self.trig.out()
        self.echo.input()
コード例 #5
0
    def __init__(self, pin1=24, pin2=28, pin3=25, pin4=33):
        """Initialize the interface passing the four GPIO pins
           to connect to.  Be sure to subtract 902 from the pin
           out diagram.  For example, GPIO pin 29 corresponds to 
           pin out 926.  To use this pin pass 926-902 or 24
        """
        self.GP = GPIOProcessor()
        self.pin1 = self.GP.getPin(pin1)
        self.pin2 = self.GP.getPin(pin2)
        self.pin3 = self.GP.getPin(pin3)
        self.pin4 = self.GP.getPin(pin4)
        self.pinl = [self.pin1, self.pin2, self.pin3, self.pin4]

        for k in range(4):
            self.pinl[k].out()

        self.speed = 100.0
コード例 #6
0
class GPIO():
    def __init__(self):
        pass

    def __enter__(self):
        self.GP = GPIOProcessor()
        self.forward_pin = self.GP.getPin25()
        self.forward_pin.out()
        self.right_high = self.GP.getPin26()
        self.right_high.out()
        self.right_low = self.GP.getPin27()
        self.right_low.out()
        self.left_high = self.GP.getPin29()
        self.left_high.out()
        self.left_low = self.GP.getPin30()
        self.left_low.out()
        return self

    def __exit__(self, exc_type, exc_val, exc_tb):
        self.GP.cleanup()

    def brake(self):
        self.forward_pin.low()

    def unbrake(self):
        self.forward_pin.high()

    def turn_left(self):
        self.left_low.low()
        self.left_high.high()

    def turn_right(self):
        self.right_low.low()
        self.right_high.high()
コード例 #7
0
class DC:
    def __init__(self):
        """
        DC maps DragonBoard 410c GPIO pins for Debian to the L293N H-Bridge I/C, ready to receive control
        messages from Manager.py.

        Green wire : Pin 23 -> OpAmp Node 1 -> L298N h-bridge Input 2
        White wire : Pin 24 -> OpAmp Node 4 -> L298N h-bridge Enable A
        Yellow wire : Pin 26 -> OpAmp Node 3 -> L298N h-bridge Input 1

        Set Input 2 to Low, Input 1 to High for clockwise spin.
        """

        self.gp = GPIOProcessor()

        # h-bridge
        self.green = self.gp.getPin23()
        self.white = self.gp.getPin24()
        self.yellow = self.gp.getPin26()

        self.green.out()
        self.white.out()
        self.yellow.out()

        # clockwise
        self.green.low()  # Input 2
        self.yellow.high()  # Input 1

        self.isPropSpinning = False

    def start_motor(self):
        """
        Set Enable A to High to start motor.
        :rtype: Boolean
        :return: True if motor started, False if failed.
        """
        try:
            self.white.low()
            self.white.high()
            self.isPropSpinning = True
            return True
        except KeyboardInterrupt():
            print "Keyboard interrupt received. Cleaning up ..."
            self.gp.cleanup()
            return False

    def stop_motor(self):
        """
        Set Enable A to Low to stop motor.
        :rtype: Boolean
        :return: True if motor stopped, False if failed.
        """
        try:
            self.white.low()
            self.isPropSpinning = False
            return True
        except KeyboardInterrupt():
            print "Keyboard interrupt received. Cleaning up ..."
            self.gp.cleanup()
コード例 #8
0
ファイル: Sensors_v1.py プロジェクト: vino09/contadorPessoas
    def __init__(self, logger, so):
        self.frame = None
       
        self.LOG = logger
        self._OS = so
        
        # Tenta importar a biblioteca GPIO correta para o hardware
        try:
            if (self._OS == 'Windows') or (self._OS == 'vmlinux') :
                # Fake GPIO
                #self.GPIO = '{ fake}' 
                pass
                
            elif self._OS == 'raspberrypi':     # para a Raspberry PI
                import RPi.GPIO as gpio
                
                #Configuring GPIO 
                gpio.setwarnings(False)
                gpio.setmode(gpio.BOARD)
                gpio.setup(38,gpio.OUT)  # Led vermelho
                gpio.setup(40,gpio.OUT)  # Led azul
                 
                #Configuring GPIO as PWM (frequency 20 Hz)
                self._pwmRed = gpio.PWM(38,20)
                self._pwmBlue = gpio.PWM(40,20)

                #Initializing PWM
                self._pwmBlue.start(0)
                self._pwmRed.start(0)
                
                self._gps = GPS(logger, self._OS)
                self._rfid = RFIDReader(logger, self, self._OS)
                
            elif self._OS == 'linaro-alip':  # Para a Dragon
                from GPIOLibrary import GPIOProcessor

                self.GPIO = GPIOProcessor()
                self._gps = GPS(logger, self._OS)
                self._rfid = RFIDReader(logger, self, self._OS)

            else:
                # Do the default
                self.LOG.critical('Unknown operational system [' +self._OS +']')
                sys.exit(SENSOR_UNKNOWN_SO)
            
        except RuntimeError:
            self.LOG.critical('Error importing GPIO for system [%s]!  This is probably because you need superuser privileges.  You can achieve this by using [sudo] to run your script', self.OS)
            sys.exit(SENSOR_CANNOT_IMPORT_GPIO)
        
         # Default value 
        self._Temp = 23
        
        # sucesso
        self.LOG.info('Sensors[%s] successfully loaded', self._OS)
コード例 #9
0
    def __init__(self, pin1=24, pin2=28, pin3=25, pin4=33):
        """Initialize the interface passing the four GPIO pins
           to connect to.  Be sure to subtract 902 from the pin
           out diagram.  For example, GPIO pin 29 corresponds to 
           pin out 926.  To use this pin pass 926-902 or 24
        """
        self.GP = GPIOProcessor()
        self.pin1 = self.GP.getPin(pin1)
        self.pin2 = self.GP.getPin(pin2)
        self.pin3 = self.GP.getPin(pin3)
        self.pin4 = self.GP.getPin(pin4)
        self.pinl = [self.pin1, self.pin2, self.pin3, self.pin4]

        for k in range(4):
            self.pinl[k].out()

        self.speed = 100.0
コード例 #10
0
from GPIOLibrary import GPIOProcessor
import time
import math

GP = GPIOProcessor()

# GPIO assignment
# TRIG      Pin 23
# ECHO      Pin 27
# GREEN     Pin 24
# YELLOW    Pin 25
# RED       Pin 26

try:

    # Create GPIO variables
    trig = GP.getPin34()
    echo = GP.getPin27()
    green = GP.getPin24()
    yellow = GP.getPin25()
    red = GP.getPin26()

    trig.out()
    echo.input()
    green.out()
    yellow.out()
    red.out()

    # Duration of Activation (seconds)
    D = 10
コード例 #11
0
from GPIOLibrary import GPIOProcessor
import time

GP = GPIOProcessor()

try:
    on = False
    for i in range(0, 20):

        if not on:
            GP.setLED(1)
        else:
            GP.setLED(0)
        on = not on
        time.sleep(1)

finally:
    GP.cleanup()
コード例 #12
0
ファイル: stepper2.py プロジェクト: vidit2011998/WannaPark
    from GPIOLibrary import GPIOProcessor
    import time
    import math

    GP = GPIOProcessor()
    import socket
    # import time

    MAGIC = "face600d"

    server_socket = socket.socket()
    server_host = '192.168.43.20'
    server_port = 5002
    server_socket.bind((server_host, server_port))
    server_socket.listen(5)
    c,addr = server_socket.accept()


    try:
        # Stepper Motor Controls
        A1 = GP.getPin23()    # blue
        A2 = GP.getPin24()    # pink
        B1 = GP.getPin25()    # yellow
        B2 = GP.getPin26()    # orange

        A1.out()
        A2.out()
        B1.out()
        B2.out()

        # Delay time 
コード例 #13
0
                Pin25.high()
                Pin25.low()
        elif place_name == 'c':
            for x in range(0, 140):
                Pin25.high()
                Pin25.low()
        elif place_name == 'd':
            for x in range(0, 180):
                Pin25.high()
                Pin25.low()

        return True

    def on_error(self, status):
        print(status)

if __name__ == '__main__':
    try:
        l = StdOutListener()
        auth = OAuthHandler(consumer_key, consumer_secret)
        auth.set_access_token(access_token, access_secret)

        GP = GPIOProcessor()

        stream = Stream(auth, l)
        # stream.filter(track=hash_tags)
        stream.filter(follow=users)

    finally:
        GP.cleanup()
コード例 #14
0
from GPIOLibrary import GPIOProcessor
import time
import math

GP = GPIOProcessor()

# GPIO assignment
# TRIG      Pin 23
# ECHO      Pin 27
# GREEN     Pin 24
# YELLOW    Pin 25
# RED       Pin 26

try:
    
    # Create GPIO variables
    trig    = GP.getPin34()
    echo    = GP.getPin27()
    green   = GP.getPin24()
    yellow  = GP.getPin25()
    red     = GP.getPin26()

    trig.out()
    echo.input()
    green.out()
    yellow.out()
    red.out()

    # Duration of Activation (seconds)
    D = 10 
コード例 #15
0
from GPIOLibrary import GPIOProcessor
import time

GP = GPIOProcessor()

try:
    Pin25 = GP.getPin25()
    Pin25.out()

    for x in range(0, 60):
        Pin25.high()
        Pin25.low()

finally:
    GP.cleanup()

コード例 #16
0
class UltrasonicHCSR04:
    """
    Sensor Class maps DragonBoard 410c GPIO pins for Debian to the HC-SR04 ultra-sonic sensor.

    Approximate Speed of Sound through Air at 20 degrees centigrade
    343 metres per second.

    For "Shallow Water Sensor"
    Approximate Speed of Sound through Water at 15 degrees centigrade
    1464 metres per second.
    """

    def __init__(self):
        self.speed = 343  # metres per second (m/s) through Air
        # self.speed = 1464  # metres per second (m/s) through Water
        self.depth = 0

        """
        Trig (blue wire) : Pin 33 -> OpAmp Node 2 -> Ultra-sonic sensor Trig
        Echo (red wire) : Ultra-sonic sensor Echo -> Pin 30
        """
        self.gp = GPIOProcessor()

        self.trig = self.gp.getPin33()
        self.echo = self.gp.getPin34()

        self.trig.out()
        self.echo.input()

    def get_depth(self):
        return self.depth

    def set_depth(self, new_depth):
        self.depth = new_depth

    def check_depth(self):
        """
        Activate the sensor to send sound ping (Trig) and receive the echo (Echo) underwater,
        measuring the time interval and calculating and storing the value in depth.
        """
        try:
            print "Activating Shallow Water Sensor ..."
            self.trig.low()
            # time.sleep(0.000002)  # at least 2 micro-seconds
            time.sleep(0.5)  # At least 2 micro-seconds. 0.5 tested and working.
            self.trig.high()
            time.sleep(0.0001)  # At least 5 micro-seconds. 100 tested and working.
            self.trig.low()
            print "Pulse sent."

            # defining variables
            pulse_start = time.time()
            pulse_end = time.time()

            # Wait for pulse to be sent, then
            # save start time.
            # Note : Adding counter to break while loop due to weird glitch.
            counter = 10000
            while self.echo.getValue() == 0 and counter > 0:
                pulse_start = time.time()
                counter -= 1
                #  print "counter :", counter

            if self.echo.getValue() == 1:
                print "Received echo."
                while self.echo.getValue() == 1:
                    pulse_end = time.time()

            if counter == 0:
                print "No echo received for long period. Return to Manager and start again."
                self.set_depth(0)
                return False

            # Calculate total pulse duration
            # print "pulse_end time :", pulse_end
            # print "pulse_start time : ", pulse_start
            pulse_duration = pulse_end - pulse_start
            # print "pulse_duration time :", pulse_duration

            # Use pulse duration to calculate distance
            # Remember that the pulse has to go there and come back
            distance = round((pulse_duration * self.speed) / 2, 2)
            # print "distance :", distance
            self.set_depth(distance)
            return True
        except KeyboardInterrupt():
            print "Keyboard interrupt received. Cleaning up ..."
            self.gp.cleanup()
            return False
コード例 #17
0
from GPIOLibrary import GPIOProcessor
import time
import math

GP = GPIOProcessor()

try:
    # Stepper Motor Controls
    A1 = GP.getPin34()    # Green
    A2 = GP.getPin24()    # Black
    B1 = GP.getPin33()    # White
    B2 = GP.getPin26()    # Yellow

    A1.out()
    A2.out()
    B1.out()
    B2.out()

    # Delay time 
    T = 0.001

    # Stepper Sequence (Forward ; Reverse)
    SS = [[[0,1,0,1],[1,0,0,1],[1,0,1,0],[0,1,1,0]],
         [[0,1,0,1],[0,1,1,0],[1,0,1,0],[1,0,0,1]]]

    # Forward/Reverse Indicator (0 - Forward, 1 - Reverse)
    FR = 0

    # Step Angle
    SA = 1.8    # 1.8 degrees per step
    
コード例 #18
0
class StepperMotor:
    # Stepper motor switching sequence
    seq = [[1, 0, 0, 0], [1, 1, 0, 0], [0, 1, 0, 0], [0, 1, 1, 0],
           [0, 0, 1, 0], [0, 0, 1, 1], [0, 0, 0, 1], [1, 0, 0, 1]]

    def __init__(self, pin1=24, pin2=28, pin3=25, pin4=33):
        """Initialize the interface passing the four GPIO pins
           to connect to.  Be sure to subtract 902 from the pin
           out diagram.  For example, GPIO pin 29 corresponds to 
           pin out 926.  To use this pin pass 926-902 or 24
        """
        self.GP = GPIOProcessor()
        self.pin1 = self.GP.getPin(pin1)
        self.pin2 = self.GP.getPin(pin2)
        self.pin3 = self.GP.getPin(pin3)
        self.pin4 = self.GP.getPin(pin4)
        self.pinl = [self.pin1, self.pin2, self.pin3, self.pin4]

        for k in range(4):
            self.pinl[k].out()

        self.speed = 100.0

    @property
    def speed(self):
        return self.__speed

    @speed.setter
    def speed(self, speed):
        if speed < 0:
            self.__speed = 0.0
        elif speed > 100:
            self.__speed = 100.0
        else:
            self.__speed = float(speed)

    def cleanup(self):
        """cleanup must be the last call to the class so that all
           GPIO pins are properly released.
        """
        self.GP.cleanup()

    def move(self, degrees=360):
        """Move the stepper motor shaft dgrees.  If degrees is negative
           the shaft will spin in reverse.
        """
        pinl = list(self.pinl)
        if degrees < 0:
            pinl.reverse()
            degrees = abs(degrees)

        steps_per_deg = 4076.0 / 360.0
        steps = int(steps_per_deg * degrees)

        delay = 0.03 / self.speed

        for k in range(steps):
            seq_inx = k % 8
            # print("seq_inx= {0:2d}".format(seq_inx))
            for j in range(4):
                # print("\t Pin= {0:d}".format(j))
                # print("\t Value= {0:d}".format(StepperMotor.seq[seq_inx][j]))
                pinl[j].setValue(StepperMotor.seq[seq_inx][j])
                time.sleep(delay)
コード例 #19
0
ファイル: blink_led.py プロジェクト: yathinosaur/RedBrick
from GPIOLibrary import GPIOProcessor
import time
import requests
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.retry import Retry

session = requests.Session()
retry = Retry(connect=3, backoff_factor=0.5)
adapter = HTTPAdapter(max_retries=retry)
session.mount('http://', adapter)

session.get(url)

GP = GPIOProcessor()

r2 = requests.post('http://129.21.70.129:8081/newId', json = {
		"id": "mason",
		"blood_pressure": "100",
		"histamine_concentration": "1",
		"core_body_temperature": "36",
		"safe": "true"
	})

try:
    Pin29 = GP.getPin29()
    Pin29.input()

    Pin31 = GP.getPin31()
    Pin31.input()	

    Pin33 = GP.getPin33()
コード例 #20
0
from GPIOLibrary import GPIOProcessor
import time

GP = GPIOProcessor()

try:
    Pin23 = GP.getPin23()
    Pin23.out()

    Pin25 = GP.getPin25()
    Pin25.out()

    Pin27 = GP.getPin27()
    Pin27.out()

    Pin31 = GP.getPin31()
    Pin31.out()

    print("Pins are set to output")

    for i in range(0, 20):
        if Pin23.getValue() == 1:
            Pin23.low()
            Pin25.high()
        elif Pin25.getValue() == 1:
            Pin25.low()
            Pin27.high()
        elif Pin27.getValue() == 1:
            Pin27.low()
            Pin31.high()
        elif Pin31.getValue() == 1:
コード例 #21
0
"""
    Script to control the DCMotor based on the ShallowWaterSensor readings.
"""
import time

from GPIOLibrary import GPIOProcessor

from Sensor import UltrasonicHCSR04
from Motor import DC

gp = GPIOProcessor()
sws = UltrasonicHCSR04()  # Shallow Water Sensor
prop = DC()  # propeller

try:
    print "Paddle Scoot starting up ..."
    #  ========================
    #  Just prop spinning for testing. No Shallow Water Sensor.
    #  ========================
    #  prop.stop_motor()
    #  prop.start_motor()
    #  print "prop spinning? : ", prop.isPropSpinning
    #
    #  ========================
    #  Uncomment when ultrasonic sensor is fixed.
    #  ========================
    #    isSwsActive = sws.check_depth()
    #    prop.stop_motor()

    #    if isSwsActive and not prop.isPropSpinning:
    #        print "Sensor activated successfully and motor stopped."
コード例 #22
0
class StepperMotor:
    # Stepper motor switching sequence
    seq = [[1,0,0,0], [1,1,0,0], [0,1,0,0], [0,1,1,0],
           [0,0,1,0], [0,0,1,1], [0,0,0,1], [1,0,0,1]]

    def __init__(self, pin1=24, pin2=28, pin3=25, pin4=33):
        """Initialize the interface passing the four GPIO pins
           to connect to.  Be sure to subtract 902 from the pin
           out diagram.  For example, GPIO pin 29 corresponds to 
           pin out 926.  To use this pin pass 926-902 or 24
        """
        self.GP = GPIOProcessor()
        self.pin1 = self.GP.getPin(pin1)
        self.pin2 = self.GP.getPin(pin2)
        self.pin3 = self.GP.getPin(pin3)
        self.pin4 = self.GP.getPin(pin4)
        self.pinl = [self.pin1, self.pin2, self.pin3, self.pin4]

        for k in range(4):
            self.pinl[k].out()

        self.speed = 100.0

    @property
    def speed(self):
        return self.__speed

    @speed.setter
    def speed(self,speed):
        if speed < 0:
            self.__speed = 0.0
        elif speed > 100:
            self.__speed = 100.0
        else:
            self.__speed = float(speed)


    def cleanup(self):
        """cleanup must be the last call to the class so that all
           GPIO pins are properly released.
        """
        self.GP.cleanup()

    def move(self, degrees=360):
        """Move the stepper motor shaft dgrees.  If degrees is negative
           the shaft will spin in reverse.
        """
        pinl = list(self.pinl)
        if degrees < 0:
            pinl.reverse()
            degrees = abs(degrees)

        steps_per_deg =4076.0/360.0
        steps = int(steps_per_deg * degrees)

        delay = 0.03 / self.speed

        for k in range(steps):
            seq_inx = k % 8
            # print("seq_inx= {0:2d}".format(seq_inx))
            for j in range(4):
                # print("\t Pin= {0:d}".format(j))
                # print("\t Value= {0:d}".format(StepperMotor.seq[seq_inx][j]))
                pinl[j].setValue(StepperMotor.seq[seq_inx][j])
                time.sleep(delay)
コード例 #23
0
from GPIOLibrary import GPIOProcessor
import time
import math

# DB410c GPIO pin list
outl = []

# Stepper motor switching sequence
seq = [[1,0,0,0], [1,1,0,0], [0,1,0,0], [0,1,1,0],
       [0,0,1,0], [0,0,1,1], [0,0,0,1], [1,0,0,1]]

stepAngle = 5.625
delay = 0.0003
#delay = 1

GP = GPIOProcessor()

try:
    # Use pins 231, 33, 30, and 34 to control motor
    out0 = GP.getPin29()  # Blue
    out1 = GP.getPin33()  # Pink
    out2 = GP.getPin30()  # Yellow
    out3 = GP.getPin34()  # Orange

    outl = [out0, out1, out2, out3]
    outl.reverse()

    # Set the pin direction to out
    for k in range(4):
        outl[k].out()
コード例 #24
0
from GPIOLibrary import GPIOProcessor
import time

GP = GPIOProcessor()

# GPIO Assignments
#Din    = 27
#A1     = 34	Green
#A2     = 33	White
#A3     = 24   	Black
#A4     = 26	Yellow
#PIR    = 29
#Ind    = 30

Din = GP.getPin27()
Din.input()
A1 = GP.getPin34()
A1.out()
A2 = GP.getPin33()
A2.out()
A3 = GP.getPin24()
A3.out()
A4 = GP.getPin26()
A4.out()
PIR = GP.getPin29()
PIR.out()
PIR.low()
Ind = GP.getPin30()
Ind.out()
Ind.low()
コード例 #25
0
ファイル: ir_sensor.py プロジェクト: jpmunz/gpio
from GPIOLibrary import GPIOProcessor
import time

GP = GPIOProcessor()

try:
    pin = GP.getPin33()
    pin.input()

    while True:

        timeout = time.time() + 5
        count = 0
        count2 = 0
        while True:
            if pin.getValue() == 0:
                count += 1
            if pin.getValue() == 1:
                count2 += 1
            if time.time() > timeout:
                break
        print "saw " + str(count) + " zeros"
        print "saw " + str(count2) + " ones"

finally:
    GP.cleanup()
コード例 #26
0
from GPIOLibrary import GPIOProcessor
import time
import numpy as np
GP = GPIOProcessor()

try:
    trig = GP.getPin29()
    trig.out()

    echo = GP.getPin30()
    echo.input()

    trig.low()
    print("Wait for sensor to settle")
    time.sleep(2)
    distances = []
    for i in range(15):
        pulseStart = 0
        pulseEnd = 0
        isOutR = False
        init = time.clock()
        trig.high()
        time.sleep(0.00001)
        trig.low()
        while (echo.getValue() == 0):
            pulseStart = time.clock()
            if (pulseStart - init > 0.3):
                print("out of range")
                isOutR = True
                break
        pulseEnd = time.clock()
コード例 #27
0
from GPIOLibrary import GPIOProcessor
import time

GP = GPIOProcessor()

try:

    # Set up GPIO
    vcc = GP.getPin34()
    vcc.out()

    while True:
        print 'Turn on? [y/n]'
        r = raw_input()
        if r == 'y':
            vcc.high()

            # Sensor is on
            print 'Sensor is on.'
            print 'Exit? [y]'
            r = raw_input()
            if r == 'y':
                vcc.low()

        else:
            break

finally:
    GP.cleanup()
コード例 #28
0
from GPIOLibrary import GPIOProcessor
import time
import math

GP = GPIOProcessor()

try:
    # Stepper Motor Controls
    A1 = GP.getPin34()  # Green
    A2 = GP.getPin24()  # Black
    B1 = GP.getPin33()  # White
    B2 = GP.getPin26()  # Yellow

    A1.out()
    A2.out()
    B1.out()
    B2.out()

    # Delay time
    T = 0.001

    # Stepper Sequence (Forward ; Reverse)
    SS = [[[0, 1, 0, 1], [1, 0, 0, 1], [1, 0, 1, 0], [0, 1, 1, 0]],
          [[0, 1, 0, 1], [0, 1, 1, 0], [1, 0, 1, 0], [1, 0, 0, 1]]]

    # Forward/Reverse Indicator (0 - Forward, 1 - Reverse)
    FR = 0

    # Step Angle
    SA = 1.8  # 1.8 degrees per step
コード例 #29
0
from GPIOLibrary import GPIOProcessor
import time
import math

# DB410c GPIO pin list
outl = []

# Stepper motor switching sequence
seq = [[1, 0, 0, 0], [1, 1, 0, 0], [0, 1, 0, 0], [0, 1, 1, 0], [0, 0, 1, 0],
       [0, 0, 1, 1], [0, 0, 0, 1], [1, 0, 0, 1]]

stepAngle = 5.625
delay = 0.0003
#delay = 1

GP = GPIOProcessor()

try:
    # Use pins 231, 33, 30, and 34 to control motor
    out0 = GP.getPin29()  # Blue
    out1 = GP.getPin33()  # Pink
    out2 = GP.getPin30()  # Yellow
    out3 = GP.getPin34()  # Orange

    outl = [out0, out1, out2, out3]
    outl.reverse()

    # Set the pin direction to out
    for k in range(4):
        outl[k].out()
コード例 #30
0
ファイル: main.py プロジェクト: ForTheYin/coffee-client
import requests, time, json, giphy_client, webbrowser
from giphy_client.rest import ApiException
from pprint import pprint
from GPIOLibrary import GPIOProcessor

URL = "https://be070769.ngrok.io/"
UUID = "123e4567-e89b-12d3-a456-426655440000"

GP = GPIOProcessor()

def main():
    # get_gif()
    current_state = {"brew_button": None, "temperature": None, "strength_button": None}
    while True:
        time.sleep(5)
        actions = get_latest()
        print(actions)
        actions_performed = []
        for item in actions:
            execute_action(item, actions_performed, current_state)
        post_actions(actions_performed, current_state)

def execute_action(item, actions_performed, current_state):
    if (item['action'] == "brew"):
        item['status'] = "completed" if brewCoffee() else "failed"
        current_state['brew_button'] = "brewing"
    elif (item['action'] == "switch_brew"):
        item['status'] = "completed" if setStrongMode() else "failed"
        current_state['strength_button'] = "strong" if current_state['strength_button'] == "regular" else "regular"
    
    actions_performed.append(item)
コード例 #31
0
from GPIOLibrary import GPIOProcessor
import time

GP = GPIOProcessor()

try:

    # Set up GPIO
    vcc = GP.getPin34()
    vcc.out()

    while True:
        print 'Turn on? [y/n]'
        r = raw_input()
        if r == 'y':
            vcc.high()
            
            # Sensor is on
            print 'Sensor is on.'
            print 'Exit? [y]'
            r = raw_input()
            if r == 'y':
                vcc.low()
            
        else:
            break

finally:
    GP.cleanup()
コード例 #32
0
ファイル: blink_led.py プロジェクト: harrysedev/HackGSU18
from GPIOLibrary import GPIOProcessor
import time

GP = GPIOProcessor()

try:
    Pin27 = GP.getPin27()
    Pin27.out()

    Pin29 = GP.getPin29()
    Pin29.input()	

    for i in range(0,20):
        pinValue = Pin29.getValue();
	
	if pinValue == 1:
	    Pin27.high()
        else:
            Pin27.low()
        time.sleep(1)

finally:
    GP.cleanup()
コード例 #33
0
ファイル: radio_receiver.py プロジェクト: jpmunz/gpio
import csv
from datetime import datetime
from GPIOLibrary import GPIOProcessor
import time

GP = GPIOProcessor()

MAX_DURATION = 120
received = [[], []]

try:
    receiverPin = GP.getPin33()
    receiverPin.out()
    start = datetime.now()
    running_time = 0

    while running_time < MAX_DURATION:
        time_delta = datetime.now() - start
        received[0].append(time_delta)
        received[1].append(receiverPin.getValue())
        running_time = time_delta.seconds

    for i in range(len(received[0])):
        received[0][i] = received[0][
            i].seconds + received[0][i].microseconds / 1000000.0

    with open('receiver_result.csv', 'wb') as csvfile:
        writer = csv.writer(csvfile,
                            delimiter=' ',
                            quotechar='|',
                            quoting=csv.QUOTE_MINIMAL)
コード例 #34
0
ファイル: stepper_motor.py プロジェクト: jpmunz/gpio
import csv
from datetime import datetime
import matplotlib.pyplot as pyplot
from GPIOLibrary import GPIOProcessor
import time

GP = GPIOProcessor()

# https://www.youtube.com/watch?v=B86nqDRskVU

DELAY = 0.001

WAVE_SEQUENCE = [
    [1, 0, 0, 0],
    [0, 1, 0, 0],
    [0, 0, 1, 0],
    [0, 0, 0, 1],
]

FULL_STEP_SEQUENCE = [
    [1, 1, 0, 0],
    [0, 1, 1, 0],
    [0, 0, 1, 1],
    [1, 0, 0, 1],
]

try:
    steps_made = 0

    pins = [
        GP.getPin31(),
コード例 #35
0
from GPIOLibrary import GPIOProcessor
import time

GP = GPIOProcessor()

# GPIO Assignments
#Din    = 27
#A1     = 34	Green
#A2     = 33	White
#A3     = 24   	Black
#A4     = 26	Yellow
#PIR    = 29
#Ind    = 30

Din = GP.getPin27()
Din.input()
A1 = GP.getPin34()
A1.out()
A2 = GP.getPin33()
A2.out()
A3 = GP.getPin24()
A3.out()
A4 = GP.getPin26()
A4.out()
PIR = GP.getPin29()
PIR.out()
PIR.low()
Ind = GP.getPin30()
Ind.out()
Ind.low()