Exemplo n.º 1
0
    def stop(self):
        """Stop the component.

        """
        configs = len(self.values["pin"].get_index_configs())
        for config in range(configs):
            try:
                logger.debug("[%s] - stop GPIO Input component on pin %s", self.__class__.__name__, self.values["pin"].instances[config]['data'])
                GPIO.remove_event_detect(self.values["pin"].instances[config]['data'])
            except Exception:
                logger.exception("[%s] - Exception when stopping GPIO component", self.__class__.__name__)
        GpioComponent.stop(self)
        return True
Exemplo n.º 2
0
    def __init__(self, gpio_pin, low_temp=0, high_temp=100, history_samples=256, history_time=datetime.timedelta(minutes=5).total_seconds(), polltime=.25, onoff_wait=6):
        self.shutdown_requested = False
        self.gpio_pin = gpio_pin
        self.low_temp = low_temp
        self.high_temp = high_temp
        self.history_time = datetime.timedelta(seconds=history_time)
        self.history_samples = history_samples
        self.last_history_time = 0
        self.burn = False
        self.burn_start_time = 0
        self.burn_stop_time = 0
        self.burn_wait = False
        self.burn_deadband = False
        self.burn_total_secs = 0
        self.mode = MODES.OFF
        self.mode_time = time.time()
        self.poll_time = polltime
        self.onoff_wait = onoff_wait
        self.sense_lock = RLock()

        self.sense = Thermocouple.Thermocouple(spiDev=SPI.SpiDev(port=0, device=0), chip=0)
        self.food = Thermocouple.Thermocouple(spiDev=SPI.SpiDev(port=0, device=1), chip=1)

        self.sense_history = collections.deque([], maxlen=history_samples)
        self.sense_last = None
        self.food_history = collections.deque([], maxlen=history_samples)
        self.food_last = None

        self.logger = logging.getLogger("burner")

        self.gpio = GPIO.get_platform_gpio()
        self.gpio.setup(self.gpio_pin, GPIO.OUT)
        self.gpio.output(self.gpio_pin, True)
Exemplo n.º 3
0
	def __init__(self, width, height, rst, dc=None, sclk=None, din=None, cs=None, 
				 gpio=None, spi=None, i2c_bus=I2C.get_default_bus(), i2c_address=SSD1306_I2C_ADDRESS):
		self._log = logging.getLogger('Adafruit_SSD1306.SSD1306Base')
		self._spi = None
		self._i2c = None
		self.width = width
		self.height = height
		self._pages = height/8
		self._buffer = [0]*(width*self._pages)
		# Default to platform GPIO if not provided.
		self._gpio = gpio if gpio is not None else GPIO.get_platform_gpio()
		# Setup reset pin.
		self._rst = rst
		self._gpio.setup(self._rst, GPIO.OUT)
		# Handle hardware SPI
		if spi is not None:
			self._log.debug('Using hardware SPI')
			self._spi = spi
		# Handle software SPI
		elif sclk is not None and din is not None and cs is not None:
			self._log.debug('Using software SPI')
			self._spi = SPI.BitBang(self._gpio, sclk, din, None, cs)
		# Handle hardware I2C
		elif i2c_bus is not None:
			self._log.debug('Using hardware I2C')
			self._i2c = I2C.Device(i2c_address, i2c_bus)
		else:
			raise ValueError('Unable to determine if using SPI or I2C.')
		# Initialize DC pin if using SPI.
		if self._spi is not None:
			if dc is None:
				raise ValueError('DC pin must be provided when using SPI.')
			self._dc = dc
			self._gpio.setup(self._dc, GPIO.OUT)
Exemplo n.º 4
0
 def __init__(self, **kwargs):
     """
     :param int bus_id: the SMBus id (see Raspberry Pi documentation)
     :param kwargs: parameters transmitted to :py:class:`smbus.SMBus` initializer
     """
     JNTBus.__init__(self, **kwargs)
     self._spi_lock = threading.Lock()
     self.load_extensions(OID)
     self._ada_gpio = None
     try:
         self._ada_gpio = GPIO.get_platform_gpio()
     except :
         logger.exception("[%s] - Can't get GPIO", self.__class__.__name__)
     self._ada_spi = None
     try:
         self._ada_spi = SPI
     except :
         logger.exception("[%s] - Can't get SPI", self.__class__.__name__)
     self.export_attrs('_ada_spi', self._ada_spi)
     self.export_attrs('_ada_gpio', self._ada_gpio)
     self.export_attrs('spi_acquire', self.spi_acquire)
     self.export_attrs('spi_release', self.spi_release)
     self.export_attrs('spi_locked', self.spi_locked)
     self.export_attrs('get_spi_device', self.get_spi_device)
     self.export_attrs('get_spi_device_pin', self.get_spi_device_pin)
Exemplo n.º 5
0
 def __init__(self, dc, spi, rst=None, gpio=None, width=ILI9341_TFTWIDTH,
     height=ILI9341_TFTHEIGHT, bgr=False, bit_depth=ILI9341_16BIT):
     """Create an instance of the display using SPI communication.  Must
     provide the GPIO pin number for the D/C pin and the SPI driver.  Can
     optionally provide the GPIO pin number for the reset pin as the rst
     parameter.
     """
     assert bit_depth in (ILI9341_16BIT, ILI9341_18BIT)
     self._dc = dc
     self._rst = rst
     self._spi = spi
     self._gpio = gpio
     self.width = width
     self.height = height
     self.bgr = bgr
     self.bit_depth = bit_depth
     if self._gpio is None:
         self._gpio = GPIO.get_platform_gpio()
     # Set DC as output.
     self._gpio.setup(dc, GPIO.OUT)
     # Setup reset as output (if provided).
     if rst is not None:
         self._gpio.setup(rst, GPIO.OUT)
     # Set SPI to mode 0, MSB first.
     spi.set_mode(0)
     spi.set_bit_order(SPI.MSBFIRST)
     spi.set_clock_hz(64000000)
Exemplo n.º 6
0
	def __init__(self, dc, spi, rst=None, gpio=None, width=ILI9341_TFTWIDTH,
		height=ILI9341_TFTHEIGHT):
		"""Create an instance of the display using SPI communication.  Must
		provide the GPIO pin number for the D/C pin and the SPI driver.  Can
		optionally provide the GPIO pin number for the reset pin as the rst
		parameter.
		"""
		self._dc = dc
		self._rst = rst
		self._spi = spi
		self._gpio = gpio
		self.width = width
		self.height = height
		if self._gpio is None:
			self._gpio = GPIO.get_platform_gpio()
		# Set DC as output.
		self._gpio.setup(dc, GPIO.OUT)
		# Setup reset as output (if provided).
		if rst is not None:
			self._gpio.setup(rst, GPIO.OUT)
		# Set SPI to mode 0, MSB first.
		spi.set_mode(0)
		spi.set_bit_order(SPI.MSBFIRST)
	
                # Clock nerfed for the Minnowboard	
                if(Platform.platform_detect() == 3):
                    spi.set_clock_hz(1000000)
                else:
                    spi.set_clock_hz(64000000)
		
                # Create an image buffer.
		self.buffer = Image.new('RGB', (width, height))
Exemplo n.º 7
0
	def begin(self, contrast=40, bias=4):
		"""Initialize display."""
		# Default to detecting platform GPIO.
		if self._gpio is None:
			self._gpio = GPIO.get_platform_gpio()
		# Default to bit bang SPI.
		if self._spi is None:
			self._spi = SPI.BitBang(self._gpio, self._sclk, self._din, None, self._cs)
		# Set pin outputs.
		self._gpio.setup(self._dc, GPIO.OUT)
		if self._rst is not None:
			self._gpio.setup(self._rst, GPIO.OUT)
			# Toggle RST low to reset.
			self._gpio.set_low(self._rst)
			time.sleep(0.1)
			self._gpio.set_high(self._rst)
		# Enter extended mode commands.
		self.command(PCD8544_FUNCTIONSET | PCD8544_EXTENDEDINSTRUCTION)
		# Set LCD bias.
		self.command(PCD8544_SETBIAS | bias)
		# Set contrast.
		contrast = max(0, min(contrast, 0x7f)) # Clamp to values 0-0x7f
		self.command(PCD8544_SETVOP | contrast)
		# Set normal display mode.
		self.command(PCD8544_FUNCTIONSET)
		self.command(PCD8544_DISPLAYCONTROL | PCD8544_DISPLAYNORMAL)
Exemplo n.º 8
0
 def __init__(self, cs, sclk=None, mosi=None, miso=None, gpio=None, 
              spi=None):
     """Create an instance of the PN532 class using either software SPI (if 
     the sclk, mosi, and miso pins are specified) or hardware SPI if a
     spi parameter is passed.  The cs pin must be a digital GPIO pin.
     Optionally specify a GPIO controller to override the default that uses 
     the board's GPIO pins.
     """
     # Default to platform GPIO if not provided.
     self._gpio = gpio
     if self._gpio is None:
         self._gpio = GPIO.get_platform_gpio()
     # Initialize CS line.
     self._cs = cs
     self._gpio.setup(self._cs, GPIO.OUT)
     self._gpio.set_high(self._cs)
     # Setup SPI provider.
     if spi is not None:
         logger.debug('Using hardware SPI.')
         # Handle using hardware SPI.
         self._spi = spi
         self._spi.set_clock_hz(1000000)
     else:
         logger.debug('Using software SPI')
         # Handle using software SPI.  Note that the CS/SS pin is not used
         # as it will be manually controlled by this library for better
         # timing.
         self._spi = SPI.BitBang(self._gpio, sclk, mosi, miso)
     # Set SPI mode and LSB first bit order.
     self._spi.set_mode(0)
     self._spi.set_bit_order(SPI.LSBFIRST)
Exemplo n.º 9
0
 def __init__(self, rst=None, address=BNO055_ADDRESS_A, i2c=None, gpio=None,
              serial_port=None, serial_timeout_sec=5, **kwargs):
     # If reset pin is provided save it and a reference to provided GPIO
     # bus (or the default system GPIO bus if none is provided).
     self._rst = rst
     if self._rst is not None:
         if gpio is None:
             import Adafruit_GPIO as GPIO
             gpio = GPIO.get_platform_gpio()
         self._gpio = gpio
         # Setup the reset pin as an output at a high level.
         self._gpio.setup(self._rst, GPIO.OUT)
         self._gpio.set_high(self._rst)
         # Wait a 650 milliseconds in case setting the reset high reset the chip.
         time.sleep(0.65)
     self._serial = None
     self._i2c_device = None
     if serial_port is not None:
         # Use serial communication if serial_port name is provided.
         # Open the serial port at 115200 baud, 8N1.  Add a 5 second timeout
         # to prevent hanging if device is disconnected.
         self._serial = serial.Serial(serial_port, 115200, timeout=serial_timeout_sec,
                                      writeTimeout=serial_timeout_sec)
     else:
         # Use I2C if no serial port is provided.
         # Assume we're using platform's default I2C bus if none is specified.
         if i2c is None:
             import Adafruit_GPIO.I2C as I2C
             i2c = I2C
         # Save a reference to the I2C device instance for later communication.
         self._i2c_device = i2c.get_i2c_device(address, **kwargs)
Exemplo n.º 10
0
 def start(self, mqttc, trigger_thread_reload_cb=None):
     """Start the bus
     """
     JNTBus.start(self, mqttc, trigger_thread_reload_cb)
     try:
         self.gpio = GPIO.get_platform_gpio()
     except Exception:
         logger.exception("[%s] - Exception when starting GPIO bus", self.__class__.__name__)
     self.update_attrs('gpio', self.gpio)
Exemplo n.º 11
0
 def Init(self):
     if not self.initialized:
         _gpio = GPIO.get_platform_gpio()
         #GPIO = Adafruit_GPIO.RPiGPIOAdapter(_gpio)
         #GPIO.setmode(GPIO.BOARD)
         
         _gpio.setup(11, GPIO.IN)
         _gpio.setup(7, GPIO.OUT)
         self.initialized = True
Exemplo n.º 12
0
	def __init__(self, dc, rst, sclk=None, din=None, cs=None, gpio=None, spi=None, backlight=None):
		self._sclk = sclk
		self._din = din
		self._dc = dc
		self._cs = cs
		self._rst = rst
		self._gpio = gpio
		self._spi = spi
		self._backlight = backlight
		# Default to detecting platform GPIO.
		if self._gpio is None:
			self._gpio = GPIO.get_platform_gpio()
		if self._rst is not None:
			self._gpio.setup(self._rst, GPIO.OUT)
		if self._backlight is not None:
			self._gpio.setup(self._backlight, GPIO.OUT)
			#Default turn on backlight
			self._gpio.set_high(self._backlight)
		# Default to bit bang SPI.
		if self._spi is None:
			self._spi = SPI.BitBang(self._gpio, self._sclk, self._din, None, self._cs)
		# Set pin outputs.
		self._gpio.setup(self._dc, GPIO.OUT)
		# Initialize buffer to Adafruit logo.
		self._buffer = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
						0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
						0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFC, 0xFE, 0xFF, 0xFC, 0xE0,
						0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
						0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
						0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
						0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8,
						0xF8, 0xF0, 0xF0, 0xE0, 0xE0, 0xC0, 0x80, 0xC0, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x3F, 0x7F,
						0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
						0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
						0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
						0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x1F, 0x3F, 0x7F, 0xFF, 0xFF,
						0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE7, 0xC7, 0xC7, 0x87, 0x8F, 0x9F, 0x9F, 0xFF, 0xFF, 0xFF,
						0xC1, 0xC0, 0xE0, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xFC, 0xFC, 0xFC, 0xFE, 0xFE, 0xFE,
						0xFC, 0xFC, 0xF8, 0xF8, 0xF0, 0xE0, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
						0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
						0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
						0x00, 0x80, 0xC0, 0xE0, 0xF1, 0xFB, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x1F, 0x0F, 0x0F, 0x87,
						0xE7, 0xFF, 0xFF, 0xFF, 0x1F, 0x1F, 0x3F, 0xF9, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xFD, 0xFF,
						0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x3F, 0x0F, 0x07, 0x01, 0x00, 0x00, 0x00,
						0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
						0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
						0x00, 0x00, 0x00, 0xF0, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE,
						0x7E, 0x3F, 0x3F, 0x0F, 0x1F, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0xE0, 0xF1, 0xFF, 0xFF, 0xFF, 0xFF,
						0xFF, 0xFC, 0xF0, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
						0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
						0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
						0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x01,
						0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x0F, 0x1F, 0x3F, 0x7F, 0x7F,
						0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x7F, 0x1F, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
						0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
						0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ]
Exemplo n.º 13
0
    def __init__(
        self,
        width,
        height,
        rst,
        dc=None,
        sclk=None,
        din=None,
        cs=None,
        gpio=None,
        spi=None,
        i2c_bus=None,
        i2c_address=SSD1306_I2C_ADDRESS,
        i2c=None,
    ):
        self._log = logging.getLogger("Adafruit_SSD1306.SSD1306Base")
        self._spi = None
        self._i2c = None
        self.width = width
        self.height = height
        self._pages = height / 8
        self._buffer = [0] * (width * self._pages)
        # Default to platform GPIO if not provided.
        self._gpio = gpio
        if self._gpio is None:
            self._gpio = GPIO.get_platform_gpio()
            # Setup reset pin.
        self._rst = rst
        self._gpio.setup(self._rst, GPIO.OUT)
        # Handle hardware SPI
        if spi is not None:
            self._log.debug("Using hardware SPI")
            self._spi = spi
            self._spi.set_clock_hz(8000000)
            # Handle software SPI
        elif sclk is not None and din is not None and cs is not None:
            self._log.debug("Using software SPI")
            self._spi = SPI.BitBang(self._gpio, sclk, din, None, cs)
            # Handle hardware I2C
        elif i2c is not None:
            self._log.debug("Using hardware I2C with custom I2C provider.")
            self._i2c = i2c.get_i2c_device(i2c_address)
        else:
            self._log.debug("Using hardware I2C with platform I2C provider.")
            import Adafruit_GPIO.I2C as I2C

            if i2c_bus is None:
                self._i2c = I2C.get_i2c_device(i2c_address)
            else:
                self._i2c = I2C.get_i2c_device(i2c_address, busnum=i2c_bus)
                # Initialize DC pin if using SPI.
        if self._spi is not None:
            if dc is None:
                raise ValueError("DC pin must be provided when using SPI.")
            self._dc = dc
            self._gpio.setup(self._dc, GPIO.OUT)
Exemplo n.º 14
0
 def test_101_detect(self):
     self.onlyRasperryTest()
     import Adafruit_GPIO as GPIO
     comp = self.factory[self.component_name]()
     gpio = GPIO.get_platform_gpio()
     comp.setup_pir(gpio, 21, GPIO.RISING, comp.callback_pir, 200)
     time.sleep(5)
     dist = comp.values['status'].data
     print "status", dist
     self.assertNotEqual(dist, None)
     self.assertTrue(comp.check_heartbeat())
     gpio.cleanup()
Exemplo n.º 15
0
 def test_102_read_distance(self):
     self.onlyRasperryTest()
     import Adafruit_GPIO as GPIO
     comp = self.factory[self.component_name]()
     gpio = GPIO.get_platform_gpio()
     comp.setup_sonic(gpio, 20, 21, GPIO.RISING, comp.callback_echo, 200)
     comp.trigger_sonic(gpio, 20)
     time.sleep(1)
     dist = comp.values['status'].data
     print "distance", dist
     self.assertNotEqual(dist, None)
     self.assertTrue(comp.check_heartbeat())
     gpio.cleanup()
Exemplo n.º 16
0
    def __init__(self, rs, en, d4, d5, d6, d7, cols, lines, red, green, blue,
                 gpio=GPIO.get_platform_gpio(), 
                 invert_polarity=True,
                 enable_pwm=False,
                 pwm=PWM.get_platform_pwm(),
                 initial_color=(1.0, 1.0, 1.0)):
        """Initialize the LCD with RGB backlight.  RS, EN, and D4...D7 parameters 
        should be the pins connected to the LCD RS, clock enable, and data line 
        4 through 7 connections. The LCD will be used in its 4-bit mode so these 
        6 lines are the only ones required to use the LCD.  You must also pass in
        the number of columns and lines on the LCD.

        The red, green, and blue parameters define the pins which are connected
        to the appropriate backlight LEDs.  The invert_polarity parameter is a
        boolean that controls if the LEDs are on with a LOW or HIGH signal.  By
        default invert_polarity is True, i.e. the backlight LEDs are on with a
        low signal.  If you want to enable PWM on the backlight LEDs (for finer
        control of colors) and the hardware supports PWM on the provided pins,
        set enable_pwm to True.  Finally you can set an explicit initial backlight
        color with the initial_color parameter.  The default initial color is
        white (all LEDs lit).

        You can optionally pass in an explicit GPIO class,
        for example if you want to use an MCP230xx GPIO extender.  If you don't
        pass in an GPIO instance, the default GPIO for the running platform will
        be used.
        """
        super(Adafruit_RGBCharLCD, self).__init__(rs, en, d4, d5, d6, d7,
                                                  cols,
                                                  lines, 
                                                  enable_pwm=enable_pwm,
                                                  backlight=None,
                                                  invert_polarity=invert_polarity,
                                                  gpio=gpio, 
                                                  pwm=pwm)
        self._red = red
        self._green = green
        self._blue = blue
        # Setup backlight pins.
        if enable_pwm:
            # Determine initial backlight duty cycles.
            rdc, gdc, bdc = self._rgb_to_duty_cycle(initial_color)
            pwm.start(red, rdc)
            pwm.start(green, gdc)
            pwm.start(blue, bdc)
        else:
            gpio.setup(red, GPIO.OUT)
            gpio.setup(green, GPIO.OUT)
            gpio.setup(blue, GPIO.OUT)
            self._gpio.output_pins(self._rgb_to_pins(initial_color))
Exemplo n.º 17
0
  def __init__(self, width, height, rst, dc, spi=None, spi_port=None, spi_device=None, gpio=None):
    """ Initialize the SSD1351

    width: pixel width (128)
    height: pixel height (128)

    rst: reset pin
    dc: dc pin

    spi: SPI device
            spi_port: if SPI object is not passed, then use this spi port
            spi_device: if SPI object is not passed, use this spi device

    gpio: GPIO device. If GPIO is not passed, use the platform gpio

    """

    # Set screen dimensions
    self.width = width
    self.height = height

    # Set up GPIO
    if gpio is not None:
      self._gpio = gpio
    else:
      self._gpio = GPIO.get_platform_gpio()

    # Set up pins
    self._rst = rst
    self._dc = dc
    self._gpio.setup(self._rst, GPIO.OUT)
    self._gpio.setup(self._dc, GPIO.OUT)

    # Set up SPI
    if spi is not None:
      self._spi = spi
    else:
      if spi_port is None or spi_device is None:
        raise ValueError(
            "spi_port and spi_dev must be set if no spi object is passed")
      self._spi = SPI.SpiDev(
          spi_port, spi_device, max_speed_hz=20000000)

    self._spi.set_clock_hz(20000000)

    # Create buffer for images
    self._buffer = [0] * (self.width * self.height)
    self._current_row = 0
Exemplo n.º 18
0
 def __init__(self, bus=0, device=0, dc_pin=25, reset_pin=17, buffer_rows=128, buffer_cols=128, rows=128, cols=128):
     self.cols = cols
     self.rows = rows
     self.buffer_rows = buffer_rows
     self.mem_bytes = self.buffer_rows * self.cols / 8  # total bytes in SSD1306 display ram
     self.dc_pin = dc_pin
     self.reset_pin = reset_pin
     self.spi = s_SPI.SpiDev(0, 0, max_speed_hz=8000000)
     self._gpio = GPIO.get_platform_gpio()
     self._rst = reset_pin
     self._gpio.setup(self._rst, GPIO.OUT)
     self._dc = dc_pin
     self._gpio.setup(self._dc, GPIO.OUT)
     self.font = font5x8.Font5x8
     self.col_offset = 0
     self.bitmap = self.SimpleBitmap(buffer_cols, buffer_rows)
     self.flipped = False
Exemplo n.º 19
0
 def __init__(self, clk=None, cs=None, miso=None, mosi=None, spi=None, gpio=None):
     """Initialize MAX31855 device with software SPI on the specified CLK,
     CS, and DO pins.  Alternatively can specify hardware SPI by sending an
     Adafruit_GPIO.SPI.SpiDev device in the spi parameter.
     """
     self._spi = None
     # Handle hardware SPI
     if spi is not None:
         self._spi = spi
     elif clk is not None and cs is not None and miso is not None and mosi is not None:
         # Default to platform GPIO if not provided.
         if gpio is None:
             gpio = GPIO.get_platform_gpio()
         self._spi = SPI.BitBang(gpio, clk, mosi, miso, cs)
     else:
         raise ValueError('Must specify either spi for for hardware SPI or clk, cs, miso, and mosi for softwrare SPI!')
     self._spi.set_clock_hz(1000000)
     self._spi.set_mode(0)
     self._spi.set_bit_order(SPI.MSBFIRST)
Exemplo n.º 20
0
    def __init__(self, a_pin, b_pin):
        self.a_pin = a_pin
        self.b_pin = b_pin

        self.gpio = GPIO.get_platform_gpio()

        self.gpio.setup(self.a_pin, GPIO.IN)
        self.gpio.setup(self.b_pin, GPIO.IN)

        self.last_delta = 0
        self.r_seq = self.rotation_sequence()

        # steps_per_cycle and remainder are only used in get_cycles which
        # returns a coarse-granularity step count.  By default
        # steps_per_cycle is 4 as there are 4 steps per
        # detent on my encoder, and get_cycles() will return -1 or 1
        # for each full detent step.
        self.steps_per_cycle = 4
        self.remainder = 0
Exemplo n.º 21
0
    def __init__(self, width, height, rst, dc=None, sclk=None, din=None, cs=None, gpio=None,
                 spi=None, i2c_bus=None, i2c_address=SSD1306_I2C_ADDRESS,
                 i2c=None):
        self._spi = None
        self._i2c = None
        self.width = width
        self.height = height
        self._pages = height // 8
        self._buffer = [0] * width * self._pages
        self._cursor = 0

        # Default to platform GPIO if not provided.
        self._gpio = gpio
        if self._gpio is None:
            self._gpio = GPIO.get_platform_gpio()

        # Setup reset pin.
        self._rst = rst
        self._gpio.setup(self._rst, GPIO.OUT)

        # Handle hardware SPI
        if spi is not None:
            self._spi = spi
            self._spi.set_clock_hz(8000000)
        # Handle software SPI
        elif sclk is not None and din is not None and cs is not None:
            self._spi = SPI.BitBang(self._gpio, sclk, din, None, cs)
        # Handle hardware I2C
        elif i2c is not None:
            self._i2c = i2c.get_i2c_device(i2c_address)
        else:
            import Adafruit_GPIO.I2C as I2C

            self._i2c = I2C.get_i2c_device(i2c_address) if i2c_bus is None else I2C.get_i2c_device(i2c_address,
                                                                                                   busnum=i2c_bus)

        # Initialize DC pin if using SPI.
        if self._spi is not None:
            if dc is None:
                raise ValueError('DC pin must be provided when using SPI.')
            self._dc = dc
            self._gpio.setup(self._dc, GPIO.OUT)
Exemplo n.º 22
0
    def __init__(self, num_led, global_brightness=MAX_BRIGHTNESS,
                 order='rgb', mosi=10, sclk=11, max_speed_hz=8000000,
                 ce=None):
        """Initializes the library.
        
        """
        self.num_led = num_led  # The number of LEDs in the Strip
        order = order.lower()
        self.rgb = RGB_MAP.get(order, RGB_MAP['rgb'])
        # Limit the brightness to the maximum if it's set higher
        if global_brightness > self.MAX_BRIGHTNESS:
            self.global_brightness = self.MAX_BRIGHTNESS
        else:
            self.global_brightness = global_brightness

        self.leds = [self.LED_START, 0, 0, 0] * self.num_led  # Pixel buffer

        # MOSI 10 and SCLK 11 is hardware SPI, which needs to be set-up differently
        if mosi == 10 and sclk == 11:
            self.spi = SPI.SpiDev(0, 0 if ce is None else ce, max_speed_hz)  # Bus 0
        else:
            self.spi = SPI.BitBang(GPIO.get_platform_gpio(), sclk, mosi, ss=ce)
Exemplo n.º 23
0
    def __init__(self, width=128, height=64, dc=None, sclk=None, din=None, cs=None,
				 gpio=None, spi=None ):
        self._spi = None
        self.width = width
        self.height = height
        self._pages = height/8
        self._buffer = [0]*(width*self._pages)
        # Default to platform GPIO if not provided.
        self._gpio = gpio
        if self._gpio is None:
            self._gpio = GPIO.get_platform_gpio()
        # Setup reset pin.
        if spi is not None:
            #self._log.debug('Using hardware SPI')
            self._spi = spi
            self._spi.set_clock_hz(8000000)
        # Handle software SPI
        if self._spi is not None:
            if dc is None:
                raise ValueError('DC pin must be provided when using SPI.')
            self._dc = dc
            self._gpio.setup(self._dc, GPIO.OUT)
Exemplo n.º 24
0
 def __init__(self, TCA9548A_address=0x70, N_SHTs=8):
     self.sht = SHT31()  # Handle to all sensors in the array!
     self.TCA9548A = I2C.get_i2c_device(TCA9548A_address)
     self.N_SHTs = N_SHTs
     gpio = Adafruit_GPIO.get_platform_gpio()  #? is this neccessary?
Exemplo n.º 25
0
from time import sleep
import Adafruit_GPIO as GPIO
import Adafruit_GPIO.SPI as SPI
import RPi.GPIO
from utils import bytes_to_hex_str

SCLK = 40
MOSI = 38
MISO = 35
SS = 36

gpio = GPIO.get_platform_gpio(mode=RPi.GPIO.BOARD)
device = SPI.BitBang(gpio=gpio, sclk=SCLK, mosi=MOSI, miso=MISO, ss=SS)

# reset all registers to default
res = device.transfer([0x3C, 0x96])
# res (bytearray)
res = bytes_to_hex_str(res)
print('res {}'.format(res))
sleep(1)

# res = device.transfer([0x40, 0]) # b'\x00\x24'
res = device.transfer([0x41, 0])  # b'\x00\x22'
res = bytes_to_hex_str(res)
print('res {}'.format(res))
Exemplo n.º 26
0
 def test_remove_event_detect(self):
     rpi_gpio = Mock()
     adapter = GPIO.RPiGPIOAdapter(rpi_gpio)
     adapter.remove_event_detect(1)
     rpi_gpio.remove_event_detect.assert_called_with(1)
Exemplo n.º 27
0
	def test_raspberrypi(self):
		gpio = GPIO.get_platform_gpio()
		self.assertIsInstance(gpio, GPIO.RPiGPIOAdapter)
Exemplo n.º 28
0
from collections import namedtuple

motor = namedtuple("motor", "step dir")
sensor = namedtuple("sensor", "dev rate")

## parameters - beaglebone
# motor1 = motor(step = "P8_8", dir = "P8_10")
# motor2 = motor(step = "P8_12", dir = "P8_14")
## parameters - minnowboard
motor1 = motor(step = 476, dir = 477)
motor2 = motor(step = 478, dir = 479)
sensor1 = sensor(dev = "/dev/ttyUSB0", rate = 9600)
sensor2 = sensor(dev = "/dev/ttyUSB1", rate = 9600)
## parameters - general
delta = 50
gpio = GPIO.get_platform_gpio()
pos_max = 70
pos_min = -70

## functions
# single step on rising edge
def step (pin):
  gpio.output(pin, GPIO.HIGH)
  time.sleep(1E-3)
  gpio.output(pin, GPIO.LOW)
  time.sleep(1E-3)

# do some steps
def loop (pin_step, pin_dir, num, dir):
  gpio.output(pin_dir, dir)
  for i in range(0, num):
Exemplo n.º 29
0
#
import time
# Import the PCA9685 16-channel I2C PWM module.
import Adafruit_PCA9685 as PWM
# Import the GPIO library
###import CHIP_IO.GPIO as GPIO
import Adafruit_GPIO as gpio

GPIO = gpio.get_platform_gpio()

# Import the pin definition (a symbolic link to MyPins.<RobotName>.py)
# for your particular robot -
from MyPins import *

# Initialise the PCA9685 at the appropriate address and
# bus (0x40 and 1, respectively)
pwm = PWM.PCA9685(address=0x40, busnum=1)

#set GPIO pin directions (IN / OUT) for Ultrasonic Range Detector
GPIO.setup(GPIO_TRIGGER_F, gpio.OUT)
GPIO.setup(GPIO_ECHO_F, gpio.IN)

#set GPIO pin directions (IN / OUT) for Tracks
GPIO.setup(GPIO_RFRONT, gpio.OUT)
GPIO.setup(GPIO_RREAR, gpio.OUT)
GPIO.setup(GPIO_LFRONT, gpio.OUT)
GPIO.setup(GPIO_LREAR, gpio.OUT)

# Center the servo
pwm.set_pwm(PWM_CH_SERVO, 0,
            (int)(round(servo_min + ((servo_max - servo_min) / 2))))
Exemplo n.º 30
0
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
from PIL import Image

import ST7735 as TFT
import Adafruit_GPIO as GPIO
import Adafruit_GPIO.SPI as SPI
import qrcode
from nomorepass.core import NoMorePass
from uuid import getnode as get_mac
import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)

GPIO.setup(27, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(17, GPIO.OUT)
GPIO.setup(18, GPIO.OUT)
GPIO.output(17,True)

isopen = False
opencnt = 0

mac = get_mac()
macaddr = ':'.join(("%012X" % mac)[i:i+2] for i in range(0, 12, 2))

WIDTH = 128
HEIGHT = 160
SPEED_HZ = 4000000
Exemplo n.º 31
0
 def test_remove_event_detect(self):
     bbio_gpio = Mock()
     adapter = GPIO.AdafruitBBIOAdapter(bbio_gpio)
     adapter.remove_event_detect(1)
     bbio_gpio.remove_event_detect.assert_called_with(1)
Exemplo n.º 32
0
 def test_beagleboneblack(self):
     gpio = GPIO.get_platform_gpio()
     self.assertIsInstance(gpio, GPIO.AdafruitBBIOAdapter)
Exemplo n.º 33
0
 def test_add_event_detect(self):
     rpi_gpio = Mock()
     adapter = GPIO.RPiGPIOAdapter(rpi_gpio)
     adapter.add_event_detect(1, GPIO.RISING)
     rpi_gpio.add_event_detect.assert_called_with(1, rpi_gpio.RISING)
Exemplo n.º 34
0
 def test_raspberrypi(self):
     gpio = GPIO.get_platform_gpio()
     self.assertIsInstance(gpio, GPIO.RPiGPIOAdapter)
Exemplo n.º 35
0
 def test_cleanup_pin(self):
     bbio_gpio = Mock()
     adapter = GPIO.AdafruitBBIOAdapter(bbio_gpio)
     adapter.cleanup(1)
     bbio_gpio.cleanup.assert_called_with(1)
Exemplo n.º 36
0
 def test_wait_for_edge(self):
     bbio_gpio = Mock()
     adapter = GPIO.AdafruitBBIOAdapter(bbio_gpio)
     adapter.wait_for_edge(1, GPIO.FALLING)
     bbio_gpio.wait_for_edge.assert_called_with(1, bbio_gpio.FALLING)
Exemplo n.º 37
0
lcd_columns = 16
lcd_rows = 2

# Initialize the LCD using the pins above.
#lcd = LCD.Adafruit_CharLCD(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7,
#lcd_columns, lcd_rows, lcd_backlight,False)

# Backlight pwm separately, is not supported by Adafruit
lcd = Adafruit_CharLCD(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7,
                       lcd_columns, lcd_rows)

# Print a two line message
lcd.message('Hello\nworld!')

#GPIO.setmode(GPIO.BOARD)
GPIO.setup(lcd_backlight, GPIO.OUT)

# set frequency
p = GPIO.PWM(12, 400)
# Start with duty cycle (percentage)
p.start(100)
# set duty cycle
#p.ChangeDutyCycle(10.0)


def on_disconnect(client, userdata, rc=0):
    #logging.debug("DisConnected result code "+str(rc))
    client.loop_stop()


def on_message(client, userdata, message):
Exemplo n.º 38
0
def closeDoor():
    print "Clossing..."
    GPIO.output(17,False)
    GPIO.output(18,True)
    isopen = False
    opencnt = 0
Exemplo n.º 39
0
def LCD_Light(val): 
    global backlight
    if (val==1):
        GPIO.output(backlight, GPIO.HIGH)
    else:
        GPIO.output(backlight, GPIO.LOW)
Exemplo n.º 40
0
 def test_add_event_detect(self):
     bbio_gpio = Mock()
     adapter = GPIO.AdafruitBBIOAdapter(bbio_gpio)
     adapter.add_event_detect(1, GPIO.RISING)
     bbio_gpio.add_event_detect.assert_called_with(1, bbio_gpio.RISING)
Exemplo n.º 41
0
 def test_event_detected(self):
     bbio_gpio = Mock()
     adapter = GPIO.AdafruitBBIOAdapter(bbio_gpio)
     adapter.event_detected(1)
     bbio_gpio.event_detected.assert_called_with(1)

def yawFromQuatenion(w, x, y, z):
    ysqr = y * y
    t3 = +2.0 * (w * z + x * y)
    t4 = +1.0 - 2.0 * (ysqr + z * z)
    Z = math.degrees(math.atan2(t3, t4))
    return Z


# main
if __name__ == '__main__':  # Program start from here
    try:
        try:
            bno = None
            gpio = GPIO.get_platform_gpio(mode=rpi_GPIO.BCM)
            pwm = PWM.get_platform_pwm()
            (bno, gpio) = init(bno, gpio)

            dt = 0.1
            f = 1 / dt

            # set up the relays
            relay1 = 12
            pwm.start(relay1, 0, f)
            relay2 = 18
            pwm.start(relay2, 0, f)

            #init control gains
            Ki = 1
            Kp = 1
Exemplo n.º 43
0
    def __init__(self,
                 rs,
                 en,
                 d4,
                 d5,
                 d6,
                 d7,
                 cols,
                 lines,
                 red,
                 green,
                 blue,
                 gpio=GPIO.get_platform_gpio(),
                 invert_polarity=True,
                 enable_pwm=False,
                 pwm=PWM.get_platform_pwm(),
                 initial_color=(1.0, 1.0, 1.0)):
        """Initialize the LCD with RGB backlight.  RS, EN, and D4...D7 parameters 
        should be the pins connected to the LCD RS, clock enable, and data line 
        4 through 7 connections. The LCD will be used in its 4-bit mode so these 
        6 lines are the only ones required to use the LCD.  You must also pass in
        the number of columns and lines on the LCD.

        The red, green, and blue parameters define the pins which are connected
        to the appropriate backlight LEDs.  The invert_polarity parameter is a
        boolean that controls if the LEDs are on with a LOW or HIGH signal.  By
        default invert_polarity is True, i.e. the backlight LEDs are on with a
        low signal.  If you want to enable PWM on the backlight LEDs (for finer
        control of colors) and the hardware supports PWM on the provided pins,
        set enable_pwm to True.  Finally you can set an explicit initial backlight
        color with the initial_color parameter.  The default initial color is
        white (all LEDs lit).

        You can optionally pass in an explicit GPIO class,
        for example if you want to use an MCP230xx GPIO extender.  If you don't
        pass in an GPIO instance, the default GPIO for the running platform will
        be used.
        """
        super(Adafruit_RGBCharLCD,
              self).__init__(rs,
                             en,
                             d4,
                             d5,
                             d6,
                             d7,
                             cols,
                             lines,
                             enable_pwm=enable_pwm,
                             backlight=None,
                             invert_polarity=invert_polarity,
                             gpio=gpio,
                             pwm=pwm)
        self._red = red
        self._green = green
        self._blue = blue
        # Setup backlight pins.
        if enable_pwm:
            # Determine initial backlight duty cycles.
            rdc, gdc, bdc = self._rgb_to_duty_cycle(initial_color)
            pwm.start(red, rdc)
            pwm.start(green, gdc)
            pwm.start(blue, bdc)
        else:
            gpio.setup(red, GPIO.OUT)
            gpio.setup(green, GPIO.OUT)
            gpio.setup(blue, GPIO.OUT)
            self._gpio.output_pins(self._rgb_to_pins(initial_color))
Exemplo n.º 44
0
    def __init__(self,
                 dac_model,
                 clk=None,
                 cs=None,
                 do=None,
                 spi=None,
                 gpio=None):
        """The constructor for the AD56x8 class.

        Args:
            AD56x8 DAC Specific Args
            dac_model (str): command constant

            Adafruit-GPIO Specific Args
            clk (int): DAC value to selected channel
            cs (str, int): Platform specific pin selection for CS
            do (str, int): Platform specific pin selection for DO
            spi (str, int): Platform specific pin selection for CS
            gpio (str, int): Platform specific selection for platform GPIO

        Attributes:
            DATA_WIDTH (int): Width of DAC value in bits
            VREF (float): Internal VREF voltage
            PU_DAC_MULT (float): Default power-up DAC output value

        Attributes are set for the specific DAC model upon construction, which
        are useful for calculating the DAC value to write for a desired
        output voltage

        Since this component does not have a MISO/DOUT line, it isn't possible
        to determine which/any commands have been received. Use a loopback to
        a ADC, or get a better part.
        """

        # Set DAC attributes specific to called model
        if dac_model in AD56x8_MODEL_PARAMS.keys():
            setattr(self, 'device', dac_model)
            for key, value in AD56x8_MODEL_PARAMS[dac_model].items():
                setattr(self, key, value)
        else:
            raise ValueError('AD56x8: DAC model specified not in known set')

        # Initialize device with software SPI on the specified CLK,
        # CS, and DO pins.  Alternatively can specify hardware SPI by sending
        # an Adafruit_GPIO.SPI.SpiDev device in the spi parameter.

        self._spi = None

        # Handle hardware SPI
        if spi is not None:
            self._spi = spi
        elif clk is not None and cs is not None and do is not None:
            # Default to platform GPIO if not provided.
            if gpio is None:
                gpio = GPIO.get_platform_gpio()
            self._spi = SPI.BitBang(gpio, clk, do, None, cs)
        else:
            raise ValueError('Must specify either hardware spi or clk, \
                                cs, and do for software SPI!')

        # SPI Configurations
        self._spi.set_clock_hz(5000000)
        self._spi.set_mode(0)
        self._spi.set_bit_order(SPI.MSBFIRST)
Exemplo n.º 45
0
def main():
    pygame.init()
    screen = pygame.display.set_mode((900, 600))

    complete = pygame.mixer.Sound('thats-correct.ogg')

    # Trigger the master alarm
    master_alarm = True

    # Generate the display objects
    goal_display = seven_segment_i2c.SevenSegmentDisplay(address=0x71)
    actual_display = seven_segment_i2c.SevenSegmentDisplay(address=0x72)
    parallel_group_display0 = seven_segment_i2c.SevenSegmentDisplay(address=0x73)
    parallel_group_display1 = seven_segment_i2c.SevenSegmentDisplay(address=0x74)
    parallel_group_display2 = seven_segment_i2c.SevenSegmentDisplay(address=0x75)

    # Set up the input pins for the switches
    pins = ["P8_7",  "P8_9",  "P8_11",
            "P8_8",  "P8_10", "P8_12",
            "P8_14", "P8_16", "P8_18"]

    switches = [GPIO.get_platform_gpio()] * len(pins)
    for i in range(len(switches)):
        switches[i].setup(pins[i], GPIO.IN)

    # Set the goal impedance of the circuit
    goal = set_goal(load_combinations())

    # Set a fake actual resistance to get the while loop started
    # actual = 0

    # Display the goal impedance of the circuit
    goal_display.write_int(goal)

    while master_alarm is True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                master_alarm = True

        # Read all the switches.
        switch_states = [0] * len(switches)
        resistance = [0, 0, 0]
        for i in range(len(switches)):
            switch_states[i] = switches[i].input(pins[i])

        # Calculate the resistance of the display groups
        for i in range(0, 3):
            if switch_states[i]:
                resistance[0] += RESISTOR_VALUES[i]  # Calculate the resistance of the first group
        for i in range(3, 6):
            if switch_states[i]:
                resistance[1] += RESISTOR_VALUES[i]  # Calculate the resistance of the second group
        for i in range(6, 9):
            if switch_states[i]:
                resistance[2] += RESISTOR_VALUES[i]  # Calculate the resistance of the third group

        # I'm not sure what this does, I can't remember why I added it. I think it was because the 'resistance' array
        # was not appending properly, although I can't see how this would fix that...
        for i in range(len(resistance)):
            resistance[i] = resistance[i]

        actual = sum(resistance)

        # Display the resistance values
        parallel_group_display0.write_int(resistance[0])
        parallel_group_display1.write_int(resistance[1])
        parallel_group_display2.write_int(resistance[2])
        actual_display.write_int(actual)

        # Check to see if we have solved the puzzle
        if actual == goal:
            master_alarm = False
            complete.play()

            # Flash the 'goal' and 'actual' displays to show they match
            for i in range(3):
                goal_display.clear_display()
                actual_display.clear_display()
                parallel_group_display0.clear_display()
                parallel_group_display1.clear_display()
                parallel_group_display2.clear_display()

                time.sleep(0.15)

                goal_display.write_int(goal)
                actual_display.write_int(actual)
                parallel_group_display0.write_int(resistance[0])
                parallel_group_display1.write_int(resistance[1])
                parallel_group_display2.write_int(resistance[2])

                time.sleep(0.50)

            # Turn off all the displays when the puzzle is solved.
            # I think we should play a sound to reinforce the success
            goal_display.clear_display()
            actual_display.clear_display()
            parallel_group_display0.clear_display()
            parallel_group_display1.clear_display()
            parallel_group_display2.clear_display()

        # Delay for a small amount of time
        time.sleep(0.25)

        # Update the display
        pygame.display.flip()
Exemplo n.º 46
0
    SCAN_TIMEOUT = float(sys.argv[1])

if len(sys.argv) > 2:
    CS = int(sys.argv[2])
    MOSI = int(sys.argv[3])
    MISO = int(sys.argv[4])
    SCLK = int(sys.argv[5])

time.sleep(2)

# initialize pn532 python
pn532 = PN532.PN532(cs=CS,
                    sclk=SCLK,
                    mosi=MOSI,
                    miso=MISO,
                    gpio=GPIO.RPiGPIOAdapter(RPi.GPIO, RPi.GPIO.BOARD))

# begin pn532 operations
pn532.begin()

print json.dumps({'message': 'Initialized', 'code': 1})

# Get the firmware version from the chip and print(it out.)
ic, ver, rev, support = pn532.get_firmware_version()
print json.dumps({
    'message': 'Firmware Version',
    'code': 3,
    'data': {
        'ic': ic,
        'ver': ver,
        'rev': rev,
Exemplo n.º 47
0
	def test_beagleboneblack(self):
		gpio = GPIO.get_platform_gpio()
		self.assertIsInstance(gpio, GPIO.AdafruitBBIOAdapter)
Exemplo n.º 48
0
 def test_cleanup(self):
     rpi_gpio = Mock()
     adapter = GPIO.AdafruitBBIOAdapter(rpi_gpio)
     adapter.cleanup()
     rpi_gpio.cleanup.assert_called()
Exemplo n.º 49
0
def get_platform_gpio_for_pi(**keywords):
    import RPi.GPIO
    return GPIO.RPiGPIOAdapter(RPi.GPIO, **keywords)
Exemplo n.º 50
0
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

from PIL import Image

import Adafruit_ILI9341 as TFT
import Adafruit_GPIO as GPIO
gpio = GPIO.get_platform_gpio()
import Adafruit_GPIO.SPI as SPI
import os
import time

global cs1, cs2, cs3, cs4
cs1 = 20
cs2 = 21
cs3 = 18
cs4 = 17

#reset pins
global rst1, rst2, rst3, rst4
rst1 = 2
rst2 = 27
rst3 = 22
Exemplo n.º 51
0
 def __init__(self,
              dc,
              rst,
              sclk=None,
              din=None,
              cs=None,
              gpio=None,
              spi=None):
     self._sclk = sclk
     self._din = din
     self._dc = dc
     self._cs = cs
     self._rst = rst
     self._gpio = gpio
     self._spi = spi
     # Default to detecting platform GPIO.
     if self._gpio is None:
         self._gpio = GPIO.get_platform_gpio()
     if self._rst is not None:
         self._gpio.setup(self._rst, GPIO.OUT)
     # Default to bit bang SPI.
     if self._spi is None:
         self._spi = SPI.BitBang(self._gpio, self._sclk, self._din, None,
                                 self._cs)
     # Set pin outputs.
     self._gpio.setup(self._dc, GPIO.OUT)
     # Initialize buffer to Adafruit logo.
     self._buffer = [
         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
         0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFC,
         0xFE, 0xFF, 0xFC, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
         0x00, 0x00, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8,
         0xF8, 0xF8, 0xF8, 0xF0, 0xF0, 0xE0, 0xE0, 0xC0, 0x80, 0xC0, 0xFC,
         0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x3F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF,
         0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F,
         0x1F, 0x3F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
         0xE7, 0xC7, 0xC7, 0x87, 0x8F, 0x9F, 0x9F, 0xFF, 0xFF, 0xFF, 0xC1,
         0xC0, 0xE0, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xFC, 0xFC,
         0xFC, 0xFE, 0xFE, 0xFE, 0xFC, 0xFC, 0xF8, 0xF8, 0xF0, 0xE0, 0xC0,
         0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0,
         0xE0, 0xF1, 0xFB, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x1F, 0x0F,
         0x0F, 0x87, 0xE7, 0xFF, 0xFF, 0xFF, 0x1F, 0x1F, 0x3F, 0xF9, 0xF8,
         0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xFD, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
         0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x3F, 0x0F, 0x07, 0x01, 0x00, 0x00,
         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
         0x00, 0x00, 0x00, 0xF0, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
         0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0x7E, 0x3F, 0x3F, 0x0F, 0x1F, 0xFF,
         0xFF, 0xFF, 0xFC, 0xF0, 0xE0, 0xF1, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
         0xFC, 0xF0, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00,
         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03,
         0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x01, 0x01, 0x01, 0x01,
         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x0F, 0x1F, 0x3F,
         0x7F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x7F, 0x1F, 0x03, 0x00,
         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
     ]
Exemplo n.º 52
0
 def test_wait_for_edge(self):
     rpi_gpio = Mock()
     adapter = GPIO.RPiGPIOAdapter(rpi_gpio)
     adapter.wait_for_edge(1, GPIO.FALLING)
     rpi_gpio.wait_for_edge.assert_called_with(1, rpi_gpio.FALLING)
Exemplo n.º 53
0
 def get_led_controller(self):
     import Adafruit_GPIO as GPIO
     return GPIO_LEDController(GPIO.get_platform_gpio(), self._pin_led, self._get_pwm())
Exemplo n.º 54
0
 def test_event_detected(self):
     rpi_gpio = Mock()
     adapter = GPIO.RPiGPIOAdapter(rpi_gpio)
     adapter.event_detected(1)
     rpi_gpio.event_detected.assert_called_with(1)
Exemplo n.º 55
0
    def __init__(self, rs, en, d4, d5, d6, d7, cols, lines, backlight=None,
                    invert_polarity=True,
                    enable_pwm=False,
                    gpio=GPIO.get_platform_gpio(),
                    pwm=PWM.get_platform_pwm(),
                    initial_backlight=1.0):
        """Initialize the LCD.  RS, EN, and D4...D7 parameters should be the pins
        connected to the LCD RS, clock enable, and data line 4 through 7 connections.
        The LCD will be used in its 4-bit mode so these 6 lines are the only ones
        required to use the LCD.  You must also pass in the number of columns and
        lines on the LCD.  

        If you would like to control the backlight, pass in the pin connected to
        the backlight with the backlight parameter.  The invert_polarity boolean
        controls if the backlight is one with a LOW signal or HIGH signal.  The 
        default invert_polarity value is True, i.e. the backlight is on with a
        LOW signal.  

        You can enable PWM of the backlight pin to have finer control on the 
        brightness.  To enable PWM make sure your hardware supports PWM on the 
        provided backlight pin and set enable_pwm to True (the default is False).
        The appropriate PWM library will be used depending on the platform, but
        you can provide an explicit one with the pwm parameter.

        The initial state of the backlight is ON, but you can set it to an 
        explicit initial state with the initial_backlight parameter (0 is off,
        1 is on/full bright).

        You can optionally pass in an explicit GPIO class,
        for example if you want to use an MCP230xx GPIO extender.  If you don't
        pass in an GPIO instance, the default GPIO for the running platform will
        be used.
        """
        # Save column and line state.
        self._cols = cols
        self._lines = lines
        # Save GPIO state and pin numbers.
        self._gpio = gpio
        self._rs = rs
        self._en = en
        self._d4 = d4
        self._d5 = d5
        self._d6 = d6
        self._d7 = d7
        # Save backlight state.
        self._backlight = backlight
        self._pwm_enabled = enable_pwm
        self._pwm = pwm
        self._blpol = not invert_polarity
        # Setup all pins as outputs.
        for pin in (rs, en, d4, d5, d6, d7):
            gpio.setup(pin, GPIO.OUT)
        # Setup backlight.
        if backlight is not None:
            if enable_pwm:
                pwm.start(backlight, self._pwm_duty_cycle(initial_backlight))
            else:
                gpio.setup(backlight, GPIO.OUT)
                gpio.output(backlight, self._blpol if initial_backlight else not self._blpol)
        # Initialize the display.
        self.write8(0x33)
        self.write8(0x32)
        # Initialize display control, function, and mode registers.
        self.displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF
        self.displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_2LINE | LCD_5x8DOTS
        self.displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT
        # Write registers.
        self.write8(LCD_DISPLAYCONTROL | self.displaycontrol)
        self.write8(LCD_FUNCTIONSET | self.displayfunction)
        self.write8(LCD_ENTRYMODESET | self.displaymode)  # set the entry mode
        self.clear()
Exemplo n.º 56
0
 def test_add_event_callback(self):
     rpi_gpio = Mock()
     adapter = GPIO.RPiGPIOAdapter(rpi_gpio)
     adapter.add_event_callback(1, callback=self.test_add_event_callback)
     rpi_gpio.add_event_callback.assert_called_with(
         1, self.test_add_event_callback)
Exemplo n.º 57
0

import time
import sys
import os
from PIL import Image
from pyDrivers.ada_lcd import *
import pyDrivers.ILI9341 as TFT
import Adafruit_GPIO as GPIO
import Adafruit_GPIO.SPI as SPI

if (len(sys.argv) < 2 ):
    print "Usage: python slideshow.py [image directory]"
    exit(1)

myGPIO = GPIO.get_platform_gpio()

myGPIO.setup(12,GPIO.IN)
myGPIO.setup(16,GPIO.IN)

lcd = ADA_LCD()
lcd.clear()

SPI_PORT = 0
SPI_DEVICE = 0
SPEED = 16000000
DC = 10
RST = 14 

imageList = []
rawList = os.listdir(sys.argv[1])
Exemplo n.º 58
0
 def __init__(self, rs, en, d4, d5, d6, d7, cols, lines, backlight=None,
                 invert_polarity=True,
                 enable_pwm=False,
                 gpio=GPIO.get_platform_gpio(),
                 pwm=PWM.get_platform_pwm(),
                 initial_backlight=1.0):
     """Initialize the LCD.  RS, EN, and D4...D7 parameters should be the pins
     connected to the LCD RS, clock enable, and data line 4 through 7 connections.
     The LCD will be used in its 4-bit mode so these 6 lines are the only ones
     required to use the LCD.  You must also pass in the number of columns and
     lines on the LCD.  
     If you would like to control the backlight, pass in the pin connected to
     the backlight with the backlight parameter.  The invert_polarity boolean
     controls if the backlight is one with a LOW signal or HIGH signal.  The 
     default invert_polarity value is True, i.e. the backlight is on with a
     LOW signal.  
     You can enable PWM of the backlight pin to have finer control on the 
     brightness.  To enable PWM make sure your hardware supports PWM on the 
     provided backlight pin and set enable_pwm to True (the default is False).
     The appropriate PWM library will be used depending on the platform, but
     you can provide an explicit one with the pwm parameter.
     The initial state of the backlight is ON, but you can set it to an 
     explicit initial state with the initial_backlight parameter (0 is off,
     1 is on/full bright).
     You can optionally pass in an explicit GPIO class,
     for example if you want to use an MCP230xx GPIO extender.  If you don't
     pass in an GPIO instance, the default GPIO for the running platform will
     be used.
     """
     # Save column and line state.
     self._cols = cols
     self._lines = lines
     # Save GPIO state and pin numbers.
     self._gpio = gpio
     self._rs = rs
     self._en = en
     self._d4 = d4
     self._d5 = d5
     self._d6 = d6
     self._d7 = d7
     # Save backlight state.
     self._backlight = backlight
     self._pwm_enabled = enable_pwm
     self._pwm = pwm
     self._blpol = not invert_polarity
     # Setup all pins as outputs.
     for pin in (rs, en, d4, d5, d6, d7):
         gpio.setup(pin, GPIO.OUT)
     # Setup backlight.
     if backlight is not None:
         if enable_pwm:
             pwm.start(backlight, self._pwm_duty_cycle(initial_backlight))
         else:
             gpio.setup(backlight, GPIO.OUT)
             gpio.output(backlight, self._blpol if initial_backlight else not self._blpol)
     # Initialize the display.
     self.write8(0x33)
     self.write8(0x32)
     # Initialize display control, function, and mode registers.
     self.displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF
     self.displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_2LINE | LCD_5x8DOTS
     self.displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT
     # Write registers.
     self.write8(LCD_DISPLAYCONTROL | self.displaycontrol)
     self.write8(LCD_FUNCTIONSET | self.displayfunction)
     self.write8(LCD_ENTRYMODESET | self.displaymode)  # set the entry mode
     self.clear()
Exemplo n.º 59
0
def openDoor ():
    print "Opening..."
    GPIO.output(18,False)
    GPIO.output(17,True)
    isopen = True
    opencnt = 40
Exemplo n.º 60
0
 def test_add_event_callback(self):
     bbio_gpio = Mock()
     adapter = GPIO.AdafruitBBIOAdapter(bbio_gpio)
     adapter.add_event_callback(1, callback=self.test_add_event_callback)
     bbio_gpio.add_event_callback.assert_called_with(
         1, self.test_add_event_callback)