diff --git a/electrode_check.py b/electrode_check.py index fcf4330..0341bd2 100644 --- a/electrode_check.py +++ b/electrode_check.py @@ -1,20 +1,10 @@ from __future__ import print_function import os import datetime -from shutil import copyfile - -try: - import RPi.GPIO as GPIO -except: - pass import subprocess import numpy as np import matplotlib.pyplot as plt import matplotlib.gridspec as gridspec -from time import sleep, time -from os import system -from sys import stdout -from IPython import embed from uldaq import (get_daq_device_inventory, DaqDevice, AInScanFlag, ScanStatus, ScanOption, create_float_buffer, InterfaceType, AiInputMode) @@ -77,31 +67,9 @@ class plot(): if show_y[enu] == False: ax.tick_params(axis='y', which='both', left=False, right=False, labelleft=False) - self.axs.append(ax) -def GPIO_setup(LED1_pin, LED2_pin, Button1_pin, Button2_pin): - # LED output pins - GPIO.setmode(GPIO.BOARD) - - GPIO.setup(LED1_pin, GPIO.OUT) # 1 - GPIO.output(LED1_pin, GPIO.LOW) - GPIO.setup(LED2_pin, GPIO.OUT) # 2 - GPIO.output(LED2_pin, GPIO.LOW) - - LED_status = [False, False] - - # switch controlled input - GPIO.setup(Button1_pin, GPIO.IN) - GPIO.setup(Button2_pin, GPIO.IN) - - # GPIO.setup(Button1_pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) - # GPIO.setup(Button2_pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) - - return LED_status - - def read_cfg(cfg_file, now, init_read=False): cfg_f = open(cfg_file, 'r+') cfg = cfg_f.readlines() @@ -142,76 +110,6 @@ def read_cfg(cfg_file, now, init_read=False): return channels, samplerate, n_cols, n_rows, max_v, gain - # for line in cfg: - # if 'Columns1' in line: - # self.Grid.columns_val = int(line.split(':')[1].strip()) - # elif 'Rows1' in line: - # self.Grid.rows_val = int(line.split(':')[1].strip()) - # elif "ColumnDistance1" in line: - # self.Grid.col_dist_val = float(line.split(':')[-1].strip().replace('cm', '')) - # elif "RowDistance1" in line: - # self.Grid.row_dist_val = float(line.split(':')[-1].strip().replace('cm', '')) - # elif "ChannelOffset1" in line: - # self.Grid.channel_offset_val = int(line.split(':')[-1].strip()) - # elif "ElectrodeType1" in line: - # self.Grid.elec_type_val = line.split(':')[-1].strip() - # elif "RefElectrodeType1" in line: - # self.Grid.ref_elec_type_val = line.split(":")[-1].strip() - # elif "RefElectrodePosX1" in line: - # self.Grid.ref_elec_posx_val = float(line.split(':')[-1].strip().replace('m', '')) - # elif 'RefElectrodePosY1' in line: - # self.Grid.ref_elec_posy_val = float(line.split(':')[-1].strip().replace('m', '')) - # elif 'WaterDepth1' in line: - # self.Grid.water_depth_val = float(line.split(':')[-1].strip().replace('m', '')) - # - # elif "AISampleRate" in line: - # self.HardWare.ai_sr_val = float(line.split(':')[-1].strip().replace('kHz', '')) - # elif "AIMaxVolt" in line: - # self.HardWare.ai_max_vol_val = float(line.split(':')[-1].strip().replace('mV', '')) - # elif "AmplName" in line: - # self.HardWare.amp_name_val = line.split(':')[-1].strip() - # elif "AmplModel" in line: - # self.HardWare.amp_model_val = line.split(':')[-1].strip() - # elif ' Type ' in line: - # self.HardWare.amp_type_val = line.split(':')[-1].strip() - # elif 'Gain' in line: - # self.HardWare.gain_val = line.split(':')[-1].strip() - # elif "HighpassCutoff" in line: - # self.HardWare.highpass_cutoff_val = int(line.split(':')[-1].strip().replace('Hz', '')) - # elif 'LowpassCutoff' in line: - # self.HardWare.lowpass_cutoff_val = float(line.split(':')[-1].strip().replace('kHz', '')) - # - # elif "Experiment.Name" in line: - # self.Recording.experiment_name_val = line.split(':')[-1].strip() - # elif "StartDate" in line: - # self.Recording.startdate_val = line.split(':')[-1].strip() - # elif "StartTime" in line: - # self.Recording.starttime_val = ':'.join(line.split(':')[1:]).strip() - # elif "Location" in line: - # self.Recording.location_val = line.split(':')[-1].strip() - # elif "Position" in line: - # self.Recording.position_val = line.split(':')[-1].strip() - # elif "WaterTemperature" in line: - # self.Recording.water_temp_val = float(line.split(':')[-1].strip().replace('C', '')) - # elif "WaterConductivity" in line: - # self.Recording.water_cond_val = float(line.split(':')[-1].strip().replace('uS/cm', '')) - # elif 'WaterpH' in line: - # self.Recording.water_ph_val = float(line.split(':')[-1].strip().replace('pH', '')) - # elif "WaterOxygen" in line: - # self.Recording.water_oxy_val = float(line.split(':')[-1].strip().replace('mg/l', '')) - # elif "Comment" in line: - # self.Recording.comment_val = ':'.join(line.split(':')[1:]).strip() - # elif "Experimenter" in line: - # self.Recording.experimenter_val = ':'.join(line.split(':')[1:]).strip() - # elif "DataTime" in line: - # self.Recording.datatime_val = int(line.split(':')[-1].strip().replace('ms', '')) - # elif "DataInterval" in line: - # self.Recording.datainterval_val = int(line.split(':')[-1].strip().replace('ms', '')) - # elif "BufferTime" in line: - # self.Recording.buffertime_val = int(line.split(':')[-1].strip().replace('s', '')) - # else: - # continue - def main(): now = datetime.datetime.now() @@ -232,15 +130,6 @@ def main(): # read and edit config file channels, rate, n_cols, n_rows, max_v, gain = read_cfg(init_cfgfile, now) - LED1_pin = 11 - LED2_pin = 13 - Button1_pin = 16 - Button2_pin = 18 - - # LED_status = GPIO_setup(LED1_pin, LED2_pin, Button1_pin, Button2_pin) - - - # DAQ setup if True: status = ScanStatus.IDLE @@ -311,34 +200,11 @@ def main(): break print(ranges[range_index]) - # range_index = 0 - # if range_index >= len(ranges): - # range_index = len(ranges) - 1 - - # Allocate a buffer to receive the data. data = create_float_buffer(channel_count, samples_per_channel) - # system('clear') - # Start the acquisition. rate = ai_device.a_in_scan(low_channel, high_channel, input_mode, ranges[range_index], samples_per_channel, rate, scan_options, flags, data) last_idx = 0 - # f = open('/media/pi/data1/test_file.raw', 'wb') - - # LED on when here ... wait for switch to start data aquisition - - # GPIO.output(LED1_pin, GPIO.HIGH) - # LED_status[0] = True - # while GPIO.input(Button1_pin) == GPIO.LOW: - # sleep(.1) - # sleep(2) - # GPIO.output(LED1_pin, GPIO.LOW) - # LED_status[0] = False - - LED_t = time() - LED_t_interval = 2 - - disp_eth_power = True Plot = plot() Plot.max_v = max_v @@ -351,35 +217,6 @@ def main(): init_fig = True try: while True: - # blinking LED - # if time() - LED_t < .1 and LED_status[0] == False: - # LED_status[0] = True - # GPIO.output(LED1_pin, GPIO.HIGH) - # if time() - LED_t >= .1 and LED_status[0] == True: - # LED_status[0] = False - # GPIO.output(LED1_pin, GPIO.LOW) - # if time() - LED_t >= LED_t_interval: - # LED_t = time() - # - # # dist & eth0 controll - # if GPIO.input(Button2_pin) == GPIO.HIGH: - # if disp_eth_power == True: - # subprocess.run(['tvservice', '-o']) - # subprocess.run(['vcgencmd', 'display_power', '0']) - # - # subprocess.run(['sudo', 'ip', 'link', 'set', 'eth0', 'down']) - # disp_eth_power = False - # else: - # if disp_eth_power == False: - # subprocess.run(['tvservice', '-p']) - # subprocess.run(['vcgencmd', 'display_power', '1']) - # subprocess.run(['sudo', '/bin/chvt', '6']) - # subprocess.run(['sudo', '/bin/chvt', '7']) - # - # subprocess.run(['sudo', 'ip', 'link', 'set', 'eth0', 'up']) - # disp_eth_power = True - - # Get the status of the background operation status, transfer_status = ai_device.get_scan_status() index = transfer_status.current_index @@ -428,15 +265,6 @@ def main(): daq_device.disconnect() daq_device.release() - if disp_eth_power == False: - subprocess.run(['tvservice', '-p']) - subprocess.run(['vcgencmd', 'display_power', '1']) - subprocess.run(['sudo', '/bin/chvt', '6']) - subprocess.run(['sudo', '/bin/chvt', '7']) - - # subprocess.run(['sudo', 'ip', 'link', 'set', 'eth0', 'up']) - # GPIO.cleanup() - if __name__ == '__main__': main() diff --git a/grid_recorder.py b/grid_recorder.py index 049d2a1..0970b4a 100644 --- a/grid_recorder.py +++ b/grid_recorder.py @@ -152,7 +152,7 @@ class Recorder(): self.high_channel = self.config.channels - 1 self.buffer_sec = 20 - self.samples_per_channel = self.samplerate * self.buffer_sec # * channels = Buffer size + self.samples_per_channel = self.config.samplerate * self.buffer_sec # * channels = Buffer size self.buffer_size = self.samples_per_channel * self.config.channels print('\nChannels: %.0f' % self.config.channels) # rate = 20000 @@ -292,8 +292,8 @@ class Recorder(): temp_interval = 300 # sec --> 5 min disp_eth_power = True - self.samplerate = self.ai_device.a_in_scan(self.low_channel, self.high_channel, self.input_mode, self.ranges[self.range_index], self.samples_per_channel, - self.samplerate, self.scan_options, self.flags, data) + self.config.samplerate = self.ai_device.a_in_scan(self.low_channel, self.high_channel, self.input_mode, self.ranges[self.range_index], self.samples_per_channel, + self.config.samplerate, self.scan_options, self.flags, data) status, transfer_status = self.ai_device.get_scan_status() last_idx = 0 @@ -322,7 +322,7 @@ class Recorder(): disp_eth_power = True last_button_2_t = time() - if self.record_temp == True: + if self.config.record_temp == True: if time() - temp_t0 > next_temp_t: w1_f = open(self.w1_bus_path, 'r') w1_file = w1_f.readlines() @@ -348,7 +348,7 @@ class Recorder(): # sync LED if (time() - LED_t0) % sync_LED_t_interval < .1 and self.LED_status[2] == False: if self.led_f != None: - Cidx = int((self.buffer_size * buffer_no + last_idx) / self.channels) + Cidx = int((self.buffer_size * buffer_no + last_idx) / self.config.channels) self.led_f.write('%.4f\n' % (time() - LED_t0)) self.led_f.flush() self.led_f2.write('%.0f\n' % Cidx) @@ -377,7 +377,7 @@ class Recorder(): else: (np.array(data[last_idx:], dtype=np.float32) / self.config.gain).tofile(self.f) - if datetime.datetime.now().hour * 60 + datetime.datetime.now().minute >= self.end_clock[0] * 60 + self.end_clock[1]: + if datetime.datetime.now().hour * 60 + datetime.datetime.now().minute >= self.config.end_clock[0] * 60 + self.config.end_clock[1]: self.f.flush() GPIO.output(self.LED1_pin, GPIO.LOW) GPIO.output(self.LED_out_pin, GPIO.LOW) @@ -391,7 +391,8 @@ class Recorder(): print('\nDone!') self.f.close() - self.temp_f.close() + if self.config.record_temp == True: + self.temp_f.close() self.led_f.close() GPIO.output(self.LED1_pin, GPIO.HIGH) @@ -426,7 +427,7 @@ def main(): rec_duration = int(sys.argv[1]) config.start_clock = [config.now.hour, config.now.minute] config.end_clock = [config.now.hour, config.now.minute + rec_duration] - if config.end_clock[2] >= 60: + if config.end_clock[1] >= 60: config.end_clock[0] += 1 config.end_clock[1] -= 60