当前位置: 首页>>代码示例>>Python>>正文


Python SPI.BitBang方法代码示例

本文整理汇总了Python中Adafruit_GPIO.SPI.BitBang方法的典型用法代码示例。如果您正苦于以下问题:Python SPI.BitBang方法的具体用法?Python SPI.BitBang怎么用?Python SPI.BitBang使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Adafruit_GPIO.SPI的用法示例。


在下文中一共展示了SPI.BitBang方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_mode_0_read

# 需要导入模块: from Adafruit_GPIO import SPI [as 别名]
# 或者: from Adafruit_GPIO.SPI import BitBang [as 别名]
def test_mode_0_read(self):
        gpio = MockGPIO()
        device = SPI.BitBang(gpio, 1, 2, 3, 4)
        gpio.pin_read[3] = [0, 0, 0, 1, 1, 1, 1, 1]
        result = device.read(1)
        # Verify clock
        self.assertListEqual(gpio.pin_written[1], [0, 1, 0, 1, 0, 1, 0, 1,
                                                   0, 1, 0, 1, 0, 1, 0, 1, 0])
        # Verify MOSI
        self.assertNotIn(2, gpio.pin_written)
        # Verify MISO
        self.assertNotIn(3, gpio.pin_written)
        # Verify SS
        self.assertListEqual(gpio.pin_written[4], [1, 0, 1])
        # Verify result
        self.assertEqual(result, bytearray([0x1F])) 
开发者ID:adafruit,项目名称:Adafruit_Python_GPIO,代码行数:18,代码来源:test_SPI.py

示例2: test_read_multiple_bytes

# 需要导入模块: from Adafruit_GPIO import SPI [as 别名]
# 或者: from Adafruit_GPIO.SPI import BitBang [as 别名]
def test_read_multiple_bytes(self):
        gpio = MockGPIO()
        device = SPI.BitBang(gpio, 1, 2, 3, 4)
        gpio.pin_read[3] = [0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0,
                            0, 0, 0, 1, 1, 1, 1, 1]
        result = device.read(3)
        # Verify clock
        self.assertListEqual(gpio.pin_written[1], [0, 1, 0, 1, 0, 1, 0, 1,
                                                   0, 1, 0, 1, 0, 1, 0, 1,
                                                   0, 1, 0, 1, 0, 1, 0, 1,
                                                   0, 1, 0, 1, 0, 1, 0, 1,
                                                   0, 1, 0, 1, 0, 1, 0, 1,
                                                   0, 1, 0, 1, 0, 1, 0, 1, 0])
        # Verify MOSI
        self.assertNotIn(2, gpio.pin_written)
        # Verify MISO
        self.assertNotIn(3, gpio.pin_written)
        # Verify SS
        self.assertListEqual(gpio.pin_written[4], [1, 0, 1])
        # Verify result
        self.assertEqual(result, bytearray([0x1F, 0xF8, 0x1F])) 
开发者ID:adafruit,项目名称:Adafruit_Python_GPIO,代码行数:23,代码来源:test_SPI.py

示例3: test_write_multiple_bytes

# 需要导入模块: from Adafruit_GPIO import SPI [as 别名]
# 或者: from Adafruit_GPIO.SPI import BitBang [as 别名]
def test_write_multiple_bytes(self):
        gpio = MockGPIO()
        device = SPI.BitBang(gpio, 1, 2, 3, 4)
        device.write([0x1F, 0xF8, 0x1F])
        # Verify clock
        self.assertListEqual(gpio.pin_written[1], [0, 1, 0, 1, 0, 1, 0, 1,
                                                   0, 1, 0, 1, 0, 1, 0, 1,
                                                   0, 1, 0, 1, 0, 1, 0, 1,
                                                   0, 1, 0, 1, 0, 1, 0, 1,
                                                   0, 1, 0, 1, 0, 1, 0, 1,
                                                   0, 1, 0, 1, 0, 1, 0, 1, 0])
        # Verify MOSI
        self.assertListEqual(gpio.pin_written[2], [0, 0, 0, 1, 1, 1, 1, 1,
                                                   1, 1, 1, 1, 1, 0, 0, 0,
                                                   0, 0, 0, 1, 1, 1, 1, 1])
        # Verify MISO
        self.assertNotIn(3, gpio.pin_written)
        # Verify SS
        self.assertListEqual(gpio.pin_written[4], [1, 0, 1]) 
开发者ID:adafruit,项目名称:Adafruit_Python_GPIO,代码行数:21,代码来源:test_SPI.py

示例4: __init__

# 需要导入模块: from Adafruit_GPIO import SPI [as 别名]
# 或者: from Adafruit_GPIO.SPI import BitBang [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

示例5: __init__

# 需要导入模块: from Adafruit_GPIO import SPI [as 别名]
# 或者: from Adafruit_GPIO.SPI import BitBang [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

示例6: __init__

# 需要导入模块: from Adafruit_GPIO import SPI [as 别名]
# 或者: from Adafruit_GPIO.SPI import BitBang [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

示例7: __init__

# 需要导入模块: from Adafruit_GPIO import SPI [as 别名]
# 或者: from Adafruit_GPIO.SPI import BitBang [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

示例8: __init__

# 需要导入模块: from Adafruit_GPIO import SPI [as 别名]
# 或者: from Adafruit_GPIO.SPI import BitBang [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

示例9: __init__

# 需要导入模块: from Adafruit_GPIO import SPI [as 别名]
# 或者: from Adafruit_GPIO.SPI import BitBang [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

示例10: test_pin_modes_set_correctly

# 需要导入模块: from Adafruit_GPIO import SPI [as 别名]
# 或者: from Adafruit_GPIO.SPI import BitBang [as 别名]
def test_pin_modes_set_correctly(self):
        gpio = MockGPIO()
        device = SPI.BitBang(gpio, 1, 2, 3, 4)
        self.assertDictEqual(gpio.pin_mode, { 1: GPIO.OUT,
                                              2: GPIO.OUT,
                                              3: GPIO.IN,
                                              4: GPIO.OUT }) 
开发者ID:adafruit,项目名称:Adafruit_Python_GPIO,代码行数:9,代码来源:test_SPI.py

示例11: test_ss_set_high_after_initialization

# 需要导入模块: from Adafruit_GPIO import SPI [as 别名]
# 或者: from Adafruit_GPIO.SPI import BitBang [as 别名]
def test_ss_set_high_after_initialization(self):
        gpio = MockGPIO()
        device = SPI.BitBang(gpio, 1, 2, 3, 4)
        self.assertListEqual(gpio.pin_written[4], [1]) 
开发者ID:adafruit,项目名称:Adafruit_Python_GPIO,代码行数:6,代码来源:test_SPI.py

示例12: test_mode_0_write

# 需要导入模块: from Adafruit_GPIO import SPI [as 别名]
# 或者: from Adafruit_GPIO.SPI import BitBang [as 别名]
def test_mode_0_write(self):
        gpio = MockGPIO()
        device = SPI.BitBang(gpio, 1, 2, 3, 4)
        device.write([0x1F])
        # Verify clock
        self.assertListEqual(gpio.pin_written[1], [0, 1, 0, 1, 0, 1, 0, 1,
                                                   0, 1, 0, 1, 0, 1, 0, 1, 0])
        # Verify MOSI
        self.assertListEqual(gpio.pin_written[2], [0, 0, 0, 1, 1, 1, 1, 1])
        # Verify MISO
        self.assertNotIn(3, gpio.pin_written)
        # Verify SS
        self.assertListEqual(gpio.pin_written[4], [1, 0, 1]) 
开发者ID:adafruit,项目名称:Adafruit_Python_GPIO,代码行数:15,代码来源:test_SPI.py

示例13: test_write_assert_deassert_ss_false

# 需要导入模块: from Adafruit_GPIO import SPI [as 别名]
# 或者: from Adafruit_GPIO.SPI import BitBang [as 别名]
def test_write_assert_deassert_ss_false(self):
        gpio = MockGPIO()
        device = SPI.BitBang(gpio, 1, 2, 3, 4)
        device.write([0x1F], assert_ss=False, deassert_ss=False)
        self.assertListEqual(gpio.pin_written[4], [1]) 
开发者ID:adafruit,项目名称:Adafruit_Python_GPIO,代码行数:7,代码来源:test_SPI.py

示例14: test_write_lsbfirst

# 需要导入模块: from Adafruit_GPIO import SPI [as 别名]
# 或者: from Adafruit_GPIO.SPI import BitBang [as 别名]
def test_write_lsbfirst(self):
        gpio = MockGPIO()
        device = SPI.BitBang(gpio, 1, 2, 3, 4)
        device.set_bit_order(SPI.LSBFIRST)
        device.write([0x1F])
        self.assertListEqual(gpio.pin_written[2], [1, 1, 1, 1, 1, 0, 0, 0]) 
开发者ID:adafruit,项目名称:Adafruit_Python_GPIO,代码行数:8,代码来源:test_SPI.py

示例15: test_invalid_bit_order_fails

# 需要导入模块: from Adafruit_GPIO import SPI [as 别名]
# 或者: from Adafruit_GPIO.SPI import BitBang [as 别名]
def test_invalid_bit_order_fails(self):
        gpio = MockGPIO()
        device = SPI.BitBang(gpio, 1, 2, 3, 4)
        self.assertRaises(ValueError, device.set_bit_order, -1)
        self.assertRaises(ValueError, device.set_bit_order, 2) 
开发者ID:adafruit,项目名称:Adafruit_Python_GPIO,代码行数:7,代码来源:test_SPI.py


注:本文中的Adafruit_GPIO.SPI.BitBang方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。