Example #1
0
def direction(d):
    """	Set direction of data.  Either rx or tx"""

    if not disableDirPin:
        GPIO.output(directionPin, d)  # set the pin
        # time.sleep(0.000050)	# sleep for 50uS to allow things to settle.  Decreases checksum errors
        time.sleep(0.0005)
    def __init__(self, pin_rs=25, pin_e=24, pins_db=[23, 17, 21, 22], GPIO=None):
        # Emulate the old behavior of using RPi.GPIO if we haven't been given
        # an explicit GPIO interface to use
        if not GPIO:
            import RPi.GPIO as GPIO
        GPIO.setwarnings(False)
        self.GPIO = GPIO
        self.pin_rs = pin_rs
        self.pin_e = pin_e
        self.pins_db = pins_db

        self.GPIO.setmode(GPIO.BCM)
        self.GPIO.setup(self.pin_e, GPIO.OUT)
        self.GPIO.setup(self.pin_rs, GPIO.OUT)

        for pin in self.pins_db:
            self.GPIO.setup(pin, GPIO.OUT)

        self.write4bits(0x33)  # initialization
        self.write4bits(0x32)  # initialization
        self.write4bits(0x28)  # 2 line 5x7 matrix
        self.write4bits(0x0C)  # turn cursor off 0x0E to enable cursor
        self.write4bits(0x06)  # shift cursor right

        self.displaycontrol = self.LCD_DISPLAYON | self.LCD_CURSOROFF | self.LCD_BLINKOFF

        self.displayfunction = self.LCD_4BITMODE | self.LCD_1LINE | self.LCD_5x8DOTS
        self.displayfunction |= self.LCD_2LINE

        """ Initialize to default text direction (for romance languages) """
        self.displaymode = self.LCD_ENTRYLEFT | self.LCD_ENTRYSHIFTDECREMENT
        self.write4bits(self.LCD_ENTRYMODESET | self.displaymode)  #  set the entry mode

        self.clear()
Example #3
0
 def data(self, value):
     global gpio
     global spi
     # send value
     gpio.output(self._DC, True)
     spi.xfer2(list(value))
     gpio.output(self._DC, False)
Example #4
0
def set_value(value):
    for i in range(8):
        bitwise = 0x80 >> i
        val = gpio.HIGH if bitwise & value else gpio.LOW
        gpio.output(ds, val)
        tick(clock)
    tick(latch)
def lcd_toggle_enable():
    # Toggle enable
    time.sleep(E_DELAY)
    GPIO.output(LCD_E, True)
    time.sleep(E_PULSE)
    GPIO.output(LCD_E, False)
    time.sleep(E_DELAY)
Example #6
0
def pivot_left(tf):
    gpio.output(7, True)
    gpio.output(11, False)
    gpio.output(13, True)
    gpio.output(15, False)
    time.sleep(tf)
    gpio.cleanup()
Example #7
0
def turn_rightback(tf):
    gpio.output(7, True)
    gpio.output(11, False)
    gpio.output(13, False)
    gpio.output(15, False)
    time.sleep(tf)
    gpio.cleanup()
Example #8
0
File: motion.py Project: lycying/p
 def __init__(self):
     Thread.__init__(self)
     if not none_pi:
         io.setmode(io.BCM)
         io.setup(PIR_PIN, io.IN)
     self.stop = False
     self.trigger = False
def GPIOoutput(Pin, ins):
    print "set pin ", Pin, " ", ins
    InversePins = {lsBluePin, lsGreenPin, lsRedPin, bGreenPin, bRedPin}
    if Pin in InversePins:
        GPIO.output(Pin, ins == 0 or ins == False)
    else:
        GPIO.output(Pin, ins)
Example #10
0
 def ledFail(self, led, interval):
     self.ledAllOff()
     for i in xrange(0, 15):
         GPIO.output(led, GPIO.HIGH)
         time.sleep(interval)
         GPIO.output(led, GPIO.LOW)
         time.sleep(interval)
Example #11
0
def screenSaver():
    global ssaverTime

    lcd.clear()
    lcd.noDisplay()
    GPIO.output(ledBacklight, True)

    collected = gc.collect()

    while 1:
        readButtons()

        if (
            (buttons["btnUp"] == False)
            or (buttons["btnDown"] == False)
            or (buttons["btnBack"] == False)
            or (buttons["btnSelect"] == False)
        ):
            lcd.display()
            GPIO.output(ledBacklight, False)

            ssaverTime = 0
            return

        sleep(MICRO_DELAY)
Example #12
0
 def ledBlink(self, led, interval):
     self.ledAllOff()
     while True:
         GPIO.output(led, GPIO.HIGH)
         time.sleep(interval)
         GPIO.output(led, GPIO.LOW)
         time.sleep(interval)
Example #13
0
File: loop.py Project: quatrix/rekt
    def on_pedal_change(self, channel):
        time.sleep(0.02)

        if not GPIO.input(channel):
            return

        if self.last_pedal_press is not None and time.time() - self.last_pedal_press < 0.2:
            return

        logging.info("pedal change: %d", channel)

        t0 = time.time()

        while GPIO.input(channel):
            self.last_pedal_press = time.time()

            if self.last_pedal_press - t0 > hold_time:
                break

            time.sleep(0.01)

        if time.time() - t0 > hold_time:
            self.toggle_rec()
        elif self.recording:
            self.set_mark(pedal_id=0)

        self.last_pedal_press = time.time()
Example #14
0
def getStatusInfo():
    result = []
    left = 0
    right = 0
    # retrieves status of lights:
    lights = GPIO.input(11)
    eyes = GPIO.input(13)
    # retrieves status of motors
    if not sim:
        left = PBR.GetMotor1()
        right = PBR.GetMotor2()
    result = json.dumps(
        {"type": "status", "command": "update", "left": left, "right": right, "lights": lights, "eyes": eyes},
        skipkeys=False,
        ensure_ascii=True,
        check_circular=True,
        allow_nan=True,
        cls=None,
        indent=None,
        separators=(",", ": "),
        encoding="utf-8",
        default=None,
        sort_keys=False,
    )
    return result
Example #15
0
def forward(tf):
    gpio.output(7, False)
    gpio.output(11, True)
    gpio.output(13, True)
    gpio.output(15, False)
    time.sleep(tf)
    gpio.cleanup()
Example #16
0
File: main.py Project: N07070/PyCar
def initiate_motors():
    gpio.setmode(gpio.BOARD)

    gpio.setup(7, gpio.OUT)
    gpio.setup(11, gpio.OUT)
    gpio.setup(13, gpio.OUT)
    gpio.setup(15, gpio.OUT)
Example #17
0
def reverse(tf):
    gpio.output(7, True)
    gpio.output(11, False)
    gpio.output(13, False)
    gpio.output(15, True)
    time.sleep(tf)
    gpio.cleanup()
def Sonar(trigger, echo):
    dist_list = []
    for i in range(5):
        GPIO.setup(trigger, GPIO.OUT)
        GPIO.output(trigger, True)
        time.sleep(0.00001)
        GPIO.output(trigger, False)
        start = time.time()
        count = time.time()
        GPIO.setup(echo, GPIO.IN)
        while GPIO.input(echo) == 0 and time.time() - count < 0.1:
            start = time.time()
        stop = time.time()
        while GPIO.input(echo) == 1:
            stop = time.time()
        # Calculate pulse length
        elapsed = stop - start
        # Distance pulse travelled in that time is time
        # multiplied by the speed of sound (cm/s)
        distance = elapsed * 34000
        # That was the distance there and back so halve the value
        distance = distance / 2
        dist_list = dist_list + [distance]
        time.sleep(0.01)
    sorted_list = sorted(dist_list)
    return sorted_list[2]
Example #19
0
def pivot_right(tf):
    gpio.output(7, False)
    gpio.output(11, True)
    gpio.output(13, False)
    gpio.output(15, True)
    time.sleep(tf)
    gpio.cleanup()
Example #20
0
def send(module, value):
    # to do : evaluate using bitwise operations to make this faster?
    #if moduleMap_d == False:
    #    print "You must run init() before using this module"
    #    return False
    # make with the bit stuffing
    module_bin_str = dec2bin(module, 6)
    value_bin_str = dec2bin(value, 16)
    word1_str = value_bin_str[11:16] + module_bin_str + "0"
    word2_str = value_bin_str[0:11] + "1"
    print "duplexPort.py | send |", module, value
    for i in range(12):
        pin = PINS_OUT[i]
        val = int(word1_str[i])
        #print pin, val
        GPIO.output(pin,val)

    #time.sleep(.1)
    #p = read()
    #time.sleep(.1)
    for i in range(12):
        pin = PINS_OUT[i]
        val = int(word2_str[i])
        #print pin, val
        GPIO.output(pin,val)
Example #21
0
    def controlLED(self, ledState):
        """turns off or on a LED.
		The LED is pulled up to Vcc so it needs to be driven low to turn the LED on.

		:param ledState: True to turn the light on, false to turn light off
		"""
        GPIO.output(LED_PIN, not ledState)
Example #22
0
def sonar():
    while finished != True:
        global globalstop
        GPIO_TRIGGER = 8
        GPIO_ECHO = 8
        GPIO.setup(8, GPIO.OUT)
        # Send 10us pulse to trigger
        GPIO.output(GPIO_TRIGGER, True)
        time.sleep(0.00001)
        GPIO.output(GPIO_TRIGGER, False)
        start = time.time()
        count = time.time()
        GPIO.setup(8, GPIO.IN)
        while GPIO.input(GPIO_ECHO) == 0 and time.time() - count < 0.1:
            start = time.time()
        stop = time.time()
        while GPIO.input(GPIO_ECHO) == 1:
            stop = time.time()
        # Calculate pulse length
        elapsed = stop - start
        # Distance pulse travelled in that time is time
        # multiplied by the speed of sound (cm/s)
        distance = elapsed * 34000
        # That was the distance there and back so halve the value
        distance = distance / 2
        if distance < 20:
            globalstop = 1
            print("Too close")
        else:
            globalstop = 0
            print("Far")
        time.sleep(1)
Example #23
0
 def __init__(self, channel, led_pin, f):
     self.channel = channel
     self.f = f
     self.led_pin = led_pin
     self.p = Process(target=self.target_f)
     GPIO.setup(self.channel, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
     GPIO.setup(self.led_pin, GPIO.OUT, initial=GPIO.LOW)
Example #24
0
 def __init__(self, lm1, lm2, rm1, rm2):
     self.status = "x"
     self.leftMotor = [lm1, lm2]
     self.rightMotor = [rm1, rm2]
     self.motors = self.leftMotor + self.rightMotor
     GPIO.setup(self.motors, GPIO.OUT)
     self.stop()
Example #25
0
 def init(self):
     # CS Chip Select low
     GPIO.output(self.cs, GPIO.LOW)
     # Reset
     self.reset()
     # LCD bias select
     self.send_command([self.CMD_SET_BIAS_7])
     # ADC select
     self.send_command([self.CMD_SET_ADC_NORMAL])
     # SHL select
     self.send_command([self.CMD_SET_COM_NORMAL])
     # Initial display line
     self.send_command([self.CMD_SET_DISP_START_LINE])
     # Turn on voltage converter (VC=1, VR=0, VF=0)
     self.send_command([self.CMD_SET_POWER_CONTROL | 0x4])
     sleep(0.05)
     # Turn on voltage regulator (VC=1, VR=1, VF=0)
     self.send_command([self.CMD_SET_POWER_CONTROL | 0x6])
     sleep(0.05)
     # Turn on voltage follower (VC=1, VR=1, VF=1)
     self.send_command([self.CMD_SET_POWER_CONTROL | 0x7])
     sleep(0.01)
     # Set lcd operating voltage (regulator resistor, ref voltage resistor)
     self.send_command([self.CMD_SET_RESISTOR_RATIO | 0x7])
     # Turn on display
     self.send_command([self.CMD_DISPLAY_ON])
     # Display all points
     self.send_command([self.CMD_SET_ALLPTS_NORMAL])
     # Contrast
     self.set_contrast(self.LCD_CONTRAST)
     # Clear display
     self.clear_display()
Example #26
0
 def loop(self):
     while True:
         for i in range(3):
             self.active = self.pins[::2][i]
             GPIO.output(self.active, True)
             sleep(0.01)
             GPIO.output(self.active, False)
Example #27
0
    def __init__(self):
        gpio.setmode(gpio.BOARD)

        self.right_wheel = Wheel(11, 12, 16, 18)
        self.left_wheel = Wheel(13, 15, 29, 31)

        print("move initiated")
Example #28
0
def main():
	a=random.randint(1,10)	
	preguntas()
	res=respuestas()		

	while True:
		if(GPIO.input(7)):
			if(res==1):
				print "\nCorrecto! :)"
			if(res!=1): 
				print "\nError :o"
			main()

		if(GPIO.input(8)):
			if(res==2):
				print "\nCorrecto! :)"
			if(res!=2)
				print "\nError :o"
			main()
		if(GPIO.input(9)):
			if(res==3):
				print "\nCorrecto! :)"
			if(res!=3) 
				print "\nError :o"
			time.sleep(5)
			clear_output()
			main()		
Example #29
0
def setup_input_pin(pin, resistor=None):
    """
    Setup an input pin.

    Setup pin for input and optionally configure a pull up or pull down
    resistor. `set_pin_mode` must be called first.

    Args:
        pin (int): number of pin to setup for input
        resistor (str): how to configure the internal resistor for the pin.
            Allowable values:
                - `pull_up`: enable pull up resistor
                - `pull down`: enable pull down resistor
                - `float`: do not enable resistor
                - `None`: same as `float`
    """
    if resistor == "pull_up":
        pull_up_down = GPIO.PUD_UP
    elif resistor == "pull_down":
        pull_up_down = GPIO.PUD_DOWN
    elif resistor == "float" or resistor is None:
        pull_up_down = GPIO.PUD_OFF
    else:
        raise ValueError("invalid resistor setting {}".format(resistor))

    GPIO.setup(pin, GPIO.IN, pull_up_down=pull_up_down)
Example #30
0
 def __init__(self):
     # My Servo pins
     GPIO.setmode(GPIO.BOARD)  ## Use board pin numbering
     GPIO.setwarnings(False)
     self.servoX = 0  # pan servo
     self.servoY = 3  # tilt servo
     # self.Motor1A = 21
     # self.ser = serial.Serial('/dev/ttyACM0', 9600)
     self.driver = driver.MyDriverWrapper.ServoDriver()
     # ===========
     self.center = [0.0, 0.0]  # where to recenter
     self.fps = 1.5  # frame per seconds  *** movement is wild if set too high ***
     self.stepsleep = 0.05  # time per step (smoothness)
     self.firesensitivity = 0.02  # how trigger happy
     self.triggerwait = 3  # seconds between fire/reload
     # variables
     self.triggertimer = threading.Event()
     self.armed = False  # will fire
     self.xy = self.center[:]  # current xy
     self.deltaxy = [0.0, 0.0]  # current move
     self.deltaxylast = [0.0, 0.0]  # prior move
     self.stepxy = [0.0, 0.0]  # xy per step
     self.steps = (1.0 / self.fps) / self.stepsleep  # steps per frame
     self.stepcounter = 0  # motion step counter
     threading.Thread.__init__(self)