예제 #1
0
class AnalogMFC(object):
    """ Driver for controling an analog MFC (or PC) with
    an AB Electronics ADCDAC """
    def __init__(self, channel, fullrange, voltagespan):
        self.channel = channel
        self.fullrange = fullrange
        self.voltagespan = voltagespan
        self.daq = ADCDACPi()  # create an instance of ADCDACPi
        self.daq.set_adc_refvoltage(3.3)

    def read_flow(self):
        """ Read the flow (or pressure) value """
        value = 0
        for _ in range(0, 10): # Average to minimiza noise
            value += self.daq.read_adc_voltage(1)
        value = value / 10
        #print('Value: ' + str(value))
        flow = value * self.fullrange / self.voltagespan
        return flow

    def set_flow(self, flow):
        """ Set the wanted flow (or pressure) """
        voltage = flow *  self.voltagespan / self.fullrange
        print('Voltage: ' + str(voltage))
        self.daq.set_dac_voltage(1, voltage)
        return voltage
#!/usr/bin/python

from ABE_ADCDACPi import ADCDACPi
import time

"""
================================================
ABElectronics ADCDAC Pi 2-Channel ADC, 2-Channel DAC | ADC Read Demo
Version 1.0 Created 17/05/2014
Version 1.1 16/11/2014 updated code and functions to PEP8 format

run with: python demo-adcread.py
================================================

this demo reads the voltage from channel 1 on the ADC inputs
"""

adcdac = ADCDACPi(1)  # create an instance of the ADCDAC Pi with a DAC gain set to 1

# set the reference voltage.  this should be set to the exact voltage
# measured on the raspberry pi 3.3V rail.
adcdac.set_adc_refvoltage(3.3)

while True:
    # read the voltage from channel 1 and display on the screen
    print adcdac.read_adc_voltage(1)
    time.sleep(0.5)
예제 #3
0
파일: demo.py 프로젝트: i-sri/elctro
#!/usr/bin/python
from ABE_ADCDACPi import ADCDACPi
import time
adcdac = ADCDACPi()
adcdac.set_adc_refvoltage(3.3)

while True:
   v = adcdac.read_adc_voltage(1)
   if (v < 2.2) :
      print v
   time.sleep(0.001)
예제 #4
0
#!/usr/bin/python

from ABE_ADCDACPi import ADCDACPi
import time
"""
================================================
ABElectronics ADCDAC Pi 2-Channel ADC, 2-Channel DAC | ADC Read Demo
Version 1.0 Created 17/05/2014
Version 1.1 16/11/2014 updated code and functions to PEP8 format

run with: python demo-adcread.py
================================================

this demo reads the voltage from channel 1 on the ADC inputs
"""

adcdac = ADCDACPi(
    1)  # create an instance of the ADCDAC Pi with a DAC gain set to 1

# set the reference voltage.  this should be set to the exact voltage
# measured on the raspberry pi 3.3V rail.
adcdac.set_adc_refvoltage(3.3)

while True:
    # read the voltage from channel 1 and display on the screen
    print adcdac.read_adc_voltage(1)
    time.sleep(0.5)
예제 #5
0
"""

adcdac = ADCDACPi(1)  # create an instance of the ADCDAC Pi with a DAC gain set to 1

# set the reference voltage.  this should be set to the exact voltage
# measured on the raspberry pi 3.3V rail.
adcdac.set_adc_refvoltage(3.3)

counter = 1
totalsamples = 100000

a = N.zeros(totalsamples)

starttime = datetime.datetime.now()
print ("Start: " + str(starttime))

while (counter < totalsamples):
    # read the voltage from channel 1 and display on the screen
    a[counter] = adcdac.read_adc_voltage(1,0)

    counter = counter + 1

endtime = datetime.datetime.now()

print ("End: " + str(endtime))
totalseconds = (endtime - starttime).total_seconds()

samplespersecond = totalsamples / totalseconds

print (str(samplespersecond) + " samples per second")
예제 #6
0
#!/usr/bin/python3

from ABE_ADCDACPi import ADCDACPi
import time
"""
================================================
ABElectronics ADCDAC Pi 2-Channel ADC, 2-Channel DAC | ADC Read Demo
Version 1.0 Created 29/02/2015

run with: python3 demo-adcread.py
================================================

this demo reads the voltage from channel 1 on the ADC inputs
"""

adcdac = ADCDACPi()  # create an instance of ADCDACPi

# set the reference voltage.  this should be set to the exact voltage
# measured on the raspberry pi 3.3V rail.
adcdac.set_adc_refvoltage(3.3)

while True:
    # read the voltage from channel 1 in single ended mode and display on the screen
    print(adcdac.read_adc_voltage(1, 0))
    time.sleep(0.5)
#!/usr/bin/python3

from ABE_ADCDACPi import ADCDACPi
import time

"""
================================================
ABElectronics ADCDAC Pi 2-Channel ADC, 2-Channel DAC | ADC Read Demo
Version 1.0 Created 29/02/2015

run with: python3 demo-adcread.py
================================================

this demo reads the voltage from channel 1 on the ADC inputs
"""

adcdac = ADCDACPi()  # create an instance of ADCDACPi

# set the reference voltage.  this should be set to the exact voltage
# measured on the raspberry pi 3.3V rail.
adcdac.set_adc_refvoltage(3.3)

while True:
    # read the voltage from channel 1 in single ended mode and display on the screen
    print (adcdac.read_adc_voltage(1, 0))
    time.sleep(0.5)
from ABE_ADCDACPi import ADCDACPi
import time
import datetime
"""
================================================
ABElectronics ADCDAC Pi 2-Channel ADC, 2-Channel DAC | ADC Read Demo
Version 1.0 Created 17/05/2014
Version 1.1 16/11/2014 updated code and functions to PEP8 format
run with: python demo-adcread.py
================================================
this demo reads the voltage from channel 1 on the ADC inputs
"""

adcdac = ADCDACPi(
    1)  # create an instance of the ADCDAC Pi with a DAC gain set to 1

# set the reference voltage.  this should be set to the exact voltage
# measured on the raspberry pi 3.3V rail.
adcdac.set_adc_refvoltage(3.3)
counter = 1
starttime = datetime.datetime.now()
print starttime
while (counter < 1000000):
    # read the voltage from channel 1 and display on the screen
    varx = adcdac.read_adc_voltage(1)
    counter = counter + 1
endtime = datetime.datetime.now()

print endtime - starttime
print endtime
예제 #9
0
class DetectPi:
    def __init__(self):
        '''
		Initialise ADC-DAC Pi. The DAC gain factor is set to 1, which allows 
		the DAC output voltage to be set between 0 and 2.048 V. The DAC gain 
		factor may also be set to 2, which gives an output range of 0 to 3.3 V.
		'''

        # Create instance of ADCDACPi, with gain set to 1
        self.adcdac = ADCDACPi(1)

        # Set reference voltage to 3.3 V
        self.adcdac.set_adc_refvoltage(3.3)

        return

    def getDetails(self):
        '''
		Return details of ADC_DAC Pi. This function does not currently return 
		any details, but this may change later.
		'''

        return

    def writePort(self, Port, Volt):
        '''
		Write values to a DAC pin. Values may be written to either channel 1 
		or channel 2. The maximum voltage is specified by the gain factor.
		Note: Setting a voltage of 5 V will return an error for exceeding 
		the maximum voltage.
		'''

        # Ensure port is of type list
        if type(Port) == str:
            Port = [Port]

        # Convert DAQT7 DAC ports to DAC Pi channels
        if "DAC0" in Port:
            channel = 1
        elif "DAC1" in Port:
            channel = 2

        # Set DAC output voltage <Volt> on channel <channel>
        self.adcdac.set_dac_voltage(channel, Volt)

        return

    def readPort(self, Port):
        '''
		Read values from an ADC pin. Values may be read from either channel 1 
		or channel 2. 
		'''

        # Ensure port is of type list
        if type(Port) == str:
            Port = [Port]

        # Convert DAQT7 AIN ports to ADC Pi channels
        if "AIN0" in Port:
            channel = 1
        elif "AIN1" in Port:
            channel = 2

        # Read voltage from channel <channel> in single ended mode
        voltRead = self.adcdac.read_adc_voltage(channel, 0)

        return np.float(voltRead), time.time()

    def streamRead(self, scanRate, scansPerRead, Port):
        '''
		Read analogue input values from an ADC pin, in stream mode.
		'''

        # Ensure port is of type list
        if type(Port) == str:
            Port = [Port]

        # Initialise array and time values
        Read = [0, 1, 2]
        StartingMoment = 0
        FinishingMoment = 0
        scansPerRead = int(scansPerRead)

        # Determine timing characteristics
        duration = scansPerRead / float(scanRate)
        dt = 1 / float(scanRate)
        StartingMoment = time.time()

        # Allow for alternation between multiple ports
        portIndex = 0
        portLength = len(Port)

        # Loop for the duration
        while (time.time() - StartingMoment) < duration:
            # Read the ADC value and append to an array
            voltRead = self.readPort(Port[portIndex])[0]
            Read[0].append(voltRead)
            portIndex = (portIndex + 1) % portLength

            # Wait for the program to run at the correct frequency
            lastReadTime = readTime
            readTime = time.time()
            if readTime - lastReadTime < dt:
                time.sleep(dt - readTime + lastReadTime)

        # Calculate and print elapsed time
        FinishingMoment = time.time()
        print('Elapsed time %f seconds' % (FinishingMoment - StartingMoment))

        return Read, StartingMoment, FinishingMoment

    def close(self):
        '''
		Close ADC-DAC Pi.
		'''

        pass
예제 #10
0
def main(args):
	user_input = sys.argv
	startV = float(user_input[1])
	maxV = float(user_input[2])
	# lowV = float(user_input[3])
	# endV = float(user_input[4])

	print("User has typed in : %s" %user_input)
	print("Test starts at %.3f volts" %startV)
	print("Test peaks at %.3f volts" %maxV)

	# initialize
	adcdac = ADCDACPi(1) # create an instance of the ADCDAC Pi with a DAC gain set to 1
	adcdac.set_adc_refvoltage(3.3) # powered off 3.3V GPIO rail

	# TODO: add in sample number
	csv_filename, test_csv = open_csv(1)

	# Hardware settings/references
	shunt_resistor = 10 # 10 Ohms
		# High-Side Current Monitor IC
	gain = 500
		# DAC Vref = 2.048v internal
		# ADC Vref = Vdd = 3.3v

	# start test
	raw_input("Press [Enter] to view Conditions")
	adcdac.set_dac_voltage(1, startV)  # set the voltage on channel 1
	voltage = startV
	# 1mV increments
		# init = int(startV*1000)
		# peak = int(maxV*1000)
	# 10mV increments
	init = int(startV*100)
	peak = int(maxV*100)
	count = 0
	print("START is %0.3f VOLTS" %voltage)
	print("HIGH is %0.3f VOLTS" %maxV)
	print("INIT is %0.3f UNITS" %init)
	print("PEAK is %0.3f UNITS" %peak)
	raw_input("Press [Enter] to begin the test")

	# ramp up
	for i in range (init, peak, 1):
		adcdac.set_dac_voltage(1, voltage)
		# read channel 1 in single ended mode
		voltage_reading = adcdac.read_adc_voltage(1, 0)
		#print("%0.3f counts" %i)
		# Vdrop @ shunt = voltage_reading/gain
		# Current = Vdrop/Rshunt
		calc_current = (voltage_reading/gain)/shunt_resistor
		print("%.3f volts driven, %.3f volts seen" %(voltage, voltage_reading))
		print("Calculated current is %.5f mA \n" %(calc_current*1000))
		#save test results
		count = count + 1
		test_csv.write("%d, %.3f, %.3f, %s\n" %(count, voltage, voltage_reading, calc_current))
		voltage = voltage+0.01
		time.sleep(0.040)
	# ramp down
	for i in range (peak, init-1, -1):
		adcdac.set_dac_voltage(1, voltage)
		# read channel 1 in single ended mode
		voltage_reading = adcdac.read_adc_voltage(1, 0)
		#print("%0.3f counts" %i)
		calc_current = (voltage_reading/gain)/shunt_resistor
		print("%.3f volts driven, %.3f volts seen" %(voltage, voltage_reading))
		print("Calculated current is %.5f mA \n" %(calc_current*1000))
		#save test results
		count = count + 1
		test_csv.write("%d, %.3f, %.3f, %s\n" %(count, voltage, voltage_reading, calc_current))
		voltage = voltage-0.01
		time.sleep(0.040)  

	raw_input("press [Enter] to set DAC to 0 volts")
	adcdac.set_dac_voltage(1, 0)    
	test_csv.close()
	upload_file(csv_filename)