コード例 #1
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)
コード例 #2
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"
コード例 #3
0
ファイル: testspi.py プロジェクト: jasonblewis/bbb-clock
#!/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
コード例 #4
0
#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
        print("data is")
        print(angle2)