本文整理汇总了Python中Adafruit_GPIO.SPI.SpiDev方法的典型用法代码示例。如果您正苦于以下问题:Python SPI.SpiDev方法的具体用法?Python SPI.SpiDev怎么用?Python SPI.SpiDev使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Adafruit_GPIO.SPI
的用法示例。
在下文中一共展示了SPI.SpiDev方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_if_listening_enabled
# 需要导入模块: from Adafruit_GPIO import SPI [as 别名]
# 或者: from Adafruit_GPIO.SPI import SpiDev [as 别名]
def check_if_listening_enabled(self):
if self.data.settings['user_input']['ANALOG_INPUT']['value'] == 'enabled':
if not self.analog_input:
try:
## note - using software spi for now although on the same pins as the hardware spi described below because hardware spi wasnt working with lcd display
#SPI_PORT = 1
#SPI_DEVICE = 2
#self.analog_input = Adafruit_MCP3008.MCP3008(spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE))
CLK = 21
MISO = 19
MOSI = 20
CS = 16
self.analog_input = Adafruit_MCP3008.MCP3008(clk=CLK, cs=CS, miso=MISO, mosi=MOSI)
except:
self.message_handler('INFO', 'analog inputs not connected')
self.poll_analog_inputs()
else:
self.root.after(1000, self.check_if_listening_enabled)
示例2: test_hardware_spi_initialize
# 需要导入模块: from Adafruit_GPIO import SPI [as 别名]
# 或者: from Adafruit_GPIO.SPI import SpiDev [as 别名]
def test_hardware_spi_initialize(self):
"""
Checks to see if the sensor can initialize on the hardware SPI interface.
Will fail if it cannot find the MAX31856 library or any dependencies.
Test only checks to see that the sensor can be initialized in Software, does not check the
hardware connection.
"""
_logger.debug('test_hardware_SPI_initialize()')
# Raspberry Pi hardware SPI configuration.
spi_port = 0
spi_device = 0
sensor = MAX31856(hardware_spi=SPI.SpiDev(spi_port, spi_device))
if sensor:
self.assertTrue(True)
else:
self.assertTrue(False)
示例3: test_get_temperaure_reading
# 需要导入模块: from Adafruit_GPIO import SPI [as 别名]
# 或者: from Adafruit_GPIO.SPI import SpiDev [as 别名]
def test_get_temperaure_reading(self):
"""
Checks to see if we can read a temperature from the board, using Hardware SPI
"""
_logger.debug('test_get_temperaure_reading')
# Raspberry Pi hardware SPI configuration.
spi_port = 0
spi_device = 0
sensor = MAX31856(hardware_spi=SPI.SpiDev(spi_port, spi_device))
temp = sensor.read_temp_c()
if temp:
self.assertTrue(True)
else:
self.assertTrue(False)
示例4: test_get_internal_temperaure_reading
# 需要导入模块: from Adafruit_GPIO import SPI [as 别名]
# 或者: from Adafruit_GPIO.SPI import SpiDev [as 别名]
def test_get_internal_temperaure_reading(self):
"""
Checks to see if we can read a temperature from the board, using Hardware SPI
"""
_logger.debug('test_get_internal_temperature_reading()')
# Raspberry Pi hardware SPI configuration.
spi_port = 0
spi_device = 0
sensor = MAX31856(hardware_spi=SPI.SpiDev(spi_port, spi_device))
temp = sensor.read_internal_temp_c()
if temp:
self.assertTrue(True)
else:
self.assertTrue(False)
示例5: main
# 需要导入模块: from Adafruit_GPIO import SPI [as 别名]
# 或者: from Adafruit_GPIO.SPI import SpiDev [as 别名]
def main():
# Get bus address if provided or use default address
SPI_DEVICE = 0
if len(sys.argv) >= 2:
SPI_DEVICE = int(sys.argv[1], 0)
if not 0 <= SPI_DEVICE <= 1:
raise ValueError("Invalid address value")
# Raspberry Pi hardware SPI configuration.
SPI_PORT = 0
sensor = MAX31855.MAX31855(spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE))
temp = sensor.readTempC()
print('{0:0.1f}'.format(temp))
示例6: _get_mcp
# 需要导入模块: from Adafruit_GPIO import SPI [as 别名]
# 或者: from Adafruit_GPIO.SPI import SpiDev [as 别名]
def _get_mcp(self):
import Adafruit_GPIO.SPI as SPI
import Adafruit_MCP3008
if self.mode == MCP3008Mode.SOFTWARE:
self.mcp = Adafruit_MCP3008.MCP3008(clk=self.CLK, cs=self.CS,
miso=self.MISO, mosi=self.MOSI)
elif self.mode == MCP3008Mode.HARDWARE:
self.mcp = Adafruit_MCP3008.MCP3008(spi=SPI.SpiDev(self.spi_port, self.spi_device))
else:
raise RuntimeError('Unsupported MCP3008 mode: {}'.format(self.mode))
return self.mcp
示例7: test_get_register_reading
# 需要导入模块: from Adafruit_GPIO import SPI [as 别名]
# 或者: from Adafruit_GPIO.SPI import SpiDev [as 别名]
def test_get_register_reading(self):
"""
Checks to see if we can read a register from the device. Good test for correct
connectivity.
"""
_logger.debug('test_get_register_reading()')
# Raspberry Pi hardware SPI configuration.
spi_port = 0
spi_device = 0
sensor = MAX31856(hardware_spi=SPI.SpiDev(spi_port, spi_device))
value = sensor._read_register(MAX31856.MAX31856_REG_READ_CR0)
for ii in range(0x00, 0x10):
# Read all of the registers, will store data to log
sensor._read_register(ii) # pylint: disable-msg=protected-access
if value:
self.assertTrue(True)
else:
self.assertTrue(False)
#def test_get_temperaure_reading_software_spi(self):
#"""Checks to see if we can read a temperature from the board, using software SPI
#"""
#_logger.debug('test_get_temperature_reading_software_spi')
## Raspberry Pi software SPI configuration.
#software_spi = {"clk": 25, "cs": 8, "do": 9, "di": 10}
#sensor = MAX31856(software_spi=software_spi)
#temp = sensor.read_temp_c()
#if temp:
#self.assertTrue(True)
#else:
#self.assertTrue(False)
示例8: __init__
# 需要导入模块: from Adafruit_GPIO import SPI [as 别名]
# 或者: from Adafruit_GPIO.SPI import SpiDev [as 别名]
def __init__(self, channel):
self.curVal = 0.0
self.channel = channel
self.mcp = Adafruit_MCP3008.MCP3008(spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE))
示例9: __init__
# 需要导入模块: from Adafruit_GPIO import SPI [as 别名]
# 或者: from Adafruit_GPIO.SPI import SpiDev [as 别名]
def __init__(self, pot_channel, cv_channel, minimum, maximum, init_val=0.0):
self.minimum = minimum
self.maximum = maximum
self.range = maximum - minimum
self.curVal = minimum
self.cv_offset = 0.011
self.pot_channel = pot_channel
self.cv_channel = cv_channel
self.hist = []
self.hist_size = 8
self.hist_idx = 0
self.average = 0.0
self.raw_pot = init_val
self.raw_cv = init_val
self.static_pot = init_val
self.resist_val = 0
self.resisting_change = False
self.ignoring_pot = False
self.curminpot = self.raw_pot / 4095
self.curmaxpot = self.raw_pot / 4095
self.curmincv = 2048
self.curmaxcv = 2048
self.count = 0
self.filtPotVal = 0
self.filtCVVal = 0
#self.smoothCoeff = 0.125
self.smoothCoeff = 0.33
self.hyst_amt = 0.002
self.stablized = True
self.stable_delta = 0.0
self.last_in = 0.0
if (pot_channel >= 0):
self.mcp_pot = MCP3208.MCP3208(spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE_POT))
if (cv_channel >= 0):
self.mcp_cv = MCP3208.MCP3208(spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE_CV))
示例10: __init__
# 需要导入模块: from Adafruit_GPIO import SPI [as 别名]
# 或者: from Adafruit_GPIO.SPI import SpiDev [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)