test_name = 'constant'  # Name of test to run - constant volate voltammetery
curr_range = '100uA'  # Name of current range for test [-10uA, +10uA]
sample_rate = 100.0  # Rate (samples/sec) at which to collect samples

test_param = {
    'quietValue': 0.0,  # Output voltage during quiet peroid
    'quietTime': 1000,  # Duration of quiet period (ms)
    'value': 2.5,  # Output volatage (V) durring constant voltage test
    'duration': 4000,  # Duration of constant voltage test (ms)
}

# Create Device object and set sample rate, current range and test parameters
dev = Potentiostat(port)
dev.set_sample_rate(sample_rate)
dev.set_curr_range(curr_range)
dev.set_param(test_name, test_param)

# Run cyclic voltammetry test
t, volt, curr = dev.run_test(test_name, display='pbar', filename=datafile)

# plot results using matplotlib
plt.subplot(211)
plt.title('Voltage and current vs time')
plt.plot(t, volt)
plt.ylabel('potential (V)')
plt.ylim(0, test_param['value'] * 1.1)
plt.grid('on')

plt.subplot(212)
plt.plot(t, curr)
Пример #2
0
from potentiostat import Potentiostat
import sys
import time

if len(sys.argv) > 1:
    port = sys.argv[1]
else:
    port = '/dev/ttyACM0'

channel_list = [1, 7]
num_sample = 10
sleep_dt = 0.25

dev = Potentiostat(port)
dev.set_volt_range('5V')
dev.set_curr_range('100uA')

dev.set_mux_enabled(True)
dev.set_enabled_mux_channels(channel_list)
dev.set_mux_ref_elect_connected(True)
dev.set_mux_ctr_elect_connected(True)

print()

for channel in channel_list:

    print('testing channel: ', channel)
    print('----------------------------------------------')

    dev.set_mux_wrk_elect_connected(channel)
    dev.set_volt(0.0)
Пример #3
0
    v0 = -0.9  # Initial voltage (V)
    v1 = 1.2  # Final voltage (V)

    amp = 0.1  # Sinusoid ampliude (V)
    per = 2.0  # Sinusoid period (s)

    dt = 0.05  # Time step for setting voltage and measurements
    t_total = 60.0  # Total experiment duration

    volt_func = create_sin_linear_func(t0, t1, v0, v1, amp, per)

    # Create device object, set voltage/current ranges and run test
    pstat = Potentiostat('/dev/ttyACM0')
    pstat.set_volt_range('2V')
    pstat.set_curr_range('100uA')
    t, volt, curr = run_manual_test(pstat, volt_func, dt, t_total)

    # Plot results
    plt.subplot(211)
    plt.plot(t, volt)
    plt.ylabel('potential (V)')
    plt.grid('on')

    plt.subplot(212)
    plt.plot(t, curr)
    plt.xlabel('time (s)')
    plt.ylabel('current (uA)')
    plt.grid('on')
    plt.show()
        'step': [(1000, -0.25), (1000, 0.5)],
    },

    # Multistep Test Data
    {
        'quietValue':
        0.0,
        'quietTime':
        1000,
        'step': [(1000, -0.5), (1000, -0.2), (1000, -0.3), (1000, -0.0),
                 (1000, -0.1), (1000, 0.3), (1000, 0.2), (1000, 0.5)],
    },
]

cpp = Potentiostat(port)
cpp.set_curr_range(curr_range)
cpp.set_sample_rate(sample_rate)
print(test_name[int_test], test_data[int_test])
cpp.set_param(test_name[int_test], test_data[int_test])

t, volt, curr = cpp.run_test(test_name[int_test], display='pbar')
file = open(datafile[int_test], 'w')
file.write('Time \n' + str(t) + '\n' + 'Volt \n' + str(volt) + '\n'
           'Curr \n' + str(curr) + '\n')
plt.figure(1)
plt.subplot(211)
plt.plot(t, volt)
plt.ylabel('potential (V)')
plt.grid('on')

plt.subplot(212)
Пример #5
0
class ConstVoltLogger(object):
    def __init__(self, param):
        """
        param - dictionary of parameters for the constant voltage test. It
        should contain the following items.

         filename      Data log filename
         port          Potentiostat serial port
         volt_range    Output voltage range
         curr_range    Measurement current range
         sample_dt     Sample period (s)
         volt          # Output voltage (V)

        """
        self.param = param
        self.done = False
        self.sep = ','

        self.pstat = Potentiostat(self.param['port'])
        self.pstat.set_volt_range(self.param['volt_range'])
        self.pstat.set_curr_range(self.param['curr_range'])
        self.pstat.set_volt(self.param['volt'])

        self.scheduler = sched.scheduler(time.time, time.sleep)
        self.scheduler_event = None
        signal.signal(signal.SIGINT, self.sigint_handler)

    def get_file_start_time(self):
        t_start_file = None
        if os.path.exists(self.param['filename']):
            line_list = []
            with open(self.param['filename'], 'r') as fid:
                try:
                    line_list = fid.readlines()
                    start_line = line_list[0]
                    start_line = start_line.split(self.sep)
                    t_start_file = float(start_line[0])
                except:
                    pass
        return t_start_file

    def run(self):
        self.done = False
        t_start = time.time()
        t_start_file = self.get_file_start_time()
        if t_start_file is None:
            t_start_file = t_start

        print()
        print('press ctl-c to exit')
        print()
        print('t (s), current (A)')
        print('------------------')

        with open(self.param['filename'], 'a') as fid:
            cnt = 0
            while not self.done:
                curr = self.pstat.get_curr()
                t_current = time.time()
                t_elapsed = t_current - t_start_file

                fid.write('{0}{1} {2}{3}'.format(t_current, self.sep, curr,
                                                 os.linesep))
                print('{0:1.2f}{1} {2:1.4f}'.format(t_elapsed, self.sep, curr))

                t_next = t_start + (cnt + 1) * self.param['sample_dt']
                self.scheduler_event = self.scheduler.enterabs(
                    t_next, 1, lambda: None, ())
                self.scheduler.run()
                cnt += 1

    def sigint_handler(self, signum, frame):
        self.scheduler.cancel(self.scheduler_event)
        self.done = True
Пример #6
0
    port = sys.argv[1]
else:
    port = '/dev/ttyACM0'

dev = Potentiostat(port)


# Set current range
# ---------------------------------------------------------------------

new_curr_range = "10uA"

curr_range = dev.get_curr_range()
print('volt range: {0}'.format(curr_range))

curr_range = dev.set_curr_range(new_curr_range)
print('volt range: {0}'.format(curr_range))

curr_range = dev.get_curr_range()
print('volt range: {0}'.format(curr_range))
print()



# Set voltage range. 
# --------------------------------------------------------------------
# Note, this is only need for manual operation as the voltage range is 
# automatically set from the parameters when running tests.

new_volt_range = "5V"
volt_range = dev.get_volt_range()