def __init__(self, model): # The world model self.model = model # Initialisation of the SPI communication self.SPIchannel = 0 SPIspeed = 562500 wiringpi.wiringPiSetupGpio() wiringpi.wiringPiSPISetupMode(self.SPIchannel, SPIspeed, 0) # Boolean that allow the thread to be quit self.terminated = False # Initialise the thread Thread.__init__(self)
def __init__(self, SPI_CHANNEL, SPI_FREQUENCY, CS_PIN): "Instantiates a DAC object with the given parameters" self.SPI_CHANNEL = SPI_CHANNEL self.SPI_FREQUENCY = SPI_FREQUENCY self.CS_PIN = CS_PIN debug_print('pydac8532 initializing with:') debug_print(' SPI_MODE = %d' % self.SPI_MODE) debug_print(' SPI_CHANNEL = %d' % self.SPI_CHANNEL) debug_print(' SPI_FREQUENCY = ' + format(self.SPI_FREQUENCY, ',')) debug_print(' CS_PIN = %d' % self.CS_PIN) # Set up the wiringPi object to use physical pin numbers wp.wiringPiSetupPhys() # Initialize CS pin wp.pinMode(self.CS_PIN, wp.OUTPUT) wp.digitalWrite(self.CS_PIN, wp.HIGH) # Initialize the wiringPi SPI setup spi_success = wp.wiringPiSPISetupMode(self.SPI_CHANNEL, self.SPI_FREQUENCY, self.SPI_MODE) #JKR debug_print('SPI success: ' + str(spi_success))
def __init__(self, SPI_CHANNEL, SPI_FREQUENCY, CS_PIN): self.SPI_CHANNEL = SPI_CHANNEL self.SPI_FREQUENCY = SPI_FREQUENCY self.CS_PIN = CS_PIN debug_print('pylps22hb initializing with:') debug_print(' SPI_MODE = %d' % self.SPI_MODE) debug_print(' SPI_CHANNEL = %d' % self.SPI_CHANNEL) debug_print(' SPI_FREQUENCY = ' + format(self.SPI_FREQUENCY, ',')) debug_print(' CS_PIN = %d' % CS_PIN) # Set up the wiringpi object to use physical pin numbers wp.wiringPiSetupPhys() # Initialize CS pins wp.pinMode(self.CS_PIN, wp.OUTPUT) wp.digitalWrite(self.CS_PIN, wp.HIGH) # Initialize the wiringpi SPI setup #spi_success = wp.wiringPiSPISetup(self.SPI_CHANNEL, self.SPI_FREQUENCY) spi_success = wp.wiringPiSPISetupMode(self.SPI_CHANNEL, self.SPI_FREQUENCY, self.SPI_MODE) #JKR debug_print("SPI success " + str(spi_success))
def __init__(self, carrier=F_433, callback=None): self.carrier = carrier self.callback = (lambda x: None) if callback is None else callback wiringpi.wiringPiSetup() wiringpi.wiringPiSPISetupMode(0, 4000000, 0) # spi initialization wiringpi.pinMode(GDO0, wiringpi.INPUT) wiringpi.pinMode(GDO2, wiringpi.INPUT) self.reset() # CC1101 reset self.regConfigSettings(self.carrier) # CC1101 register config self.spiWriteBurstReg(CC1101_PATABLE, (0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60)) # CC1101 PATABLE config wiringpi.pinMode(GDO0, wiringpi.GPIO.INPUT) wiringpi.pullUpDnControl(GDO0, wiringpi.GPIO.PUD_UP) wiringpi.wiringPiISR(GDO0, wiringpi.GPIO.INT_EDGE_FALLING, lambda: self.callback(buffer=self.receiveData()))
def __init__(self, *args): debug_print('pydads1256 initializing with:') debug_print(' SPI_MODE = %d' % self.SPI_MODE) debug_print(' SPI_CHANNEL = %d' % self.SPI_CHANNEL) debug_print(' SPI_FREQUENCY = ' + format(self.SPI_FREQUENCY, ',')) debug_print(' CS_PIN = %d' % self.CS_PIN) debug_print(' DRDY_PIN = %d' % self.DRDY_PIN) debug_print(' RESET_PIN = %d' % self.RESET_PIN) debug_print(' PDWN_PIN = %d' % self.PDWN_PIN) # Set up the wiringpi object to use physical pin numbers wp.wiringPiSetupPhys() # Initialize the DRDY pin wp.pinMode(self.DRDY_PIN, wp.INPUT) # Initialize the reset pin wp.pinMode(self.RESET_PIN, wp.OUTPUT) wp.digitalWrite(self.RESET_PIN, wp.HIGH) # Initialize PDWN pin wp.pinMode(self.PDWN_PIN, wp.OUTPUT) wp.digitalWrite(self.PDWN_PIN, wp.HIGH) # Initialize CS pin wp.pinMode(self.CS_PIN, wp.OUTPUT) wp.digitalWrite(self.CS_PIN, wp.HIGH) # Initialize the wiringpi SPI setup #spi_success = wp.wiringPiSPISetup(self.SPI_CHANNEL, self.SPI_FREQUENCY) spi_success = wp.wiringPiSPISetupMode(self.SPI_CHANNEL, self.SPI_FREQUENCY, self.SPI_MODE) #JKR debug_print("SPI success " + str(spi_success))
def __init__(self, spi_port=0, spi_cs=1, spi_cs_gpio=MOVIT_CS_GPIO): self.spi_cs_gpio = spi_cs_gpio self.spi_port = spi_port self.errors = 0 wiringpi.wiringPiSetupGpio() wiringpi.pinMode(self.spi_cs_gpio, wiringpi.OUTPUT) # OUTPUT ret = wiringpi.wiringPiSPISetupMode(self.spi_port, 2000000, 0) # Channel, speed, mode if ret < 0: self.errors += 1 raise RuntimeError("Unable to open SPI port") self.reset()
def __init__(self): # Set up the wiringpi object to use physical pin numbers wp.wiringPiSetupPhys() # Initialize the DRDY pin wp.pinMode(self.DRDY_PIN, wp.INPUT) # Initialize the reset pin wp.pinMode(self.RESET_PIN, wp.OUTPUT) wp.digitalWrite(self.RESET_PIN, wp.HIGH) # Initialize PDWN pin wp.pinMode(self.PDWN_PIN, wp.OUTPUT) wp.digitalWrite(self.PDWN_PIN, wp.HIGH) # Initialize CS pin wp.pinMode(self.CS_PIN, wp.OUTPUT) wp.digitalWrite(self.CS_PIN, wp.HIGH) # Initialize the wiringpi SPI setup spi_success = wp.wiringPiSPISetupMode(self.SPI_CHANNEL, self.SPI_FREQUENCY, self.SPI_MODE) debug_print("SPI success " + str(spi_success))
def __init__(self, conf=ADS1256_default_config): # Set up the wiringpi object to use physical pin numbers wp.wiringPiSetupPhys() # Config and initialize the SPI and GPIO pins used by the ADC. # The following four entries are actively used by the code: self.SPI_CHANNEL = conf.SPI_CHANNEL self.DRDY_PIN = conf.DRDY_PIN self.CS_PIN = conf.CS_PIN self.DRDY_TIMEOUT = conf.DRDY_TIMEOUT self.DRDY_DELAY = conf.DRDY_DELAY # Only one GPIO input: if conf.DRDY_PIN is not None: self.DRDY_PIN = conf.DRDY_PIN wp.pinMode(conf.DRDY_PIN, wp.INPUT) # GPIO Outputs. Only the CS_PIN is currently actively used. ~RESET and # ~PDWN must be set to static logic HIGH level if not hardwired: for pin in (conf.CS_PIN, conf.RESET_PIN, conf.PDWN_PIN): if pin is not None: wp.pinMode(pin, wp.OUTPUT) wp.digitalWrite(pin, wp.HIGH) # Initialize the wiringpi SPI setup. Return value is the Linux file # descriptor for the SPI bus device: fd = wp.wiringPiSPISetupMode(conf.SPI_CHANNEL, conf.SPI_FREQUENCY, conf.SPI_MODE) if fd == -1: raise IOError("ERROR: Could not access SPI device file") return False # ADS1255/ADS1256 command timing specifications. Do not change. # Delay between requesting data and reading the bus for # RDATA, RDATAC and RREG commands (datasheet: t_6 >= 50*CLKIN period). self._DATA_TIMEOUT_US = int(1 + (50 * 1000000) / conf.CLKIN_FREQUENCY) # Command-to-command timeout after SYNC and RDATAC # commands (datasheet: t11) self._SYNC_TIMEOUT_US = int(1 + (24 * 1000000) / conf.CLKIN_FREQUENCY) # See datasheet ADS1256: CS needs to remain low # for t_10 = 8*T_CLKIN after last SCLK falling edge of a command. # Because this delay is longer than timeout t_11 for the # RREG, WREG and RDATA commands of 4*T_CLKIN, we do not need # the extra t_11 timeout for these commands when using software # chip select selection and the _CS_TIMEOUT_US. self._CS_TIMEOUT_US = int(1 + (8 * 1000000) / conf.CLKIN_FREQUENCY) # When using hardware/hard-wired chip select, still a command- # to command timeout of t_11 is needed as a minimum for the # RREG, WREG and RDATA commands. self._T_11_TIMEOUT_US = int(1 + (4 * 1000000) / conf.CLKIN_FREQUENCY) # Initialise class properties self.v_ref = conf.v_ref # At hardware initialisation, a settling time for the oscillator # is necessary before doing any register access. # This is approx. 30ms, according to the datasheet. time.sleep(0.03) self.wait_DRDY() # Device reset for defined initial state self.reset() # Configure ADC registers: # Status register not yet set, only variable written to avoid multiple # triggering of the AUTOCAL procedure by changing other register flags self._status = conf.status # Class properties now configure registers via their setter functions self.mux = conf.mux self.adcon = conf.adcon self.drate = conf.drate self.gpio = conf.gpio self.status = conf.status
import wiringpi import time spichannel = 0 print(1) spispeed = 7812500 print(2) wiringpi.wiringPiSetupGpio() print(3) wiringpi.wiringPiSPISetup(spichannel, spispeed) print(4) wiringpi.wiringPiSPISetupMode(spichannel, spispeed, 0) print(5) senddata = str(4772) print(senddata) while True: a = wiringpi.wiringPiSPIDataRW(0, senddata) print(a) time.sleep(1)