本文整理汇总了Python中spidev.SpiDev方法的典型用法代码示例。如果您正苦于以下问题:Python spidev.SpiDev方法的具体用法?Python spidev.SpiDev怎么用?Python spidev.SpiDev使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类spidev
的用法示例。
在下文中一共展示了spidev.SpiDev方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_spi
# 需要导入模块: import spidev [as 别名]
# 或者: from spidev import SpiDev [as 别名]
def get_spi(self):
spi = None
try:
spi = spidev.SpiDev()
bus = 0
device = 0
spi.open(bus, device)
spi.max_speed_hz = 10000000
spi.mode = 0b00
spi.lsbfirst = False
except Exception as e:
print(e)
GPIO.cleanup()
if spi:
spi.close()
spi = None
return spi
# https://www.raspberrypi.org/documentation/hardware/raspberrypi/spi/README.md
# https://www.raspberrypi.org/forums/viewtopic.php?f=44&t=19489
示例2: readadc
# 需要导入模块: import spidev [as 别名]
# 或者: from spidev import SpiDev [as 别名]
def readadc(adcnum):
spi = spidev.SpiDev()
spi.open(0,0)
# read SPI data from MCP3004 chip, 4 possible adc’s (0 thru 3)
if ((adcnum > 3) or (adcnum < 0)):
return-1
r = spi.xfer2([1,8+adcnum <<4,0])
#print(r)
adcout = ((r[1] &3) <<8)+r[2]
return adcout
示例3: __init__
# 需要导入模块: import spidev [as 别名]
# 或者: from spidev import SpiDev [as 别名]
def __init__(self, partial_refresh_limit=32, fast_refresh=True):
""" Initialize the EPD class.
`partial_refresh_limit` - number of partial refreshes before a full refrersh is forced
`fast_frefresh` - enable or disable the fast refresh mode,
see smart_update() method documentation for details"""
self.width = EPD_WIDTH
""" Display width, in pixels """
self.height = EPD_HEIGHT
""" Display height, in pixels """
self.fast_refresh = fast_refresh
""" enable or disable the fast refresh mode """
self.partial_refresh_limit = partial_refresh_limit
""" number of partial refreshes before a full refrersh is forced """
self._last_frame = None
self._partial_refresh_count = 0
self._init_performed = False
self.spi = spidev.SpiDev(0, 0)
示例4: get_spi
# 需要导入模块: import spidev [as 别名]
# 或者: from spidev import SpiDev [as 别名]
def get_spi(self):
spi = None
try:
spi = spidev.SpiDev()
bus = 0
device = 0
spi.open(bus, device)
spi.max_speed_hz = 10000000
spi.mode = 0b00
spi.lsbfirst = False
except Exception as e:
print(e)
GPIO.cleanup()
if spi:
spi.close()
spi = None
return spi
# https://www.raspberrypi.org/documentation/hardware/raspberrypi/spi/README.md
# https://www.raspberrypi.org/forums/viewtopic.php?f=44&t=19489
示例5: main
# 需要导入模块: import spidev [as 别名]
# 或者: from spidev import SpiDev [as 别名]
def main(speed = 500000):
spi = None
try:
spi = spidev.SpiDev()
except Exception as e:
print(e)
spi = prepare_spi(spi, speed)
orig = [i for i in range(128)] * 30
result = spi.transfer(orig)
# print(orig)
# print(result)
count_all, count_err, error_ratio = cal_error_rate(orig, result)
print('count_all: {}, count_err: {}, error_ratio: {}'.format(count_all, count_err, error_ratio))
if spi: spi.close()
示例6: sysInfo
# 需要导入模块: import spidev [as 别名]
# 或者: from spidev import SpiDev [as 别名]
def sysInfo(eth0info, wlan0info):
bus, device = 0, 0
spi = SPI.SpiDev(bus, device)
display = Epd(spi, DISPLAY_TYPE)
display.clearDisplayPart()
height, width = display.size
# canvas to draw to
image = Image.new('1', display.size, WHITE)
# add some text to it
info = eth0info + wlan0info
text = Text(width, height, info, chars=24)
image.paste(text.image, (0, 0, height, width), mask=BLACK)
# send image to display
display.showImageFull(display.imageToPixelArray(image))
示例7: main
# 需要导入模块: import spidev [as 别名]
# 或者: from spidev import SpiDev [as 别名]
def main():
bus, device = 0, 0
spi = SPI.SpiDev(bus, device)
display = Epd(spi, DISPLAY_TYPE)
print('--> Init and clear full screen %s' % display.size)
display.clearDisplayPart()
height, width = display.size
# canvas to draw to
image = Image.new('1', display.size, WHITE)
# add some text to it
text = Text(width, height, "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.", chars=24)
image.paste(text.image, (0, 0, height, width), mask=BLACK)
# send image to display
display.showImageFull(display.imageToPixelArray(image))
# main
示例8: __init__
# 需要导入模块: import spidev [as 别名]
# 或者: from spidev import SpiDev [as 别名]
def __init__(self, port, device, max_speed_hz=500000):
"""Initialize an SPI device using the SPIdev interface. Port and device
identify the device, for example the device /dev/spidev1.0 would be port
1 and device 0.
"""
import spidev
self._device = spidev.SpiDev()
self._device.open(port, device)
self._device.max_speed_hz=max_speed_hz
# Default to mode 0, and make sure CS is active low.
self._device.mode = 0
self._device.cshigh = False
示例9: __init__
# 需要导入模块: import spidev [as 别名]
# 或者: from spidev import SpiDev [as 别名]
def __init__(self, num_led, global_brightness=MAX_BRIGHTNESS,
order='rgb', bus=0, device=1, max_speed_hz=8000000):
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
self.spi = spidev.SpiDev() # Init the SPI device
self.spi.open(bus, device) # Open SPI port 0, slave device (CS) 1
# Up the speed a bit, so that the LEDs are painted faster
if max_speed_hz:
self.spi.max_speed_hz = max_speed_hz
示例10: __init__
# 需要导入模块: import spidev [as 别名]
# 或者: from spidev import SpiDev [as 别名]
def __init__(self, num_led, global_brightness=MAX_BRIGHTNESS,
order='rgb', bus=0, device=1, max_speed_hz=8000000, endFrame=255):
self.num_led = num_led # The number of LEDs in the Strip
self._endFrame = endFrame
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
self.spi = spidev.SpiDev() # Init the SPI device
self.spi.open(bus, device) # Open SPI port 0, slave device (CS) 1
# Up the speed a bit, so that the LEDs are painted faster
if max_speed_hz:
self.spi.max_speed_hz = max_speed_hz
示例11: setup
# 需要导入模块: import spidev [as 别名]
# 或者: from spidev import SpiDev [as 别名]
def setup(self):
"""Set up Inky GPIO and reset display."""
if not self._gpio_setup:
if self._gpio is None:
try:
import RPi.GPIO as GPIO
self._gpio = GPIO
except ImportError:
raise ImportError('This library requires the RPi.GPIO module\nInstall with: sudo apt install python-rpi.gpio')
self._gpio.setmode(self._gpio.BCM)
self._gpio.setwarnings(False)
self._gpio.setup(self.dc_pin, self._gpio.OUT, initial=self._gpio.LOW, pull_up_down=self._gpio.PUD_OFF)
self._gpio.setup(self.reset_pin, self._gpio.OUT, initial=self._gpio.HIGH, pull_up_down=self._gpio.PUD_OFF)
self._gpio.setup(self.busy_pin, self._gpio.IN, pull_up_down=self._gpio.PUD_OFF)
if self._spi_bus is None:
import spidev
self._spi_bus = spidev.SpiDev()
self._spi_bus.open(0, self.cs_channel)
self._spi_bus.max_speed_hz = 488000
self._gpio_setup = True
self._gpio.output(self.reset_pin, self._gpio.LOW)
time.sleep(0.1)
self._gpio.output(self.reset_pin, self._gpio.HIGH)
time.sleep(0.1)
self._send_command(0x12) # Soft Reset
self._busy_wait()
示例12: __init__
# 需要导入模块: import spidev [as 别名]
# 或者: from spidev import SpiDev [as 别名]
def __init__(self, cs=None):
self.spi = spidev.SpiDev(0, 0)
GPIO.setmode(GPIO.BCM)
self._cs = cs
if cs:
GPIO.setup(self._cs, GPIO.OUT)
GPIO.output(self._cs, GPIO.HIGH)
self.spi.max_speed_hz = 1000000
self.spi.mode = 0b10 # CPOL=1 & CPHA=0
示例13: __init__
# 需要导入模块: import spidev [as 别名]
# 或者: from spidev import SpiDev [as 别名]
def __init__(self, gainFactor=1):
"""
Class Constructor - Define SPI bus and init
:param gainFactor: Set the DAC's gain factor. The value should
be 1 or 2. Gain factor is used to determine output voltage
from the formula: Vout = G * Vref * D/4096
Where G is gain factor, Vref (for this chip) is 2.048 and
D is the 12-bit digital value, defaults to 1
:type gainFactor: int, optional
:raises ValueError: DAC __init__: Invalid gain factor. Must be 1 or 2
"""
# Define SPI bus and init
self.__spiDAC = spidev.SpiDev()
self.__spiDAC.open(0, 1)
self.__spiDAC.max_speed_hz = (20000000)
if (gainFactor != 1) and (gainFactor != 2):
raise ValueError('DAC __init__: Invalid gain factor. \
Must be 1 or 2')
else:
self.gain = gainFactor
self.maxdacvoltage = self.__dacMaxOutput__[self.gain]
示例14: __init__
# 需要导入模块: import spidev [as 别名]
# 或者: from spidev import SpiDev [as 别名]
def __init__(self, gainFactor=1):
"""Class Constructor
gainFactor -- Set the DAC's gain factor. The value should
be 1 or 2. Gain factor is used to determine output voltage
from the formula: Vout = G * Vref * D/4096
Where G is gain factor, Vref (for this chip) is 2.048 and
D is the 12-bit digital value
"""
# Define SPI bus and init
self.__spiDAC = spidev.SpiDev()
self.__spiDAC.open(0, 1)
self.__spiDAC.max_speed_hz = (20000000)
if (gainFactor != 1) and (gainFactor != 2):
raise ValueError('DAC __init__: Invalid gain factor. \
Must be 1 or 2')
else:
self.gain = gainFactor
self.maxdacvoltage = self.__dacMaxOutput__[self.gain]
示例15: setup
# 需要导入模块: import spidev [as 别名]
# 或者: from spidev import SpiDev [as 别名]
def setup():
"""Initialize Unicorn HAT HD."""
global _spi, _buf, is_setup
if is_setup:
return
_spi = spidev.SpiDev()
_spi.open(0, 0)
_spi.max_speed_hz = 9000000
is_setup = True