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
#!/usr/bin/python from ABE_ADCDACPi import ADCDACPi import time """ ================================================ ABElectronics ADCDAC Pi 2-Channel ADC, 2-Channel DAC | DAC Write 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-dacwrite.py ================================================ this demo will generate a 1.5V p-p square wave at 1Hz """ adcdac = ADCDACPi() while True: adcdac.set_dac_voltage(1, 1.5) # set the voltage on channel 1 to 1.5V time.sleep(0.5) # wait 0.5 seconds adcdac.set_dac_voltage(1, 0) # set the voltage on channel 1 to 0V time.sleep(0.5) # wait 0.5 seconds
#!/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)
#!/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)
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 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)