當前位置: 首頁>>代碼示例>>Python>>正文


Python Adafruit_GPIO.get_platform_gpio方法代碼示例

本文整理匯總了Python中Adafruit_GPIO.get_platform_gpio方法的典型用法代碼示例。如果您正苦於以下問題:Python Adafruit_GPIO.get_platform_gpio方法的具體用法?Python Adafruit_GPIO.get_platform_gpio怎麽用?Python Adafruit_GPIO.get_platform_gpio使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Adafruit_GPIO的用法示例。


在下文中一共展示了Adafruit_GPIO.get_platform_gpio方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: import Adafruit_GPIO [as 別名]
# 或者: from Adafruit_GPIO import get_platform_gpio [as 別名]
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 ] 
開發者ID:adafruit,項目名稱:Adafruit_Nokia_LCD,代碼行數:22,代碼來源:PCD8544.py

示例2: __init__

# 需要導入模塊: import Adafruit_GPIO [as 別名]
# 或者: from Adafruit_GPIO import get_platform_gpio [as 別名]
def __init__(self, clk=None, cs=None, do=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._logger = logging.getLogger('Adafruit_MAX31855.MAX31855')
        self._spi = None
        # Handle hardware SPI
        if spi is not None:
            self._logger.debug('Using hardware SPI')
            self._spi = spi
        elif clk is not None and cs is not None and do is not None:
            self._logger.debug('Using software SPI')
            # Default to platform GPIO if not provided.
            if gpio is None:
                gpio = GPIO.get_platform_gpio()
            self._spi = SPI.BitBang(gpio, clk, None, do, cs)
        else:
            raise ValueError('Must specify either spi for for hardware SPI or clk, cs, and do for softwrare SPI!')
        self._spi.set_clock_hz(5000000)
        self._spi.set_mode(0)
        self._spi.set_bit_order(SPI.MSBFIRST) 
開發者ID:adafruit,項目名稱:Adafruit_Python_MAX31855,代碼行數:24,代碼來源:MAX31855.py

示例3: __init__

# 需要導入模塊: import Adafruit_GPIO [as 別名]
# 或者: from Adafruit_GPIO import get_platform_gpio [as 別名]
def __init__(self, count, clk=None, do=None, spi=None, gpio=None):
        """Initialize set of WS2801/SPI-like addressable RGB LEDs.  Must
        specify the count of pixels, and either an explicit clk (clokc) and do
        (data output) line for software SPI or a spi instance for hardware SPI.
        """
        self._spi = None
        if spi:
            # Handle hardware SPI.
            self._spi = spi
        elif clk and do:
            # Handle software SPI.
            # Default to platform GPIO if not provided.
            if not gpio:
                import Adafruit_GPIO as GPIO
                gpio = GPIO.get_platform_gpio()
            self._spi = SPI.BitBang(gpio, clk, do, None, None)
        else:
            raise ValueError('Must specify either spi for for hardware SPI or clk, and do for software SPI!')
        # Setup SPI interface with up to 20mhz speed.
        self._spi.set_clock_hz(1000000)
        self._spi.set_mode(0)
        self._spi.set_bit_order(SPI.MSBFIRST)
        # Setup buffer for pixel RGB data.
        self._count = count
        self._pixels = [0]*(count*3) 
開發者ID:adafruit,項目名稱:Adafruit_Python_WS2801,代碼行數:27,代碼來源:WS2801.py

示例4: __init__

# 需要導入模塊: import Adafruit_GPIO [as 別名]
# 或者: from Adafruit_GPIO import get_platform_gpio [as 別名]
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 software SPI!')
        self._spi.set_clock_hz(1000000)
        self._spi.set_mode(0)
        self._spi.set_bit_order(SPI.MSBFIRST) 
開發者ID:adafruit,項目名稱:Adafruit_Python_MCP3008,代碼行數:21,代碼來源:MCP3008.py

示例5: __init__

# 需要導入模塊: import Adafruit_GPIO [as 別名]
# 或者: from Adafruit_GPIO import get_platform_gpio [as 別名]
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(800000)
        #self._spi.set_clock_hz(1000000)
        self._spi.set_clock_hz(1000000)
        self._spi.set_mode(0)
        self._spi.set_bit_order(SPI.MSBFIRST) 
開發者ID:Qu-Bit-Electronix,項目名稱:QB_Nebulae_V2,代碼行數:23,代碼來源:MCP3208.py

示例6: __init__

# 需要導入模塊: import Adafruit_GPIO [as 別名]
# 或者: from Adafruit_GPIO import get_platform_gpio [as 別名]
def __init__(self, count, clk=None, do=None, spi=None, gpio=None):
        """Initialize set of WS2801/SPI-like addressable RGB LEDs.  Must
        specify the count of pixels, and either an explicit clk (clokc) and do
        (data output) line for software SPI or a spi instance for hardware SPI.
        """
        self._spi = None
        if spi is not None:
            # Handle hardware SPI.
            self._spi = spi
        elif clk is not None and do is not None:
            # Handle software SPI.
            # Default to platform GPIO if not provided.
            if gpio is None:
                import Adafruit_GPIO as GPIO
                gpio = GPIO.get_platform_gpio()
            self._spi = SPI.BitBang(gpio, clk, do, None, None)
        else:
            raise ValueError('Must specify either spi for for hardware SPI or clk, and do for softwrare SPI!')
        # Setup SPI interface with up to 20mhz speed.
        self._spi.set_clock_hz(1000000)
        self._spi.set_mode(0)
        self._spi.set_bit_order(SPI.MSBFIRST)
        # Setup buffer for pixel RGB data.
        self._count = count
        self._pixels = [0]*(count*3) 
開發者ID:aws-samples,項目名稱:aws-builders-fair-projects,代碼行數:27,代碼來源:WS2801.py

示例7: __init__

# 需要導入模塊: import Adafruit_GPIO [as 別名]
# 或者: from Adafruit_GPIO import get_platform_gpio [as 別名]
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)
        spi.set_clock_hz(64000000)
        # Create an image buffer.
        self.buffer = Image.new('RGB', (width, height)) 
開發者ID:adafruit,項目名稱:Adafruit_Python_ILI9341,代碼行數:28,代碼來源:ILI9341.py

示例8: test_raspberrypi

# 需要導入模塊: import Adafruit_GPIO [as 別名]
# 或者: from Adafruit_GPIO import get_platform_gpio [as 別名]
def test_raspberrypi(self):
        gpio = GPIO.get_platform_gpio()
        self.assertIsInstance(gpio, GPIO.RPiGPIOAdapter) 
開發者ID:adafruit,項目名稱:Adafruit_Python_GPIO,代碼行數:5,代碼來源:test_GPIO.py

示例9: test_beagleboneblack

# 需要導入模塊: import Adafruit_GPIO [as 別名]
# 或者: from Adafruit_GPIO import get_platform_gpio [as 別名]
def test_beagleboneblack(self):
        gpio = GPIO.get_platform_gpio()
        self.assertIsInstance(gpio, GPIO.AdafruitBBIOAdapter) 
開發者ID:adafruit,項目名稱:Adafruit_Python_GPIO,代碼行數:5,代碼來源:test_GPIO.py

示例10: test_unknown

# 需要導入模塊: import Adafruit_GPIO [as 別名]
# 或者: from Adafruit_GPIO import get_platform_gpio [as 別名]
def test_unknown(self):
        self.assertRaises(RuntimeError, GPIO.get_platform_gpio) 
開發者ID:adafruit,項目名稱:Adafruit_Python_GPIO,代碼行數:4,代碼來源:test_GPIO.py

示例11: __init__

# 需要導入模塊: import Adafruit_GPIO [as 別名]
# 或者: from Adafruit_GPIO import get_platform_gpio [as 別名]
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) 
開發者ID:adafruit,項目名稱:Adafruit_Python_PN532,代碼行數:33,代碼來源:PN532.py

示例12: __init__

# 需要導入模塊: import Adafruit_GPIO [as 別名]
# 或者: from Adafruit_GPIO import get_platform_gpio [as 別名]
def __init__(self, lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7, lcd_columns, lcd_rows, lcd_backlight):
        self.lcd = LCD(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7, lcd_columns, lcd_rows, lcd_backlight, gpio=aGPIO.get_platform_gpio())
        self.lcd.clear()
        self._columns = lcd_columns
        self._in_progress = None 
開發者ID:EricssonResearch,項目名稱:calvin-base,代碼行數:7,代碼來源:NOplate.py

示例13: __init__

# 需要導入模塊: import Adafruit_GPIO [as 別名]
# 或者: from Adafruit_GPIO import get_platform_gpio [as 別名]
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)) 
開發者ID:adafruit,項目名稱:Adafruit_Python_CharLCD,代碼行數:52,代碼來源:Adafruit_CharLCD.py

示例14: __init__

# 需要導入模塊: import Adafruit_GPIO [as 別名]
# 或者: from Adafruit_GPIO import get_platform_gpio [as 別名]
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
        if not self._rst is None:
            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) 
開發者ID:adafruit,項目名稱:Adafruit_Python_SSD1306,代碼行數:46,代碼來源:SSD1306.py

示例15: __init__

# 需要導入模塊: import Adafruit_GPIO [as 別名]
# 或者: from Adafruit_GPIO import get_platform_gpio [as 別名]
def __init__(self, tc_type=MAX31856_T_TYPE, avgsel=0x0, software_spi=None, hardware_spi=None, gpio=None):
        """
        Initialize MAX31856 device with software SPI on the specified CLK,
        CS, and DO pins.  Alternatively can specify hardware SPI by sending an
        SPI.SpiDev device in the spi parameter.

        Args:
            tc_type (1-byte Hex): Type of Thermocouple.  Choose from class variables of the form
                MAX31856.MAX31856_X_TYPE.
            avgsel (1-byte Hex): Type of Averaging.  Choose from values in CR0 table of datasheet.
                Default is single sample.
            software_spi (dict): Contains the pin assignments for software SPI, as defined below:
                clk (integer): Pin number for software SPI clk
                cs (integer): Pin number for software SPI cs
                do (integer): Pin number for software SPI MISO
                di (integer): Pin number for software SPI MOSI
            hardware_spi (SPI.SpiDev): If using hardware SPI, define the connection
        """
        self._logger = logging.getLogger('Adafruit_MAX31856.MAX31856')
        self._spi = None
        self.tc_type = tc_type
        self.avgsel = avgsel
        # Handle hardware SPI
        if hardware_spi is not None:
            self._logger.debug('Using hardware SPI')
            self._spi = hardware_spi
        elif software_spi is not None:
            self._logger.debug('Using software SPI')
            # Default to platform GPIO if not provided.
            if gpio is None:
                gpio = Adafruit_GPIO.get_platform_gpio()
            self._spi = SPI.BitBang(gpio, software_spi['clk'], software_spi['di'],
                                                  software_spi['do'], software_spi['cs'])
        else:
            raise ValueError(
                'Must specify either spi for for hardware SPI or clk, cs, and do for softwrare SPI!')
        self._spi.set_clock_hz(5000000)
        # According to Wikipedia (on SPI) and MAX31856 Datasheet:
        #   SPI mode 1 corresponds with correct timing, CPOL = 0, CPHA = 1
        self._spi.set_mode(1)
        self._spi.set_bit_order(SPI.MSBFIRST)

        self.cr1 = ((self.avgsel << 4) + self.tc_type)

        # Setup for reading continuously with T-Type thermocouple
        self._write_register(self.MAX31856_REG_WRITE_CR0, self.MAX31856_CR0_READ_CONT)
        self._write_register(self.MAX31856_REG_WRITE_CR1, self.cr1) 
開發者ID:johnrbnsn,項目名稱:Adafruit_Python_MAX31856,代碼行數:49,代碼來源:max31856.py


注:本文中的Adafruit_GPIO.get_platform_gpio方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。