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 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"
#!/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
#DGND gnd gray #3V3 orange #OM SPI TE ENABLEN #config-pin P9.20 spi #en da me alle pins from Adafruit_BBIO.SPI import SPI import Adafruit_BBIO.GPIO as GPIO import time spi = SPI(0, 0) #4 busses, this is bus 0 spi.msh = 10000 #Frequency spi.bpw = 8 #bits per word spi.cshigh = False #true means you select the chip, depends on the chip, here low means active, normally Low for IMU spi.threewire = False #if it is true, you just read, otherwise you also send commands spi.lsbfirst = False #Least significant bit first (left) spi.open(0, 0) #open #GPIO.setup("P8_11",GPIO.OUT) #GPIO.output("P8_11",GPIO.HIGH) try: while True: res = spi.xfer2([0xFFFF, 0xFFFF]) #deliver two bytes res1 = spi.readbytes(2) #Read 2 bytes angle = (res1[0] << 8) | res1[1] #merge leftbyte and rightbyte angle1 = angle & 0x3FFF #move the first two bits angle2 = float(angle1) / 16363 * 360
if DIRECTION: GPIO.output(z_direction_output, GPIO.HIGH) else: GPIO.output(z_direction_output, GPIO.LOW) # enable motors GPIO.setup(z_enable_output, GPIO.OUT) GPIO.output(z_enable_output, GPIO.LOW) #TODO: port this to other stepper actions #spio_csx = "P9_17" spio_csy = "P9_11" spio_csz = "P8_14" spi = SPI(1, 0) #spi.no_cs = True spi.cshigh = True spio_selects = [spio_csy, spio_csz] for select in spio_selects: GPIO.setup(select, GPIO.OUT) GPIO.output(select, GPIO.HIGH) GPIO.output(spio_csz, GPIO.LOW) spi.mode = 3 spi.msh = int(16000000 / 8) #spi.msh = 1000 def controlledwrite(lst, chipselect): spi.writebytes(lst) GPIO.output(chipselect, GPIO.HIGH) sleep(1)
from Adafruit_BBIO.SPI import SPI from adafruit_max31865 import MAX31865 import time spi = SPI(2, 1) spi.msh = 500000 spi.cshigh = False spi.mode = 3 sensor = MAX31865(spi) while True: temperature = sensor.get_temperature() print('Temperature: {0:0.3f}C'.format(temperature)) time.sleep(1)
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() while True: