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


Python SPI.SPI类代码示例

本文整理汇总了Python中Adafruit_BBIO.SPI.SPI的典型用法代码示例。如果您正苦于以下问题:Python SPI类的具体用法?Python SPI怎么用?Python SPI使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: DAC

class DAC():
    """ This class uses an actual DAC """

    def __init__(self, channel):
        """ Channel is the pwm output is on (0..15) """
        self.channel = channel
        self.offset = 0.0
        if 'SPI' in globals():
            # init the SPI for the DAC
            try:
                self.spi2_0 = SPI(0, 0)
            except IOError:
                self.spi2_0 = SPI(1, 0)
            self.spi2_0.bpw = 8
            self.spi2_0.mode = 1
        else:
            logging.warning("Unable to set up SPI")
            self.spi2_0 = None

    def set_voltage(self, voltage):
        logging.debug("Setting voltage to "+str(voltage))         
        if self.spi2_0 is None:
            logging.debug("SPI2_0 missing")
            return

        v_ref = 3.3                    # Voltage reference on the DAC
        dacval = int((voltage * 256.0) / v_ref)
        byte1 = ((dacval & 0xF0) >> 4) | (self.channel << 4)
        byte2 = (dacval & 0x0F) << 4
        self.spi2_0.writebytes([byte1, byte2])       # Update all channels
        self.spi2_0.writebytes([0xA0, 0xFF])
开发者ID:RaveGun,项目名称:redeem,代码行数:31,代码来源:DAC.py

示例2: __init__

	def __init__(self, bus):
		# Use Adafruit_BBIO.SPI to initialize the cap
		# and the spi bus configuration
		s = SPI(bus, self.__DEVICE)
		s.msh = self.__SPEED
		s.mode = self.__MODE
		s.close()

		# Use normal file for writing bytes
		dev = '/dev/spidev%s.%s' % (bus + 1, self.__DEVICE)
		self.spi = open(dev, 'wb')
		print 'Opened %s, Freq: %sHz' % (dev, self.__SPEED)
开发者ID:flaub,项目名称:tikitank,代码行数:12,代码来源:leds.py

示例3: __init__

 def __init__(self, channel):
     """ Channel is the pwm output is on (0..15) """
     self.channel = channel
     self.offset = 0.0
     if 'SPI' in globals():
         # init the SPI for the DAC
         try:
             self.spi2_0 = SPI(0, 0)
         except IOError:
             self.spi2_0 = SPI(1, 0)
         self.spi2_0.bpw = 8
         self.spi2_0.mode = 1
     else:
         logging.warning("Unable to set up SPI")
         self.spi2_0 = None
开发者ID:RaveGun,项目名称:redeem,代码行数:15,代码来源:DAC.py

示例4: MAX7221

class MAX7221(Display.Display):

    def __init__(self, bus, device):
    	super(MAX7221, self).__init__(8, 8)
        SPI(bus, device).mode = 0
        self.spi_bus = SPI(bus, device)
        self.buf = [0, 0, 0, 0, 0, 0, 0, 0]

        self.OP_NOP = 0x0
        self.OP_DIG0 = 0x1
        self.OP_DIG1 = 0x2
        self.OP_DIG2 = 0x3
        self.OP_DIG3 = 0x4
        self.OP_DIG4 = 0x5
        self.OP_DIG5 = 0x6
        self.OP_DIG6 = 0x7
        self.OP_DIG7 = 0x8
        self.OP_DECODEMODE = 0x9
        self.OP_INTENSITY = 0xA
        self.OP_SCANLIMIT = 0xB
        self.OP_SHUTDOWN = 0xC
        self.OP_DISPLAYTEST = 0xF

        self.init()

    def rotate(self, x, n):
        return (x << n) | (x >> (8 - n))

    def init(self):
        self.write_command(self.OP_DISPLAYTEST, 0x0)
        self.write_command(self.OP_SCANLIMIT, 0x7)
        self.write_command(self.OP_DECODEMODE, 0x0)
        self.shutdown(False)
        self.update_display()

    def shutdown(self, off):
        if off:
            off = 0
        else:
            off = 1
        self.write_command(self.OP_SHUTDOWN, off)

    def write_spi(self, reg, data):
        self.spi_bus.writebytes([reg, data])

    def write_command(self, command, arg):
        self.write_spi(command, arg)

    def write_display(self, buffer):
        for col in range(0, len(buffer)):
            self.write_spi(col + 0x1, buffer[col])

    def update_display(self):
        self.write_display(self.buf)

    def draw_pixel(self, x, y, color):
        if color == 1:
            self.buf[y] = self.buf[y] | (1 << x)
        elif color == 0:
            self.buf[y] = self.buf[y] & ~(1 << x)
        self.update_display()

    def draw_fast_hline(self, x, y, w, color):
    	self.write_spi(0x1 + y, (0xFF >> (8 - w)) << x)
开发者ID:tech2077,项目名称:BB-Matrix,代码行数:64,代码来源:MAX7221.py

示例5: setup_spi

 def setup_spi(self):
     #This is for BB Black
     self.spi = SPI(self.spi_bus, self.spi_client)
     self.spi.msh = self.spi_freq
     self.spi.mode = self.spi_mode
     self.bpw = self.spi_bits_per_word
     self.spi.cshigh = self.spi_cshigh
开发者ID:CCATObservatory,项目名称:ccat_bitbang_chips,代码行数:7,代码来源:ltc1858.py

示例6: __init__

    def __init__(self, coarsePin="P9_15", finePin="P9_16", readPin="P9_14", clockRate=100000):
        self.CS_FB_COARSE_PIN = coarsePin
        self.CS_FB_FINE_PIN = finePin
        self.CS_ADC_PIN = readPin
        self.FB_CLK_RATE = clockRate
        
        GPIO.setup(self.CS_FB_COARSE_PIN, GPIO.OUT)
        GPIO.setup(self.CS_FB_FINE_PIN, GPIO.OUT)
        GPIO.setup(self.CS_ADC_PIN, GPIO.OUT)
        self.spi00 = SPI(0,0)
        self.spi00.msh = self.FB_CLK_RATE
        
        self.fname = "dacValues.pyon"

        self.maxDACvalue = (1<<16)-1
        
        # Ca43
        self.kHz_per_mG = -2.45
        # measured
        self.mG_per_mA = 146 / 56.64
        # (sensor+DiffAmp) equivalent : 6.06ohm
        # Verr: voltage of error signal
        self.mA_per_mVerr = 1 / 6.06

        self.mG_per_mVerr = self.mG_per_mA * self.mA_per_mVerr
        self.kHz_per_mVerr = self.kHz_per_mG * self.mG_per_mVerr

        # maximum DAC output: 2.048V
        self.mVDAC_per_DACvalue = 2.048e3 / self.maxDACvalue

        # estimates for the slope qubit_freq'(DACvalue)
        # fine DAC gain 1
        # coarse DAC gain 200
        self.kHz_per_fDACvalue_est = self.kHz_per_mG * self.mG_per_mVerr * self.mVDAC_per_DACvalue
        self.kHz_per_cDACvalue_est = self.kHz_per_mG * self.mG_per_mVerr * 200 * self.mVDAC_per_DACvalue
开发者ID:cjbe,项目名称:artiqDrivers,代码行数:35,代码来源:bStabBb.py

示例7: __init__

 def __init__(self, length, missing):
     # the important piece of this for reuse is setting up the interface
     # the rest sets up the strip of leds for what we intend to do with them
     self.interface = SPI(0,1)
     self.full_length = length
     self.missing_leds = missing
     self.outbuff = [[128, 128, 128]] * length
     self.reset_buffer([128, 128, 128])
开发者ID:dave-block,项目名称:logsup-ledtube,代码行数:8,代码来源:ledtube-hardcode.py

示例8: __init__

  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)
开发者ID:Proj2501,项目名称:LED_LPD8806,代码行数:10,代码来源:LED_LPD8806.py

示例9: begin

    def begin(self, major, minor, ce_pin, irq_pin):
        # Initialize SPI bus
        self.spidev = SPI(major, minor) 
        self.ce_pin = ce_pin
        self.irq_pin = irq_pin

        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)

        # 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.write_register(NRF24.SETUP_RETR, (int('0100', 2) << NRF24.ARD) | (int('1111', 2) << NRF24.ARC))

        # Restore our default PA level
        self.setPALevel(NRF24.PA_MAX)

        # Determine if this is a p or non-p RF24 module and then
        # reset our data rate back to default value. This works
        # because a non-P variant won't allow the data rate to
        # be set to 250Kbps.
        if self.setDataRate(NRF24.BR_250KBPS):
            self.p_variant = True

        # Then set the data rate to the slowest (and most reliable) speed supported by all
        # hardware.
        self.setDataRate(NRF24.BR_1MBPS)

        # Initialize CRC and request 2-byte (16bit) CRC
        self.setCRCLength(NRF24.CRC_16)

        # Disable dynamic payloads, to match dynamic_payloads_enabled setting
        self.write_register(NRF24.DYNPD, 0)

        # Reset current status
        # Notice reset and flush is the last thing we do
        self.write_register(NRF24.STATUS, _BV(NRF24.RX_DR) | _BV(NRF24.TX_DS) | _BV(NRF24.MAX_RT))

        # Set up default configuration.  Callers can always change it later.
        # This channel should be universally safe and not bleed over into adjacent
        # spectrum.
        self.setChannel(self.channel)

        # Flush buffers
        self.flush_rx()
        self.flush_tx()
开发者ID:surveycorps,项目名称:apro-core,代码行数:48,代码来源:nrf24.py

示例10: __init__

	def __init__(self, isRFM69HW=True, interruptPin=DIO0_PIN, csPin=NSS_PIN):
		self._isRFM69HW = isRFM69HW
		self._interruptPin = interruptPin
		self._csPin = csPin

		self.SPI = SPI(SPI_BUS, SPI_CS)
		self.SPI.bpw = 8
		self.SPI.mode = 0
		self.SPI.msh = SPI_CLK_SPEED
		self.SPI.lsbfirst = False

		GPIO.setup(self._interruptPin, GPIO.IN)
		self.lastIrqLevel = GPIO.input(self._interruptPin)
		GPIO.setup(self._csPin, GPIO.OUT)
		GPIO.output(self._csPin, GPIO.HIGH)

		self.start_time = datetime.datetime.now()
开发者ID:herrod,项目名称:BurnerBoard,代码行数:17,代码来源:rfm69.py

示例11: __init__

    def __init__(self, bus, device):
    	super(MAX7221, self).__init__(8, 8)
        SPI(bus, device).mode = 0
        self.spi_bus = SPI(bus, device)
        self.buf = [0, 0, 0, 0, 0, 0, 0, 0]

        self.OP_NOP = 0x0
        self.OP_DIG0 = 0x1
        self.OP_DIG1 = 0x2
        self.OP_DIG2 = 0x3
        self.OP_DIG3 = 0x4
        self.OP_DIG4 = 0x5
        self.OP_DIG5 = 0x6
        self.OP_DIG6 = 0x7
        self.OP_DIG7 = 0x8
        self.OP_DECODEMODE = 0x9
        self.OP_INTENSITY = 0xA
        self.OP_SCANLIMIT = 0xB
        self.OP_SHUTDOWN = 0xC
        self.OP_DISPLAYTEST = 0xF

        self.init()
开发者ID:tech2077,项目名称:BB-Matrix,代码行数:22,代码来源:MAX7221.py

示例12: print

#!/usr/bin/env python2
# -*- coding: utf-8 -*-

### New Python Template File
### H27 Mar 16

import os, sys
import time
import Adafruit_BBIO.GPIO as GPIO
from Adafruit_BBIO.SPI import SPI

GPIO.setup("P9_12",GPIO.OUT)
GPIO.output("P9_12",GPIO.HIGH)
print("GPIO >> HIGH")

spi_in = SPI(0, 0)
spi_out = SPI(0, 1)

spi_out.msh = 500000

while True:
    
    GPIO.output("P9_12",GPIO.LOW)
    print("GPIO >> LOW")
    spi_out.writebytes([0b00001111])
    print("write >> num")
    print spi_in.readbytes(1)
    GPIO.output("P9_12",GPIO.HIGH)
    print("GPIO >> HIGH")
    time.sleep(1)
开发者ID:5montest,项目名称:spi,代码行数:30,代码来源:test.py

示例13: ADCinit

def ADCinit():	
	RegWrite(ADS1248.MUX0, 0b00000001);	# MUX0:  Pos. input: AIN0, Neg. input: AIN1 (Burnout current source off) 
	RegWrite(ADS1248.MUX1, 0b00100000);	# MUX1:  REF0, normal operation
	RegWrite(ADS1248.SYS0, 0b00000000);	# SYS0:  PGA Gain = 1, 5 SPS
	RegWrite(ADS1248.IDAC0,0b00000000);	# IDAC0: off
	RegWrite(ADS1248.IDAC1,0b11001100);	# IDAC1: n.c.
	RegWrite(ADS1248.VBIAS,0b00000000);	# VBIAS: BIAS voltage disabled
 	RegWrite(ADS1248.OFC0, 0b00000000);	# OFC0:  0 => reset offset calibration
	RegWrite(ADS1248.OFC1, 0b00000000);	# OFC1:  0 => reset offset calibration
	RegWrite(ADS1248.OFC2, 0b00000000);	# OFC2:  0 => reset offset calibration
	RegWrite(ADS1248.GPIOCFG, 0b00000000);	# GPIOCFG: all used as analog inputs
	RegWrite(ADS1248.GPIODIR, 0b00000000);	# GPIODIR: -
	RegWrite(ADS1248.GPIODAT, 0b00000000);	# GPIODAT: -
	
spi = SPI(0,0)	#/dev/spidev1.0
spi.msh=10000 # SPI clock set to 100 kHz
spi.bpw = 8  # bits/word
spi.threewire = False
spi.lsbfirst = False
spi.mode = 1 
spi.cshigh = False  # ADS1248 chip select (active low)
spi.open(0,0)

GPIO.setup("P9_14", GPIO.OUT)


# drive START high to start conversion

GPIO.setup(ADS1248.STARTPIN, GPIO.OUT)
GPIO.output(ADS1248.STARTPIN,GPIO.HIGH)
开发者ID:donfuge,项目名称:ADS1248,代码行数:30,代码来源:ADS1248_minimal.py

示例14: begin

    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)

        # Determine if this is a p or non-p RF24 module and then
        # reset our data rate back to default value. This works
        # because a non-P variant won't allow the data rate to
        # be set to 250Kbps.
        self.p_variant = False  # False for RF24L01 and true for RF24L01P
        if self.setDataRate(NRF24.BR_250KBPS):
            self.p_variant = True

        # Then set the data rate to the slowest (and most reliable) speed supported by all
        # hardware.
        self.setDataRate(NRF24.BR_1MBPS)

        # 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.
        # This must be done after setDataRate()
        self.setRetries(int('0101', 2), 15)
        # Line bellow will set maximum (4ms) delay
        #self.setRetries(15, 15)

        # Initialize CRC and request 2-byte (16bit) CRC
        self.setCRCLength(NRF24.CRC_16)

        # Disable dynamic payloads, to match dynamic_payloads_enabled setting
        self.write_register(NRF24.DYNPD, 0)

        # Set up default configuration.  Callers can always change it later.
        # This channel should be universally safe and not bleed over into adjacent
        # spectrum.
        self.channel = 76
        self.setChannel(self.channel)

        # Powers up the radio, this can take up to 4.5ms
        # when CE is low radio will be in standby and will initiate
        # reception or transmission very shortly after CE is raised
        # If CE pin is not used, will Power up only on startListening and stopListening
        if self.ce_pin is not None:
            self.powerUp()

        # Reset current status
        # Notice reset and flush is the last thing we do
        self.write_register(NRF24.STATUS, NRF24.RX_DR | NRF24.TX_DS | NRF24.MAX_RT)

        # Flush buffers
        self.flush_rx()
        self.flush_tx()
        self.clear_irq_flags()
开发者ID:dquadros,项目名称:SensorNRF24L01,代码行数:96,代码来源:nrf24.dq.py

示例15: SPI

#!/usr/bin/python

from Adafruit_BBIO.SPI import SPI

spi = SPI(0,0)

spi.lsbfirst=False
spi.msh=1000000

spi.cshigh=False
spi.xfer2([0x36])
spi.cshigh=True

for reg in range(0x0,0x3d+1,1):
 spi.cshigh=False
 send = [ reg+0xc0 , 0x0 ]
 recv = spi.xfer2(send)
 spi.cshigh=True
 print reg,recv

patable=9*[0]
patable[0]=0x3e+0xc0

spi.cshigh=False
dd = spi.xfer2(patable)
spi.cshigh=True
print 0x3e,dd

rxfifo=65*[0]
rxfifo[0]=0x3f+0xc0
开发者ID:cudnn,项目名称:beaglebonequadcopter,代码行数:30,代码来源:bbb-spi-cc1101.py


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