コード例 #1
0
ファイル: devices.py プロジェクト: hiveeyes/PyDatalogger
class Device_ABE_DeltaSigmaPiADC:
    """
    https://github.com/abelectronicsuk/ABElectronics_Python_Libraries
    """
    def __init__(self,
                 bus=None,
                 address=None,
                 address2=None,
                 samplerate=None,
                 gain=None):
        from ABE_helpers import ABEHelpers
        from ABE_ADCDifferentialPi import ADCDifferentialPi

        if bus is None:
            i2c_helper = ABEHelpers()
            bus = i2c_helper.get_smbus()

        # Initialize the ADC device using the default addresses and sample rate 18.
        # Sample rate can be 12, 14, 16 or 18.
        self.adc = ADCDifferentialPi(bus,
                                     address=address,
                                     address2=address2,
                                     rate=samplerate)

        # Set amplifier gain to 8.
        if gain is not None:
            self.adc.set_pga(gain)

    def read(self, channel):
        # Returns the voltage from the selected ADC channel - channels 1 to 8.
        return self.adc.read_voltage(channel)
コード例 #2
0
def hallSen():
    # GPIO Setup
    GPIO.setmode(GPIO.BOARD)
    GPIO.setup(7, GPIO.OUT)

    text_file = open("hallSensor_Data.txt", "w")
    initTime = time.time()

    t1 = 0
    t2 = 0
    flag = 0
    diameter = 14  # need to find the actual diameter !!!

    i2c_helper = ABEHelpers()
    bus = i2c_helper.get_smbus()
    adc = ADCDifferentialPi(bus, i2cAddr1, i2cAddr2, bitRate)

    SevenSeg.initDisplay()

    while (True):
        voltage = adc.read_voltage(
            channel
        )  # voltage output from hall sensor (either a pos. or neg. value)
        curTime = time.time(
        ) - initTime  # calculates the current time from time acc. minus time started with

        if voltage < 0.0 and flag == 0:  # if voltage is neg. and we have not passed by the magnet yet
            flag = 1
            t1 = t2  # stores the previous curent time from curTime
            t2 = curTime  # stores the current time in curTime
            rps = 1 / (t2 - t1)  # revolutions per second
            mph = rps * (math.pi) * diameter * (
                3600 / 63360)  # conversion from rps to miles per second
            #mph = rps*60

            #print( str(curTime) + "," + str(voltage) + "," + str(mph) )
            #text_file.write( str(curTime) + "," + str(voltage) + "," + str(mph) + "\n" )

        elif voltage < 0.0 and flag == 1:  # else if voltage is neg. but we are currently still passing by the magnet
            #print( str(curTime) + "," + str(voltage) )
            #text_file.write( str(curTime) + "," + str(voltage) + "\n" )
            temp = 1

        else:  # else the voltage is positive (meaning the magnet is not next the the hall sensor)
            flag = 0
            #print( str(curTime) + "," + str(voltage) )
            #text_file.write( str(curTime) + "," + str(voltage) + "\n" )

        SevenSeg.displayNum(int(mph))

        #time.sleep( 0.0100 )

    text_file.close()
コード例 #3
0
	def run(self):
		global mph
		global flag
		t1 = 0
		t2 = 0
		flagMine = 0
		diameter = 14     # need to find the actual diameter !!!

		i2c_helper = ABEHelpers()
		bus = i2c_helper.get_smbus()
		adc = ADCDifferentialPi(bus, i2cAddr1, i2cAddr2, bitRate)
		while True:
			c.acquire()
			if flag == 1:
				flag = 0
				voltage = adc.read_voltage( channel )               # voltage output from hall sensor (either a pos. or neg. value)
				curTime = time.time() - initTime                    # calculates the current time from time acc. minus time started with

				if voltage < 0.0 and flagMine == 0:                     # if voltage is neg. and we have not passed by the magnet yet
					flagMine = 1
					t1 = t2                                             # stores the previous curent time from curTime
					t2 = curTime                                        # stores the current time in curTime
					rps = 1/(t2 - t1)                                   # revolutions per second
					mph = rps * (math.pi) * diameter * (3600/63360)     # conversion from rps to miles per second
					#mph = rps*60

					#print( str(curTime) + "," + str(voltage) + "," + str(mph) )
					#text_file.write( str(curTime) + "," + str(voltage) + "," + str(mph) + "\n" )

				elif voltage < 0.0 and flagMine == 1:                   # else if voltage is neg. but we are currently still passing by the magnet
					#print( str(curTime) + "," + str(voltage) )
					#text_file.write( str(curTime) + "," + str(voltage) + "\n" )
					temp = 1

				else:                                               # else the voltage is positive (meaning the magnet is not next the the hall sensor)
					flagMine = 0
					#print( str(curTime) + "," + str(voltage) )
					#text_file.write( str(curTime) + "," + str(voltage) + "\n" )

				#mph = mph + 1
				c.notify_all()
			else:
				c.wait()
			c.release()
		text_file.close()	
コード例 #4
0
def StrainGauge():
    text_file = open("strainGuage_Data.txt", "w")

    i2c_helper = ABEHelpers()
    bus = i2c_helper.get_smbus()
    adc = ADCDifferentialPi(bus, i2cAddr1, i2cAddr2, bitRate)

    adc.set_pga(
        1)  # Set the gain of the PDA on the chip (Parameters: gain - 1,2,4,8)

    prev_voltage = 0

    for i in range(10000):
        voltage = adc.read_voltage(channel)  # voltage output from strain Gauge

        changeInVoltage = voltage - prev_voltage
        prev_voltage = voltage

        #print( str(changeInVoltage * 1000) )

        text_file.write(str(voltage) + "\n")
コード例 #5
0
ファイル: devices.py プロジェクト: hiveeyes/PyDatalogger
    def __init__(self,
                 bus=None,
                 address=None,
                 address2=None,
                 samplerate=None,
                 gain=None):
        from ABE_helpers import ABEHelpers
        from ABE_ADCDifferentialPi import ADCDifferentialPi

        if bus is None:
            i2c_helper = ABEHelpers()
            bus = i2c_helper.get_smbus()

        # Initialize the ADC device using the default addresses and sample rate 18.
        # Sample rate can be 12, 14, 16 or 18.
        self.adc = ADCDifferentialPi(bus,
                                     address=address,
                                     address2=address2,
                                     rate=samplerate)

        # Set amplifier gain to 8.
        if gain is not None:
            self.adc.set_pga(gain)
コード例 #6
0
Version 1.0 Created 30/10/2015

Requires python smbus to be installed
run with: python demo-resistance-thermometer.py
================================================


    
Initialise the ADC device using the default addresses and 18 bit sample rate, 
change this value if you have changed the address selection jumpers
Bit rate can be 12,14, 16 or 18
"""

i2c_helper = ABEHelpers()
bus = i2c_helper.get_smbus()
adc = ADCDifferentialPi(bus, 0x68, 0x69, 18)

# the resistor values for the Wheatstone bridge are:
resistor1 = 10000
resistor2 = 10000
resistor3 = 10000
# Input voltage
voltin = 3.3
# Resistance thermometer values from datasheet
bResistance = 3435
t25Resistance = 10000

# Constants
t0 = 273.15
t25 = t0 + 25
コード例 #7
0
# read sensors from https://www.wirelessthings.net/wireless-temperature-sensor
# using USB wireless dongle SRF Stick - USB Radio (868-915Mhz)
# https://www.wirelessthings.net/srf-stick-868-915-mhz-easy-to-use-usb-radio
# and display to screen, each sensor has an ID starting with:
# TA, TB or TC

import serial
baud = 9600
port = '/dev/ttyAMA0'
ser = serial.Serial(port, baud)
ser.timeout = 2

# Setup ADC Chip
i2c_helper = ABEHelpers()
bus = i2c_helper.get_smbus()
adc = ADCDifferentialPi(bus, 0x6a, 0x6a, 16)

# Setup GPIO pin to read pump running status
GPIO.setmode(GPIO.BCM)
GPIO.setup(19, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

# 1 wire temperature sensors
path1 = "/mnt/1wire/28.5B7DC4030000/temperature"
path2 = "/mnt/1wire/28.8C37C4030000/temperature"
path3 = "/mnt/1wire/28.611555030000/temperature"
path4 = "/mnt/1wire/28.8945C4030000/temperature"

# setup variables with default values
varCurrentMinute = 0
varPrevMinute = 0
varNow = datetime.datetime.now()
コード例 #8
0
Version 1.0 Created 04/10/2015

Requires python 3 smbus to be installed
run with: python3 demo-adxl335.py
================================================


    
Initialise the ADC device using the default addresses and 12 bit sample rate, 
change this value if you have changed the address selection jumpers
Bit rate can be 12,14, 16 or 18
"""

i2c_helper = ABEHelpers()
bus = i2c_helper.get_smbus()
adc = ADCDifferentialPi(bus, 0x68, 0x69, 12)

# the conversion factor is the ratio of the voltage divider on the inputs
conversionfactor = 1.666


# setup these static values when the sensor is not moving
xStatic = 0
yStatic = 0
zStatic = 0

xMax = 0
xMin = 0
yMax = 0
yMin = 0
zMax = 0
コード例 #9
0

Requires python smbus to be installed
run with: python demo-logvoltage.py
================================================

Initialise the ADC device using the default addresses and sample rate, change
this value if you have changed the address selection jumpers

Sample rate can be 12,14, 16 or 18
"""


i2c_helper = ABEHelpers()
bus = i2c_helper.get_smbus()
adc = ADCDifferentialPi(bus, 0x68, 0x69, 18)


def writetofile(texttowrtite):
    f = open('adclog.txt', 'a')
    f.write(str(datetime.datetime.now()) + " " + texttowrtite)
    f.closed

while (True):

    # read from adc channels and write to the log file
    writetofile("Channel 1: %02f\n" % adc.read_voltage(1))
    writetofile("Channel 2: %02f\n" % adc.read_voltage(2))
    writetofile("Channel 3: %02f\n" % adc.read_voltage(3))
    writetofile("Channel 4: %02f\n" % adc.read_voltage(4))
    writetofile("Channel 5: %02f\n" % adc.read_voltage(5))
コード例 #10
0
ABElectronics Delta-Sigma Pi 8-Channel ADC demo
Version 1.0 Created 09/05/2014
Version 1.1 16/11/2014 updated code and functions to PEP8 format

Requires python smbus to be installed
run with: python demo-read_voltage.py
================================================


Initialise the ADC device using the default addresses and sample rate, change this value if you have changed the address selection jumpers
Sample rate can be 12,14, 16 or 18
"""

i2c_helper = ABEHelpers()
bus = i2c_helper.get_smbus()
adc = ADCDifferentialPi(bus, 0x68, 0x69, 18)

while (True):

    # clear the console
    os.system('clear')

    # read from adc channels and print to screen
    print("Channel 1: %02f" % adc.read_voltage(1))
    print("Channel 2: %02f" % adc.read_voltage(2))
    print("Channel 3: %02f" % adc.read_voltage(3))
    print("Channel 4: %02f" % adc.read_voltage(4))
    print("Channel 5: %02f" % adc.read_voltage(5))
    print("Channel 6: %02f" % adc.read_voltage(6))
    print("Channel 7: %02f" % adc.read_voltage(7))
    print("Channel 8: %02f" % adc.read_voltage(8))
コード例 #11
0
ABElectronics Delta-Sigma Pi 8-Channel ADC demo
Version 1.0 Created 09/05/2014
Version 1.1 16/11/2014 updated code and functions to PEP8 format

Requires python smbus to be installed
run with: python demo-read_voltage.py
================================================


Initialise the ADC device using the default addresses and sample rate, change this value if you have changed the address selection jumpers
Sample rate can be 12,14, 16 or 18
"""

i2c_helper = ABEHelpers()
bus = i2c_helper.get_smbus()
adc = ADCDifferentialPi(bus, 0x68, 0x69, 18)

while (True):

    # clear the console
    os.system('clear')

    # read from adc channels and print to screen
    print ("Channel 1: %02f" % adc.read_voltage(1))
    print ("Channel 2: %02f" % adc.read_voltage(2))
    print ("Channel 3: %02f" % adc.read_voltage(3))
    print ("Channel 4: %02f" % adc.read_voltage(4))
    print ("Channel 5: %02f" % adc.read_voltage(5))
    print ("Channel 6: %02f" % adc.read_voltage(6))
    print ("Channel 7: %02f" % adc.read_voltage(7))
    print ("Channel 8: %02f" % adc.read_voltage(8))
コード例 #12
0
def hallSen():
    # ADC Setup
    channel = 1  # analog channel number (1-8 inclusive)
    bitRate = 12  # programmable data rate
    # 18 (3.75 SPS) less per sec. but more accurate
    # 16 (  15 SPS) --
    # 14 (  60 SPS) --
    # 12 ( 240 SPS) more per sec. but less accurate

    i2cAddr1 = 0x68  # these addresses are associated with the Address Config. 1
    i2cAddr2 = 0x69

    text_file = open("hallSensor_Data_1.txt", "w")
    initTime = time.time()

    text_file.write(str(globalValue))
    text_file.flush()

    global t1
    global t2
    flag = 0
    diameter = 14  # need to find the actual diameter !!!

    i2c_helper = ABEHelpers()
    bus = i2c_helper.get_smbus()
    adc = ADCDifferentialPi(bus, i2cAddr1, i2cAddr2, bitRate)

    global mph
    global flagThread
    global killH

    while True:
        if killH == True:
            text_file.close()
            time.sleep(10)
        else:
            voltage = adc.read_voltage(
                channel
            )  # voltage output from hall sensor (either a pos. or neg. value)
            curTime = time.time(
            ) - initTime  # calculates the current time from time acc. minus time started with

            if voltage < 0.0 and flag == 0:  # if voltage is neg. and we have not passed by the magnet yet
                flag = 1
                t1 = t2  # stores the previous curent time from curTime
                t2 = curTime  # stores the current time in curTime
                rps = 1 / (t2 - t1)  # revolutions per second
                flagThread = 1
                mph = rps * (math.pi) * diameter * (
                    3600 / 63360)  # conversion from rps to miles per second
                rpm = rps * 60
                flagThread = 0
                #mph = rps*60

                #print( str(curTime) + "," + str(voltage) + "," + str(mph) )
                text_file.write(str(curTime) + "," + str(rpm) + "\n")
                text_file.flush()

            elif voltage < 0.0 and flag == 1:  # else if voltage is neg. but we are currently still passing by the magnet
                #print( str(curTime) + "," + str(voltage) )
                #text_file.write( str(curTime) + "," + str(voltage) + "\n" )
                filler = 0

            else:  # else the voltage is positive (meaning the magnet is not next the the hall sensor)
                flag = 0
                #print( str(curTime) + "," + str(voltage) )
                #text_file.write( str(curTime) + "," + str(voltage) + "\n" )

                #time.sleep( 0.0100 )

    text_file.close()
コード例 #13
0
def hallSen(hallSensor_Num, adcChannel_Num, adcBitRate_Num, i2cAddr1_Num,
            i2cAddr2_Num, outputFile_Name, diameter_Num, hallSensorActive):
    # ADC Setup
    channel = 1  # analog channel number (1-8 inclusive)
    bitRate = 12  # programmable data rate
    # 18 (3.75 SPS) less per sec. but more
    # 16 (  15 SPS) --
    # 14 (	60 SPS) --
    # 12 ( 240 SPS) more per sec. but less accurate

    i2cAddr1 = 0x68  # these address are associated with the Address Config. 1
    i2cAddr2 = 0x69

    text_file = open("hallSensor_Data1.txt", "w")
    initTime = time.time()

    t1 = 0
    t2 = 0

    flag = 0
    diameter = 14  # need to find the actual diameter !!!

    i2c_helper = ABEHelpers()
    bus = i2c_helper.get_smbus()
    adc = ADCDifferentialPi(bus, i2cAddr1, i2cAddr2, bitRate)

    global activeMphValues
    global flagThread

    global activeHallSensors
    activeHallSensors.append(hallSensorActive)

    mph = 0
    activeMphValues.append(mph)
    #activeMphValues[hallSensor_Num-1] = mph

    while activeHallSensors[hallSensor_Num - 1]:
        voltage = adc.read_voltage(
            channel
        )  # voltage output from hall sensor (either a pos. or neg. value)
        curTime = time.time(
        ) - initTime  # calculates the current time from time acc. minus time started with

        if voltage < 0.0 and flag == 0:  # if voltage is neg. and we have not passed by the magnet yet
            flag = 1
            t1 = t2  # stores the previous current time from curTime
            t2 = curTime  # stores the current time in curTime
            rps = 1 / (t2 - t1)  # revolutions per second
            activeMphValues[
                hallSensor_Num -
                1] = (rps * (math.pi) * diameter * (3600 / 63360)
                      ) / 11.5  # conversion from rps to miles per second
            #temp = rps * (math.pi) * diameter * (3600/63360)
            rpm = rps * 60
            #activeMphValues[hallsensor_Num-1] = rpm
            #mph = rps*60

            #print( str(curTime + "," + str(voltage) + "," + str(mph) )
            text_file.write(str(curTime) + "," + str(rpm) + "\n")
            text_file.flush()

        elif voltage < 0.0 and flag == 1:  # else if voltage is neg. but we are currently still passing by the magnet
            #print( str(curTime) + "," + str(voltage) )
            #text_file.write( str(curTime) + "," str(voltage) + "\n" )
            filler = 0

        else:  # else the voltage is positive (meaning the magnet is not next to the hall sensor)
            flag = 0
            #print( str(curTime) + "," + str(voltage) )
            #text_file.write( str(curTime) + "," + str(voltage) + "\n" )
            flag = 0  # added hopefully no problems, if problems comment this out

        #time.sleep( 0.0100 )

    text_file.close()
コード例 #14
0
Version 1.0 Created 19/07/2016


Requires python smbus to be installed
run with: python demo-logvoltage.py
================================================

Initialise the ADC device using the default addresses and sample rate, change
this value if you have changed the address selection jumpers

Sample rate can be 12,14, 16 or 18
"""

i2c_helper = ABEHelpers()
bus = i2c_helper.get_smbus()
adc = ADCDifferentialPi(bus, 0x68, 0x69, 18)


def writetofile(texttowrtite):
    f = open('adclog.txt', 'a')
    f.write(str(datetime.datetime.now()) + " " + texttowrtite)
    f.closed


while (True):

    # read from adc channels and write to the log file
    writetofile("Channel 1: %02f\n" % adc.read_voltage(1))
    writetofile("Channel 2: %02f\n" % adc.read_voltage(2))
    writetofile("Channel 3: %02f\n" % adc.read_voltage(3))
    writetofile("Channel 4: %02f\n" % adc.read_voltage(4))
コード例 #15
0
================================================
ABElectronics ADC Differential Pi 8-Channel ADC demo
Version 1.0 Created 09/05/2014
Version 1.1 16/11/2014 updated code and functions to PEP8 format

Requires python smbus to be installed
run with: python demo-read_voltage.py
================================================


Initialise the ADC device using the default addresses and sample rate, change this value if you have changed the address selection jumpers
Sample rate can be 12,14, 16 or 18
"""

i2c_helper = ABEHelpers()
bus = i2c_helper.get_smbus()
adc = ADCDifferentialPi(bus, 0x68, 0x69, 18)

while (True):

    # clear the console
    os.system('clear')

    # read from adc channels and print to screen
    print ("Channel 1: %d" % adc.read_raw(1))
    print ("Sign Bit: %d" % adc.get_signbit())
   

    # wait 0.5 seconds before reading the pins again
    time.sleep(0.5)
Version 1.0 Created 30/10/2015

Requires python smbus to be installed
run with: python demo-resistance-thermometer.py
================================================


    
Initialise the ADC device using the default addresses and 18 bit sample rate, 
change this value if you have changed the address selection jumpers
Bit rate can be 12,14, 16 or 18
"""

i2c_helper = ABEHelpers()
bus = i2c_helper.get_smbus()
adc = ADCDifferentialPi(bus, 0x68, 0x69, 18)

# the resistor values for the Wheatstone bridge are:
resistor1 = 10000
resistor2 = 10000
resistor3 = 10000
# Input voltage
voltin = 3.3
# Resistance thermometer values from datasheet
bResistance = 3435
t25Resistance = 10000

# Constants
t0 = 273.15;
t25 = t0 + 25;
コード例 #17
0
# read sensors from https://www.wirelessthings.net/wireless-temperature-sensor
# using USB wireless dongle SRF Stick - USB Radio (868-915Mhz)
# https://www.wirelessthings.net/srf-stick-868-915-mhz-easy-to-use-usb-radio
# and display to screen, each sensor has an ID starting with:
# TA, TB or TC

import serial 
baud = 9600 
port = '/dev/ttyAMA0' 
ser = serial.Serial(port, baud) 
ser.timeout = 2 

# Setup ADC Chip
i2c_helper = ABEHelpers()
bus = i2c_helper.get_smbus()
adc = ADCDifferentialPi(bus, 0x6a, 0x6a, 16)


# Setup GPIO pin to read pump running status
GPIO.setmode(GPIO.BCM)
GPIO.setup(19, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)

# 1 wire temperature sensors
path1="/mnt/1wire/28.5B7DC4030000/temperature"
path2="/mnt/1wire/28.8C37C4030000/temperature"
path3="/mnt/1wire/28.611555030000/temperature"
path4="/mnt/1wire/28.8945C4030000/temperature"

# setup variables with default values
varCurrentMinute = 0
varPrevMinute = 0