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)
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)
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
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)
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"
from Adafruit_BBIO.SPI import SPI import time import numpy as np import scipy as sp import peakutils spi = SPI(0, 0) spi.mode = 1 spi.bpw = 8 spi.msh = 8000000 def put_in_reset(): print "\nput in reset" print spi.xfer2([int("16", 16), int("2F", 16), int("01", 16)]) def read_this_fifo(this, that): #print "\nread this fifo" #print "sent: 08", this, that, " 00. Got:" resp = spi.xfer2( [int("08", 16), int(str(this), 16), int(str(that), 16), int("00", 16)]) print resp return resp def put_out_reset(): print "\nput out reset"
#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, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
#!/usr/bin/python from Adafruit_BBIO.SPI import SPI from time import sleep spi = SPI(0,0) spi.bpw = 12 spi.msh = 100000 spi.lsbfirst = False spi.mode = 0 spi.open tlc5947_count = 2 tlc5947_channels = 24 # buffer = [0x000] * 48 buffer = [0x000] * (tlc5947_count * tlc5947_channels) #spi.writebytes(buffer) #print buffer spi.writebytes(buffer) #sleep(1) spi.close # CS_0 P9_17 lat # DO P9_21 din # DI P9_18 n/c
from Adafruit_BBIO.SPI import SPI import zlsGpio # alt use spidev import time #https://github.com/adafruit/adafruit-beaglebone-io-python # Constants VREF = 4.096 z = time.time() spi = SPI(1, 0) # 1, 0 is what used to be 0,0 #spi.fd = -1; spi.mode = 3 spi.bpw = 8 #Bits per word spi.msh = 1000000 y = time.time() print y - z def ReadADC_average(chan, averages, delay, vref): """ Returns average of averages measurments. rate is mS loopMax is number of measurements """ data_summ = 0.0 data_val = 0.0 for x in range(averages): data_summ += self.ReadADC(chan) time.sleep(delay)
import Adafruit_BBIO.GPIO as GPIO from Adafruit_BBIO.SPI import SPI import time pause = 0.1 chipSelect = "P9_12" GPIO.setup(chipSelect, GPIO.OUT) GPIO.output(chipSelect, GPIO.HIGH) sclk = "P9_11" GPIO.setup(sclk, GPIO.IN) spi = SPI(0, 0) spi.mode = 0 spi.msh = 500000 spi.open(0, 0) # global count # count = 0; # # def callback_function_print(input_pin): # count = count + 1 # print "Input on pin", input_pin # # GPIO.add_event_detect(sclk, GPIO.BOTH, callback=callback_function_print) def spi_write(num):
#!/usr/bin/python from Adafruit_BBIO.SPI import SPI import Adafruit_BBIO.GPIO as GPIO import time #------------------------------------------------------- # DAC # initialize the bus and device /dev/spidev2.0 spi1 = SPI(1, 0) #defining mode (CPOL = 0; CPHA = 1) spi1.mode = 1 #defining speed (in bps) spi1.msh = 10000000 #------------------------------------------------------- # mnemonics for GPIO RST = "P9_26" CLR = "P9_25" LDAC = "P9_24" #------------------------------------------------------- # defining outputs GPIO.setup(RST, GPIO.OUT) GPIO.setup(CLR, GPIO.OUT) GPIO.setup(LDAC, GPIO.OUT) #------------------------------------------------------- # initialization of outputs GPIO.output(RST, GPIO.HIGH) GPIO.output(CLR, GPIO.HIGH) GPIO.output(LDAC, GPIO.LOW) #======================================================= # DAC calibration parameters #======================================================= # global variables
from Adafruit_BBIO.SPI import SPI spi = SPI(1,0) spi.mode=2 spi.msh=200000 spi.open(1,0) print spi.readbytes(4) #print spi.xfer2([32, 11, 110, 22, 220]) spi.close()
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) time.sleep(0.02) ADCinit()
#!/usr/bin/python from Adafruit_BBIO.SPI import SPI import Adafruit_BBIO.GPIO as GPIO import math import time import dac #------------------------------------------------------- # initialize the bus and device /dev/spidev1.0 spi0 = SPI(0, 0) #defining mode (CPOL = 0; CPHA = 1) spi0.mode = 1 #defining speed (in bps) spi0.msh = 10000000 #------------------------------------------------------- # mnemonics for GPIO BUSY = "P9_20" CNV = "P9_23" #------------------------------------------------------- # defining outputs GPIO.setup(CNV, GPIO.OUT) #------------------------------------------------------- # defining inputs GPIO.setup(BUSY, GPIO.IN) #------------------------------------------------------- # initialization of outputs GPIO.output(CNV, GPIO.LOW) #======================================================= # ADC calibration parameters #======================================================= # global variables global GAIN