Ejemplo n.º 1
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
Ejemplo n.º 2
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)
Ejemplo n.º 3
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)
Ejemplo n.º 4
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)
Ejemplo n.º 5
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)
Ejemplo n.º 6
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
Ejemplo n.º 7
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
Ejemplo n.º 8
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()
Ejemplo n.º 9
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("/")
Ejemplo n.º 10
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("/")
Ejemplo n.º 11
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"
Ejemplo n.º 12
0
def spi_config():
    global RFM_SPI
    RFM_SPI = SPI(0, 0)
    RFM_SPI.msh = 5000000
Ejemplo n.º 13
0
import sys
from Adafruit_BBIO.SPI import SPI

command = sys.argv[1]

WALK = 1
WALK_BACK = 31
STOP = 15
TURNL = 3
TURNR = 7

spi = SPI(0,0) 
spi.msh = 57600
spi.bpw = 8
#for debugging with keyboard input
#command = raw_input();
spi.xfer2([getCommandCode(command)])
spi.close() 

def getCommandCode(command):
      if command == 'walk':
    print("Walk!")
    return WALK
  elif command == 'back':
    print('Reverse')
    return WALK_BACK
  elif command == 'stop':
    print('Stop!')
    return STOP
  elif command == 'left': 
    print('Turn Left')
Ejemplo n.º 14
0
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)
Ejemplo n.º 15
0
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):
    print "Writing " + num + "..."
    GPIO.output(chipSelect, GPIO.LOW)
Ejemplo n.º 16
0
#SPIO_SCLK P9.22 => SCK  blue

#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
Ejemplo n.º 17
0
from Adafruit_BBIO.SPI import SPI
import time
#https://github.com/adafruit/adafruit-beaglebone-io-python
spi = SPI(1, 0)

#spi.fd = -1;
spi.mode = 3
#spi.bpw = 8;#Bits per word
spi.msh = 1250000

time.sleep(.300)

#spi.lsbfirst = True
time.sleep(.300)


def readLong():
    x = 0
    time.sleep(.001)
    spi.writebytes([0x33])
    time.sleep(.001)
    x_high_data = spi.readbytes(1)
    time.sleep(.001)
    x = x_high_data[0] << 8
    spi.writebytes([0x34])
    time.sleep(.001)
    x_low_data = spi.readbytes(1)
    x += x_low_data[0]
    longAdc = 0.0
    longAdc += x - 32768
    #y -= 32768
Ejemplo n.º 18
0
from Adafruit_BBIO.SPI import SPI
import struct
import time

spi = SPI(0,0)
spi.mode = 1
spi.msh = 300000
spi.xfer([0b00011000, 0x02])


def decode_sent_command(ser_cmd):
    cmd_bits = (ser_cmd & (((1<<6) - 1)<<10))>>10
    data_bits = ser_cmd & ((1<<10)-1)
    return bin(cmd_bits)[2:], data_bits


def send_cmd(cmd,data):
    ser_cmd = (cmd << 10) | (data & ((1<<10)-1))
    w0 = ser_cmd >> 8
    w1 = ser_cmd & ((1<<8)-1)
    return [w0, w1]

 # write to RDAC
spi.xfer(list(struct.unpack('BB', struct.pack('>H', 1 << 10 | 0))))

 # read RDAC
spi.xfer(list(struct.unpack('BB', struct.pack('>H', 0b10 << 10 | 0))))

 # read Control register
spi.xfer(list(struct.unpack('BB', struct.pack('>H', 0b111 << 10 | 0))))
spi.readbytes(2)
Ejemplo n.º 19
0
#!/usr/bin/python
from Adafruit_BBIO.SPI import SPI
import Adafruit_BBIO.GPIO as GPIO
import time
#-------------------------------------------------------
# initialize the bus and device /dev/spidev1.0
spi0 = SPI(0, 0)  #ADC
# initialize the bus and device /dev/spidev2.0
spi1 = SPI(1, 0)  #DAC
#-------------------------------------------------------
#Set the maximum clock frequency
spi0.msh = 100000
spi1.msh = 100000
#-------------------------------------------------------
# mnemonics for GPIO
RST = "P9_26"
CLR = "P9_25"
LDAC = "P9_24"
BUSY = "P9_20"
CNV = "P9_23"
PWR_SYS = "P9_16"
#PWR_SYS = "P9_15"
#-------------------------------------------------------
# defining outputs
GPIO.setup(RST, GPIO.OUT)
GPIO.setup(CLR, GPIO.OUT)
GPIO.setup(LDAC, GPIO.OUT)
GPIO.setup(CNV, GPIO.OUT)
GPIO.setup(PWR_SYS, GPIO.OUT)
#-------------------------------------------------------
# defining inputs
Ejemplo n.º 20
0
Archivo: test.py Proyecto: 5montest/spi
### New Python Template File
### H27 Mar 16

import os, sys
import time
import Adafruit_BBIO.GPIO as GPIO
from Adafruit_BBIO.SPI import SPI

GPIO.setup("P9_12",GPIO.OUT)
GPIO.output("P9_12",GPIO.HIGH)
print("GPIO >> HIGH")

spi_in = SPI(0, 0)
spi_out = SPI(0, 1)

spi_out.msh = 500000

while True:
    
    GPIO.output("P9_12",GPIO.LOW)
    print("GPIO >> LOW")
    spi_out.writebytes([0b00001111])
    print("write >> num")
    print spi_in.readbytes(1)
    GPIO.output("P9_12",GPIO.HIGH)
    print("GPIO >> HIGH")
    time.sleep(1)

GPIO.cleanup()

Ejemplo n.º 21
0
def ADCinit():	
	RegWrite(ADS1248.MUX0, 0b00000001);	# MUX0:  Pos. input: AIN0, Neg. input: AIN1 (Burnout current source off) 
	RegWrite(ADS1248.MUX1, 0b00100000);	# MUX1:  REF0, normal operation
	RegWrite(ADS1248.SYS0, 0b00000000);	# SYS0:  PGA Gain = 1, 5 SPS
	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)
Ejemplo n.º 22
0
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):
    print "Writing " + num + "..."
    GPIO.output(chipSelect, GPIO.LOW)
    print str(spi.xfer2([int(num)]))
Ejemplo n.º 23
0
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() 
Ejemplo n.º 24
0
#!/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
Ejemplo n.º 25
0
#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)
    GPIO.output(chipselect, GPIO.LOW)
    spi.readbytes(len(lst))
    GPIO.output(chipselect, GPIO.HIGH)
    sleep(1)
    GPIO.output(chipselect, GPIO.LOW)
    spi.writebytes(lst)
    GPIO.output(chipselect, GPIO.HIGH)
    sleep(1)
Ejemplo n.º 26
0
#!/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
Ejemplo n.º 27
0
    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,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Ejemplo n.º 28
0
#!/usr/bin/python

from Adafruit_BBIO.SPI import SPI

import Adafruit_BBIO.GPIO as GPIO
import time

spi = SPI(1, 1)  #4 busses, this is bus 0
spi.msh = 500000  #Frequency
spi.bpw = 8  #bits per word
spi.cshigh = True  #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.mode=3
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
        #spi.cshigh=False

        res1 = spi.readbytes(10)
        angle = (res1[0] << 8) | res1[1]  #merge leftbyte and rightbyte
        angle1 = angle & 0x3FFF  #move the first two bits
        angle2 = float(angle1) / 16363 * 360
        #print("res    is", str(res))
        print("res1   is", str(res1))
        print("angle  is", str(angle))
Ejemplo n.º 29
0
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"
Ejemplo n.º 30
0
#!/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