Example #1
0
try:
  GPIO.output(21, GPIO.LOW)
  print "ONE"
  time.sleep(SleepTimeL); 
  GPIO.output(23, GPIO.LOW)
  print "TWO"
  time.sleep(SleepTimeL);  
  GPIO.output(24, GPIO.LOW)
  print "THREE"
  time.sleep(SleepTimeL);
  GPIO.output(25, GPIO.LOW)
  print "FOUR"
  time.sleep(SleepTimeL);
  GPIO.cleanup()
  print "Good bye!"

# End program cleanly with keyboard
except KeyboardInterrupt:
  print "  Quit"
  # Reset GPIO settings
  GPIO.cleanup()

for i in pinList: 
    GPIO.close(i);
    print str(i)+" closed\n"
    
    

# find more information on this script at
# http://youtu.be/WpM1aq4B8-A
Example #2
0
File: lcd.py Project: aks11/rpi
    wstring("+                  +")

    wbyte(LINE4, CMD)
    wstring("++++++++++++++++++++")

    tgl = 0
    while True:
        time.sleep(1)

        if tgl == 0:
            tgl = 1

            wbyte(LINE2, CMD)
            wstring("+ THIS IS LCD TEST +")

            wbyte(LINE3, CMD)
            wstring("+                  +")
        else:
            tgl = 0

            wbyte(LINE2, CMD)
            wstring("+                  +")

            wbyte(LINE3, CMD)
            wstring("+ THIS IS LCD TEST +")


if __name__ == "__main__":
    main()
    GPIO.close()
Example #3
0
 def close(self):
     GPIO.close()
     super(RPiGPIO, self).close()
Example #4
0
 def close(self):
     GPIO.close()
     super(RPiGPIO, self).close()
 def close(self):
     GPIO.close()
     print "exit"
Example #6
0
class SerialConnectionUpboard(object):
    """Wrap a serial.Serial connection and toggle reset and boot0."""

    # pylint: disable=too-many-instance-attributes

    def __init__(self,
                 serial_port,
                 baud_rate=115200,
                 parity="E",
                 gpio_reset_pin=int(18),
                 gpio_boot0_pin=int(17)):
        """Construct a SerialConnectionRpi (not yet connected)."""
        self.serial_port = serial_port
        self.baud_rate = baud_rate
        self.parity = parity
        self.can_toggle_reset = True
        self.can_toggle_boot0 = True
        self.reset_active_high = False
        self.boot0_active_low = False
        self.GPIO_DEV = '/dev/gpiochip4'

        # call connect() to establish connection
        self.serial_connection = None

        self._timeout = 5
        self._gpio_reset_pin = gpio_reset_pin
        self._gpio_boot0_pin = gpio_boot0_pin

        try:
            from periphery import GPIO
        except ImportError:
            print(
                "Couldn't import periphery.GPIO. Check if the periphery is installed on your system",
                file=sys.stderr)
            exit(1)
        try:
            self._reset = GPIO(self._gpio_reset_pin, "out")
            self._boot0 = GPIO(self._gpio_boot0_pin, "out")
        except IOError:
            print(
                "Couldn't initialise the periphery.GPIO instances. Try use the script with sudo.",
                file=sys.stderr)
            exit(1)

    @property
    def timeout(self):
        """Get timeout."""
        return self._timeout

    @timeout.setter
    def timeout(self, timeout):
        """Set timeout."""
        self._timeout = timeout
        self.serial_connection.timeout = timeout

    def connect(self):
        """Connect to the RS-232 serial port."""
        self.serial_connection = serial.Serial(
            port=self.serial_port,
            baudrate=self.baud_rate,
            # number of write_data bits
            bytesize=8,
            parity=self.parity,
            stopbits=1,
            # don't enable software flow control
            xonxoff=False,
            # don't enable RTS/CTS flow control
            rtscts=False,
            # set a timeout value, None for waiting forever
            timeout=self._timeout)
        if not self.serial_connection.is_open:
            self.serial_connection.open()
        if not self.serial_connection.is_open:
            raise IOError('Cannot open port "%s"' % self.serial_port)

    def clear_input_buffer(self):
        self.serial_connection.reset_input_buffer()

    def write(self, *args, **kwargs):
        """Write the given data to the serial connection."""
        return self.serial_connection.write(*args, **kwargs)

    def read(self, *args, **kwargs):
        """Read the given amount of bytes from the serial connection."""
        return self.serial_connection.read(*args, **kwargs)

    def enable_reset(self, enable=True):
        """Enable or disable the reset IO line."""
        # by default reset is active low

        if self.reset_active_high:
            level = (True if enable else False)  # active HIGH
        else:
            level = (False if enable else True)  # active LOW
        self._reset.write(level)

    def enable_boot0(self, enable=True):
        """Enable or disable the boot0 IO line."""
        # by default boot0 is active high

        if self.boot0_active_low:
            level = (False if enable else True)  # active LOW
        else:
            level = (True if enable else False)  # active HIGH
        self._boot0.write(level)

    def clean_gpio_pins(self):
        self._boot0.close()
        self._reset.close()