示例#1
0
 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
示例#2
0
	def __init__(self, spi = SPI(0,0), gpio_nrst = 'P9_23', gpio_dc = 'P9_24', gpio_nled = 'P9_25'):
		self.gpio_nrst = gpio_nrst
		self.gpio_dc = gpio_dc
		self.gpio_nled = gpio_nled

		self.spi = spi
		self.spi.msh = 4000000
		self.spi.mode = 0b00
		self.spi.bpw = 8
		self.spi.lsbfirst = False
		self.spi.threewire = False
		self.spi.cshigh = False

		GPIO.setup(self.gpio_nrst, GPIO.OUT, initial = GPIO.LOW)
		sleep(0.1) # workaround until library waits for permissions
		GPIO.setup(self.gpio_nrst, GPIO.OUT, initial = GPIO.LOW)
		GPIO.output(self.gpio_nrst, GPIO.LOW) # Reset.

		GPIO.setup(self.gpio_dc, GPIO.OUT, initial = GPIO.LOW)
		sleep(0.1)
		GPIO.setup(self.gpio_dc, GPIO.OUT, initial = GPIO.LOW)
		GPIO.output(self.gpio_dc, GPIO.LOW) # Command.

		if self.gpio_nled:
			GPIO.setup(self.gpio_nled, GPIO.OUT, initial = GPIO.HIGH)
			sleep(0.1)
			GPIO.setup(self.gpio_nled, GPIO.OUT, initial = GPIO.HIGH)
			GPIO.output(self.gpio_nled, GPIO.HIGH) # Off.

		self.reset()
示例#3
0
文件: RFM69HCW.py 项目: oresat/devsat
    def __init__(self,
                 LED_STATE=default_LED_STATE,
                 Fxosc=default_Fxosc,
                 Fstep=default_Fstep,
                 callsign=None,
                 node_id=default_node_id,
                 network_id=default_network_id,
                 carrier_freq=default_carrier_freq,
                 carrier_dev=default_carrier_dev,
                 carrier_bitrate=default_bitrate):
        self._mode = OPMODE_SLEEP
        self.LED_STATE = LED_STATE
        self.Fxosc = Fxosc
        self.Fstep = Fstep
        self.callsign = callsign
        self.RFM_SPI = SPI(0, 0)
        self.RFM_SPI.msh = 5000000
        self.carrier_freq = carrier_freq
        self.carrier_dev = carrier_dev
        self.bitrate = carrier_bitrate
        self.node_id = node_id
        self.network_id = network_id

        if self.callsign is None:
            raise NoCallSign("FCC Callsign not defined")
        self.ord_callsign = map(ord, list(self.callsign))
        self._io_setup()
        GPIO.output(BLUE_LEDPIN, GPIO.LOW)
        self.reset_radio()
        return
示例#4
0
    def run(self):
        #Only need to execute one of the following lines:
        #spi = SPI(bus, device) #/dev/spidev<bus>.<device>
        spi = SPI(0, 0)  #/dev/spidev1.0
        spi.msh = 2000000  # SPI clock set to 2000 kHz
        spi.bpw = 8  # bits/word
        spi.threewire = False
        spi.lsbfirst = False
        spi.mode = 1
        spi.cshigh = False  # chip select (active low)
        spi.open(0, 0)
        print("spi... msh=" + str(spi.msh))

        gchannel = 0
        buf0 = (7 << 3) | ((gchannel & 0x0f) >> 1)  #(7<<3) for auto-2 mode
        buf1 = (gchannel & 0x01) << 7
        buf1 = buf1 | 0x40  #select 5v i/p range

        while (self.running):
            ret = spi.xfer2([buf0, buf1])
            print("0x%x 0x%x" % (ret[0], ret[1]))

            chanl = (ret[0] & 0xf0) >> 4
            adcval = ((ret[0] & 0x0f) << 4) + ((ret[1] & 0xf0) >> 4)
            print(" -> chanl=%d adcval=0x%x" % (chanl, adcval))

            time.sleep(1)
示例#5
0
def PullData():
    print("pull data")

    spi = SPI(1, 0)
    spi.msh = 100000
    spi.bpw = 8

    spi.writebytes([0x30])
    sleep(0.1)
    moistureVals = spi.readbytes(3)
    moisture = str(moistureVals[0]) + str(moistureVals[1]) + str(moistureVals[2])

    spi.writebytes([0x31])
    sleep(0.1)
    moistureVals1 = spi.readbytes(3)
    moisture1 = str(moistureVals1[0]) + str(moistureVals1[1]) + str(moistureVals1[2])

    spi.writebytes([0x35])
    sleep(0.1)
    lightVals = spi.readbytes(3)
    light = str(lightVals[0]) + str(lightVals[1]) + str(lightVals[2])

    Data = []
    Data.append(moisture)
    Data.append(moisture1)
    Data.append(light)

    spi.close()
    return Data
示例#6
0
 def __init__(self):
     self.val = None
     self.tempList = []
     self.spi = SPI(0, 0)
     self.spi.msh = 1000000
     GPIO.setup(CS_PIN, GPIO.OUT)
     GPIO.output(CS_PIN, GPIO.HIGH)
     self.inter = Interpolate(x, y)
 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])
示例#8
0
 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)
示例#9
0
    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)
示例#10
0
def factory(bus=0, device=0, dev="rpi"):
    if dev == "rpi":
        import spidev
        s = spidev.SpiDev()
        s.open(0, 0)
        return s
    elif dev == "bbb":
        from Adafruit_BBIO.SPI import SPI
        bus = 1
        s = SPI(bus, device)
        s.mode = 0
        return s
示例#11
0
    def init_spi(self):
        logging.debug("Initializing spi...")
        self.spi = SPI(0, 0)  #/dev/spidev1.0

        #   SPI Mode 	Clock Polarity (CPOL/CKP) 	Clock Phase (CPHA) 	Clock Edge (CKE/NCPHA)
        #   0 	        0 	                        0 	                1
        #   1 	        0 	                        1 	                0
        #   2 	        1 	                        0 	                1
        #   3 	        1 	                        1 	                0
        self.spi.mode = 0
        self.spi.msh = SPI_CLOCK_RATE  #this is clock speed setting
        self.spi.open(0, 0)
示例#12
0
    def __init__(self, unix_socket_path, *args, **kwargs):
        self.unix_socket_path = unix_socket_path
        self.connection = None
        self.welcome_socket = None

        spi = SPI(0, 0)
        spi.msh = 2000000
        spi.mode = 1
        self.chs = [0, 1, 2, 3]
        self.ADC0 = ADC("P9_24", spi)
        self.ADC1 = ADC("P9_26", spi)
        self.ADC2 = ADC("P9_28", spi)
        self.ADC3 = ADC("P9_30", spi)
示例#13
0
    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()
示例#14
0
    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 ESB@250KBPS) 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()
示例#15
0
def getMoist_ch1():
    #print("Reading Moisture CH 1")

    spi = SPI(1, 0)
    spi.msh = 100000
    spi.bpw = 8

    spi.writebytes([0x31])
    sleep(0.01)
    moistureVals = spi.readbytes(3)
    moisture = str(moistureVals[0]) + str(moistureVals[1]) + str(moistureVals[2])

    spi.close()
    return moisture
示例#16
0
def getLight():
    #print("Reading Light Data")

    spi = SPI(1, 0)
    spi.msh = 100000
    spi.bpw = 8

    spi.writebytes([0x35])
    sleep(0.01)
    lightVals = spi.readbytes(3)
    light = str(lightVals[0]) + str(lightVals[1]) + str(lightVals[2])

    spi.close()
    return light
示例#17
0
 def __init__(self, bus, device, cePin, csnPin, irqPin):
     self.__bus = bus
     self.__device = device
     self.cePin = cePin
     self.csnPin = csnPin
     self.irqPin = irqPin
     self.spi = SPI(self.__bus, self.__device)
     self.spi.msh = 10000
     self.spi.bpw = 8  # bits/word
     self.spi.threewire = False
     self.spi.lsbfirst = False
     self.spi.mode = 0
     self.spi.cshigh = False
     self.spi.open(0, 0)
     self.last_payload = ""
示例#18
0
def Watering():
    print("watering")

    spi = SPI(1, 0)
    spi.msh = 100000
    spi.bpw = 8

    list = []
    i=0
    while i<50:
        spi.writebytes([0x31])
        sleep(0.1)
        list.append(spi.readbytes(3))
        print(list.pop())
        ++i
        sleep(0.5)
    spi.close()
示例#19
0
	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()
    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 = SPI(1, 0)
示例#21
0
def stopWatering():
    print("Stopping watering")

    session['watering_command_status'] = "OFF"

    # send the signal to arduino to stop watering
    spi = SPI(1, 0)
    spi.msh = 100000
    spi.bpw = 8

    # send the appropriate signal
    spi.writebytes([0x37])  # '7'

    print(spi.readbytes(1))

    spi.close()

    return flask.redirect("/")
示例#22
0
def startWatering():
    print("Started watering...")

    session['watering_command_status'] = "ON"

    # send the signal to arduino to start watering
    spi = SPI(1, 0)
    spi.msh = 100000
    spi.bpw = 8

    # send the appropriate signal
    spi.writebytes([0x36])  # '6'

    print(spi.readbytes(1))

    spi.close()

    return flask.redirect("/")
示例#23
0
    def __init__(self):
        # create outer classes with ability to change inner parameters

        # using two's complement
        # CONSTS
        self.DAC_SEND = "0001"  # value to be sending information to dac
        self.MAX_NEG = -pow(2, 19)  # max neg value that can be achieved
        self.MAX_POS = int(
            0b01111111111111111111)  # max pos value that can be achieved
        self.MAX_CLOCK = 340000  # maximal clock value we can get in Hz
        self.MIN_CLOCK = 50000  # minimal clock value we can get in Hz
        self.IP = '192.168.0.20'
        self.PORT = 5555

        self.act_val = 0  # actual value
        self.clock = self.MIN_CLOCK  # begin with min value

        self.spi = SPI(1, 0)  # spi for our communication
        self.spi.mode = 0b00
        self.spi.msh = self.clock

        # Triggers for the DAC
        self.reset = False
        self.ldac = False
        GPIO.setup("P8_17", GPIO.OUT)  # LDAC
        GPIO.setup("P8_18", GPIO.OUT)  # RESET
        GPIO.output("P8_18", self.reset)
        GPIO.output("P8_17", self.ldac)

        # Address for which DAC
        self.dac_address = list()
        self.dac_address = [0, 0, 0, 0, 0]  # default
        GPIO.setup("P9_15", GPIO.OUT)  # P0
        GPIO.setup("P9_11", GPIO.OUT)  # P1
        GPIO.setup("P9_12", GPIO.OUT)  # P2
        GPIO.setup("P9_13", GPIO.OUT)  # P3
        GPIO.setup("P9_14", GPIO.OUT)  # P4
        GPIO.output("P9_15", GPIO.LOW)  # P0
        GPIO.output("P9_11", GPIO.LOW)  # P1
        GPIO.output("P9_12", GPIO.LOW)  # P2
        GPIO.output("P9_13", GPIO.LOW)  # P3
        GPIO.output("P9_14", GPIO.LOW)  # P4
        self.initializeDAC()
示例#24
0
def ini_levels():

    check_ok = 0
    update_data = 0x39

    # spi.set_clock_hz(1000000)
    # spi.set_mode(0)
    # spi.set_bit_order(SPI.MSBFIRST)
    SPI_PORT = 0
    SPI_DEVICE = 0
    # SPI setup

    spi = SPI(0, 0)  #/dev/spidev1.0
    spi.msh = 100000  # SPI clock set to 100 kHz
    spi.bpw = 8  # bits/word
    spi.threewire = False
    spi.lsbfirst = False
    spi.mode = 0
    spi.cshigh = False  # ADS1248 chip select (active low)
    # spi.open(0,0)
    spi.open(SPI_PORT, SPI_DEVICE)

    print "SPI port ", SPI_PORT, "  ", SPI_DEVICE, " open"
示例#25
0
    def __init__(self, maxClock=3300000):
        # using two's complement
        self.dacSend = "0001"
        self.max_raw_minus = -pow(2, 19)  # maximal value that can be achieved
        self.max_raw_plus = int(0b01111111111111111111)
        self.actVal = 0  # actual value
        # SPI
        self.spi = SPI(1, 0)  # choose SPI device
        self.spi.mode = 0b00
        if maxClock > 1000:
            self.spi.msh = maxClock
        else:
            self.spi.msh = 3300000
            print("Minumum clock speed is 10000, setting default 33Mhz")
        # Start values
        self.reset = 0
        self.ldac = 0  # in the beggining the device is not ready(remember they are inverted)

        # P8
        GPIO.setup("P8_17", GPIO.OUT)  # LDAC
        GPIO.output("P8_17", self.ldac)
        GPIO.setup("P8_18", GPIO.OUT)  # RESET
        GPIO.output("P8_18", self.reset)

        # GPIO.setup("P8_15", GPIO.OUT) #ext rsten
        # GPIO.setup("P8_14", GPIO.OUT) # PLL LOCK
        # GPIO.setup("P8_16", GPIO.OUT) # ext Ioupden
        # NOT USED

        # P9 (addresses)
        self.dacAddress = [0, 0, 0, 0, 0]  # default
        GPIO.setup("P9_11", GPIO.OUT)  # P1
        GPIO.setup("P9_12", GPIO.OUT)  # P2
        GPIO.setup("P9_13", GPIO.OUT)  # P3
        GPIO.setup("P9_14", GPIO.OUT)  # P4
        GPIO.setup("P9_15", GPIO.OUT)  # P0
示例#26
0
文件: nrf24.py 项目: wzab/pynrf24
    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 ESB@250KBPS) 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)

        # 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,
                            NRF24.RX_DR | NRF24.TX_DS | 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)

        self.setRetries(15, 15)

        # Flush buffers
        self.flush_rx()
        self.flush_tx()
        self.clear_irq_flags()
import Adafruit_BBIO.GPIO as GPIO
from Adafruit_BBIO.SPI import SPI
# from ADS126x_constants import *

spi = SPI(0, 0)

# class ADS126x():

START_PIN = "P9_23"
RSTN_PIN = "P9_24"
DRDY_PIN = "P9_26"

GPIO.setup(RSTN_PIN, GPIO.OUT, pull_up_down=GPIO.PUD_UP)
GPIO.output(RSTN_PIN, GPIO.HIGH)

GPIO.setup(START_PIN, GPIO.OUT, pull_up_down=GPIO.PUD_DOWN)
GPIO.output(START_PIN, GPIO.LOW)

GPIO.setup(DRDY_PIN, GPIO.IN)

R0 = 100.0
A = 3.9083e-3
B = -5.775e-7
C = -4.183e-12


def R2C(R):
    if R >= 100.0:
        return (-R0*A
                +(R0**2 * A**2
                  - 4 * R0 * B * (R0 - R))**0.5)\
示例#28
0
                value[12]).split('x')[1] + ":" + hex(value[11]).split('x')[1]
    #print(address)
    rssi = value[17] - 256
    #print(rssi)
    if rssi > -70:
        if value[28] == 128:
            print("%s, 1, %d") % (address, rssi)
        if value[28] == 129:
            print("%s, 2, %d") % (address, rssi)
        if value[28] == 130:
            print("%s, 3, %d") % (address, rssi)
        if value[28] == 131:
            print("%s, 4, %d") % (address, rssi)


bt = SPI(0, 0)
bt.mode = 1
bt.msh = 1000000

#reset the module

GPIO.output("P9_12", GPIO.LOW)
time.sleep(0.1)
GPIO.output("P9_12", GPIO.HIGH)

# initialize bt module
k = 0
while k < 100:
    #print("Sending init message")
    bt.xfer2([
        0x00, 0xFE, 0x2A, 0x01, 0x00, 0xFE, 0x26, 0x02, 0x0A, 0x00, 0x00, 0x00,
示例#29
0
    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 ESB@250KBPS) 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()
示例#30
0
def spi_config():
    global RFM_SPI
    RFM_SPI = SPI(0, 0)
    RFM_SPI.msh = 5000000