本文整理汇总了Python中Adafruit_BBIO.SPI.SPI.open方法的典型用法代码示例。如果您正苦于以下问题:Python SPI.open方法的具体用法?Python SPI.open怎么用?Python SPI.open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Adafruit_BBIO.SPI.SPI
的用法示例。
在下文中一共展示了SPI.open方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: print_single_status_line
# 需要导入模块: from Adafruit_BBIO.SPI import SPI [as 别名]
# 或者: from Adafruit_BBIO.SPI.SPI import open [as 别名]
#.........这里部分代码省略.........
ce_pin is optional GPIO pin number for CE signal
irq_pin is optional GPIO pin number for IRQ signal"""
# defaults and miscelaneous initialization
self.payload_size = 32 # *< Fixed size of payloads
self.ack_payload_available = False # *< Whether there is an ack payload waiting
self.dynamic_payloads_enabled = False # *< Whether dynamic payloads are enabled.
self.ack_payload_length = 5 # *< Dynamic size of pending ack payload.
self.pipe0_reading_address = None # *< Last address set on pipe 0 for reading.
self.spidev = None
self.last_error = 0
self.auto_ack = 0
self.address_length = 5
# If all parameters are available, lets start the radio!
if major is not None and minor is not None and irq_pin is not None:
self.begin(major, minor, ce_pin, irq_pin)
def begin(self, major, minor, ce_pin, irq_pin):
"""Radio initialization, must be called before anything else.
major and minor selects SPI port,
ce_pin is GPIO pin number for CE signal
irq_pin is optional GPIO pin number for IRQ signal"""
# Initialize SPI bus
if ADAFRUID_BBIO_SPI:
self.spidev = SPI(major, minor)
self.spidev.bpw = 8
try:
self.spidev.msh = 10000000 # Maximum supported by NRF24L01+
except IOError:
pass # Hardware does not support this speed
else:
self.spidev = spidev.SpiDev()
self.spidev.open(major, minor)
self.spidev.bits_per_word = 8
try:
self.spidev.max_speed_hz = 10000000 # Maximum supported by NRF24L01+
except IOError:
pass # Hardware does not support this speed
self.spidev.cshigh = False
self.spidev.mode = 0
self.spidev.loop = False
self.spidev.lsbfirst = False
self.spidev.threewire = False
# Save pin numbers
self.ce_pin = ce_pin
self.irq_pin = irq_pin
# If CE pin is not used, CE signal must be always high
if self.ce_pin is not None:
GPIO.setup(self.ce_pin, GPIO.OUT)
# IRQ pin is optional
if self.irq_pin is not None:
GPIO.setup(self.irq_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
time.sleep(5 / 1000000.0)
# Reset radio registers
self.reset()
# Restore our default PA level
self.setPALevel(NRF24.PA_MAX)
示例2: print_single_status_line
# 需要导入模块: from Adafruit_BBIO.SPI import SPI [as 别名]
# 或者: from Adafruit_BBIO.SPI.SPI import open [as 别名]
#.........这里部分代码省略.........
self.ce_pin = "P9_15"
self.irq_pin = "P9_16"
self.channel = 76
self.data_rate = NRF24.BR_1MBPS
self.data_rate_bits = 1000
self.p_variant = False # False for RF24L01 and true for RF24L01P
self.payload_size = 5 # *< Fixed size of payloads
self.ack_payload_available = False # *< Whether there is an ack payload waiting
self.dynamic_payloads_enabled = False # *< Whether dynamic payloads are enabled.
self.ack_payload_length = 5 # *< Dynamic size of pending ack payload.
self.pipe0_reading_address = None # *< Last address set on pipe 0 for reading.
self.spidev = None
self.last_error = 0
self.crc_length = 0
self.auto_ack = 0x3F
self.address_length = 5
# If all parameters are available, lets start the radio!
if major is not None and minor is not None and irq_pin is not None:
self.begin(major, minor, ce_pin, irq_pin)
def begin(self, major, minor, ce_pin, irq_pin):
# Initialize SPI bus
if ADAFRUID_BBIO_SPI:
self.spidev = SPI(major, minor)
self.spidev.bpw = 8
try:
self.spidev.msh = 10000000 # Maximum supported by NRF24L01+
except IOError:
pass # Hardware does not support this speed
else:
self.spidev = spidev.SpiDev()
self.spidev.open(major, minor)
self.spidev.bits_per_word = 8
try:
self.spidev.max_speed_hz = 10000000 # Maximum supported by NRF24L01+
except IOError:
pass # Hardware does not support this speed
self.spidev.cshigh = False
self.spidev.mode = 0
self.spidev.loop = False
self.spidev.lsbfirst = False
self.spidev.threewire = False
self.ce_pin = ce_pin
self.irq_pin = irq_pin
if self.ce_pin is not None:
GPIO.setup(self.ce_pin, GPIO.OUT)
GPIO.setup(self.irq_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
time.sleep(5 / 1000000.0)
# Reset radio configuration
self.reset()
# Set 1500uS (minimum for 32B payload in [email protected]) timeouts, to make testing a little easier
# WARNING: If this is ever lowered, either 250KBS mode with AA is broken or maximum packet
# sizes must never be used. See documentation for a more complete explanation.
self.setRetries(int('0101', 2), 15)
示例3: LED_LPD8806
# 需要导入模块: from Adafruit_BBIO.SPI import SPI [as 别名]
# 或者: from Adafruit_BBIO.SPI.SPI import open [as 别名]
class LED_LPD8806(object):
# Constructor
def __init__(self):
self.spi = SPI(0,0) #/dev/spidev1.0 (be sure to run Python with su if 'no permission'
self.spi.msh=1000000 #SPI clock set to 1MHz (slowed from 10MHz for better stability across setups)
self.spi.bpw = 8 # bits per word
self.spi.threewire = False # not half-duplex
self.spi.lsbfirst = False # we want MSB first
self.spi.mode = 0 # options are modes 0 through 3
self.spi.cshigh = False # we want chip select to be active low
self.spi.open(0,0) # make it so
time.sleep(0.05)
def setup(self, led_pixels, debug=False):
if (debug):
print "Initializing LED strip"
global pixels
pixels = [[0x80 for x in range(3)] for y in range(led_pixels)]
for i in range(led_pixels):
pixels[i]=[0x00, 0x00, 0x00]
# Define LED functions:
# --------------------
# Update pixel display with a given delay time between pixel updates:
def writestrip(self, delay):
if (delay < 0):
delay = 0
for i in range(len(pixels)):
self.spi.writebytes([0x00, 0x00, 0x00]) #prepare write
for i in range(len(pixels)):
self.spi.writebytes(pixels[i]) #write colors to pixels
time.sleep(delay)
# Turn off all LEDs:
def clearstrip(self):
global pixels
for i in range(len(pixels)):
self.spi.writebytes([0x00, 0x00, 0x00]) #prepare write
for i in range(len(pixels)):
pixels[i] = [0x80, 0x80, 0x80]
self.writestrip(0)
# Set an individual pixel to a specific color (to display later):
def setpixelcolor(self, n, g, r, b):
global pixels
if (n >= len(pixels)):
return
if (n < 0):
return
if (g > 0xFF):
g = 0xFF
if (g < 0x80):
g = 0x80
if (r > 0xFF):
r = 0xFF
if (r < 0x80):
r = 0x80
if (b > 0xFF):
b = 0xFF
if (b < 0x80):
b = 0x80
pixels[n] = [g, r, b]
# Update display with warmer colors (more red light) by a specified amount with a delay between pixels
def warmstrip(self, warmth, delay):
global pixels
if (delay < 0):
delay = 0
for n in range(len(pixels)):
if((pixels[n][1] + warmth) < 0x80):
pixels[n][1] = 0x80
elif((pixels[n][2] + warmth) > 0xFF):
pixels[n][1] = 0xFF
else:
pixels[n][1] = pixels[n][1]+warmth
self.writestrip(delay)
# Update display with cooler colors (more blue) by a specified amount with a delay between each pixel
def coolstrip(self, coolfactor, delay):
global pixels
if (delay < 0):
delay = 0
for n in range(len(pixels)):
if((pixels[n][2] + coolfactor) < 0x80):
pixels[n][2] = 0x80
elif((pixels[n][2] + coolfactor) > 0xFF):
pixels[n][2] = 0xFF
else:
pixels[n][2] = pixels[n][2]+coolfactor
self.writestrip(delay)
# Update display with greener colors by a specified amount with a set delay between each pixel
def greenstrip(self, lushness, delay):
global pixels
if (delay < 0):
delay = 0
for n in range(len(pixels)):
#.........这里部分代码省略.........
示例4: SPI
# 需要导入模块: from Adafruit_BBIO.SPI import SPI [as 别名]
# 或者: from Adafruit_BBIO.SPI.SPI import open [as 别名]
from Adafruit_BBIO.SPI import SPI
spi = SPI(0,0)
spi.open(0,0)
#spi.msh = 100000
spi.bpw = 8
#spi.mode = b00
try:
#while True:
# set CS bit high, choose first channel to read from
#channel = 0;
#adc = spi.xfer([1,8,0])
#data = ((adc[1]&3) << 8) + adc[2]
channelSelect = 0xC0
channelSelect |= 0x18
channelSelect <<= 3
fsr = spi.xfer2([channelSelect, 0x00, 0x00])
#result = spi.readbytes(2)
#result2 = spi.readbytes(1)
resultFinal = 0x0000
resultFinal = 0x0300 & (resultFinal | (fsr[1] << 8 ))
resultFinal |= ( ( 0x00FF & fsr[2]) )
#print (8 + channel ) << 4
#print resultFinal
###################################
####################################
resultFinal = 1 #temp
示例5: SPI
# 需要导入模块: from Adafruit_BBIO.SPI import SPI [as 别名]
# 或者: from Adafruit_BBIO.SPI.SPI import open [as 别名]
from Adafruit_BBIO.SPI import SPI
spi = SPI(1,0)
spi.mode=2
spi.msh=200000
spi.open(1,0)
print spi.readbytes(4)
#print spi.xfer2([32, 11, 110, 22, 220])
spi.close()