Esempio 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
Esempio 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)
Esempio n. 3
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
Esempio n. 4
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
Esempio n. 5
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()
Esempio n. 6
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("/")
Esempio n. 7
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("/")
Esempio n. 8
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"
Esempio n. 9
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"
Esempio n. 10
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
Esempio n. 11
0
#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
from Adafruit_BBIO.SPI import SPI

spi = SPI(0,0)
spi.open(0,0)
#spi.msh = 100000
spi.bpw = 8
#spi.mode = b00
try:
#while True:
        # set CS bit high, choose first channel to read from

        #channel = 0;
        #adc = spi.xfer([1,8,0])
        #data = ((adc[1]&3) << 8) + adc[2]

        channelSelect = 0xC0
        channelSelect |= 0x18
        channelSelect <<= 3
        fsr = spi.xfer2([channelSelect, 0x00, 0x00])
        #result = spi.readbytes(2)
        #result2 = spi.readbytes(1)

        resultFinal = 0x0000
        resultFinal = 0x0300 & (resultFinal | (fsr[1] << 8 ))
        resultFinal |= ( ( 0x00FF  & fsr[2]) )
        #print (8 + channel ) << 4
        #print resultFinal

	###################################
	####################################
	resultFinal = 1 #temp
Esempio n. 13
0
from Adafruit_BBIO.SPI import SPI

import time
#https://github.com/adafruit/adafruit-beaglebone-io-python
# Constants
VREF = 4.36


spi = SPI(0,0) 

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


secondsAddress 		    	= 0x81
minutesAddress 			    = 0x82
hoursAddress			    = 0x83
dayOfWeekAddress		    = 0x84
dayOfMonthAddress		    = 0x85
monthCenturAddressy	    	= 0x86
yearAddressr				= 0x87

secondsReadAddress 			= 0x01
minutesReadAddress 			= 0x02
hoursReadAddress			= 0x03
dayOfWeekReadAddress	    = 0x04
dayOfMonthReadAddress	    = 0x05
monthCenturReadAddressy	    = 0x06
yearReadAddressr			= 0x07
Esempio n. 14
0
	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)

time.sleep(0.02)