本文整理汇总了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 ]
示例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)
示例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)
示例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)
示例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)
示例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)
示例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))
示例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)
示例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)
示例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)
示例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)
示例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
示例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))
示例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)
示例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)