diff --git a/electrode_check.py b/electrode_check.py index cd9c436..683e41e 100644 --- a/electrode_check.py +++ b/electrode_check.py @@ -50,7 +50,6 @@ class plot(): gs.update(left=0.05, bottom=0.05, top=1, right=1, hspace=0, wspace=0) - def GPIO_setup(LED1_pin, LED2_pin, Button1_pin, Button2_pin): # LED output pins GPIO.setmode(GPIO.BOARD) @@ -197,34 +196,19 @@ def main(): print('cfg file missing !!!') quit() - # create save folder and copy cfg file - # path = os.path.join(init_path, now.strftime(path_format)) - # os.makedirs(path) - # copyfile(os.path.join(os.path.split(path)[0], 'fishgrid.cfg'), os.path.join(path, 'fishgrid.cfg')) - # cfgfile = os.path.join(path, 'fishgrid.cfg') - # read and edit config file channels, rate, n_cols, n_rows, max_v = read_cfg(init_cfgfile, now) - # file = os.path.join(path, 'traces-grid1.raw') - # f = open(file, 'wb') - - # f.close() - - # embed() - # quit() - LED1_pin = 11 LED2_pin = 13 Button1_pin = 16 Button2_pin = 18 - LED_status = GPIO_setup(LED1_pin, LED2_pin, Button1_pin, Button2_pin) + # LED_status = GPIO_setup(LED1_pin, LED2_pin, Button1_pin, Button2_pin) # DAQ setup if True: - # channels = 16 status = ScanStatus.IDLE @@ -235,7 +219,7 @@ def main(): low_channel = 0 high_channel = channels - samples_per_channel = 20000 # * channels = Buffer size + samples_per_channel = rate * 2 # * channels = Buffer size # rate = 20000 scan_options = ScanOption.CONTINUOUS flags = AInScanFlag.DEFAULT @@ -298,13 +282,14 @@ def main(): # 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 + + # 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 @@ -319,36 +304,35 @@ def main(): Plot.create_axis() init_fig = True - try: - while GPIO.input(Button1_pin) == GPIO.LOW: + 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 + # 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() @@ -387,7 +371,7 @@ def main(): last_idx = index except KeyboardInterrupt: - embed() + plt.close() pass # f.close() @@ -406,7 +390,7 @@ def main(): subprocess.run(['sudo', '/bin/chvt', '7']) # subprocess.run(['sudo', 'ip', 'link', 'set', 'eth0', 'up']) - GPIO.cleanup() + # GPIO.cleanup() if __name__ == '__main__': diff --git a/grid_main.py b/grid_main.py index 7114cc2..c699f7e 100644 --- a/grid_main.py +++ b/grid_main.py @@ -1,4 +1,5 @@ import os +from time import sleep try: import RPi.GPIO as GPIO except: @@ -32,15 +33,45 @@ def main(): LED_status = GPIO_setup(LED1_pin, LED2_pin, Button1_pin, Button2_pin) + LED_status[0] = True + GPIO.output(LED1_pin, GPIO.HIGH) + LED_status[1] = True GPIO.output(LED2_pin, GPIO.HIGH) while True: - if GPIO.input(Button2_pin) == GPIO.HIGH: + if GPIO.input(Button1_pin) == GPIO.HIGH: + GPIO.output(LED1_pin, GPIO.LOW) GPIO.output(LED2_pin, GPIO.LOW) GPIO.cleanup() os.system('python3 /home/pi/code/Rasp_grid/rasp_grid.py') + sleep(5) + + + LED_status = GPIO_setup(LED1_pin, LED2_pin, Button1_pin, Button2_pin) + + LED_status[0] = True + GPIO.output(LED1_pin, GPIO.HIGH) + + LED_status[1] = True + GPIO.output(LED2_pin, GPIO.HIGH) + + # quit() + if GPIO.input(Button2_pin) == GPIO.HIGH: + for i in range(3): + for j in range(2): + sleep(0.5) + if j == 0: + GPIO.output(LED1_pin, GPIO.LOW) + GPIO.output(LED2_pin, GPIO.LOW) + else: + GPIO.output(LED1_pin, GPIO.HIGH) + GPIO.output(LED2_pin, GPIO.HIGH) + + GPIO.output(LED1_pin, GPIO.LOW) + GPIO.output(LED2_pin, GPIO.LOW) + print('shut down') quit() diff --git a/rasp_grid.py b/rasp_grid.py index 77b3a20..49f7ad6 100644 --- a/rasp_grid.py +++ b/rasp_grid.py @@ -18,7 +18,7 @@ from IPython import embed from uldaq import (get_daq_device_inventory, DaqDevice, AInScanFlag, ScanStatus, ScanOption, create_float_buffer, InterfaceType, AiInputMode) -def GPIO_setup(LED1_pin, LED2_pin, Button1_pin, Button2_pin): +def GPIO_setup(LED1_pin, LED2_pin, Button1_pin, Button2_pin, power_controll_pin): # LED output pins GPIO.setmode(GPIO.BOARD) @@ -31,7 +31,7 @@ def GPIO_setup(LED1_pin, LED2_pin, Button1_pin, Button2_pin): # switch controlled input # GPIO.setup(Button1_pin, GPIO.IN) - # GPIO.setup(Button2_pin, GPIO.IN) + GPIO.setup(power_controll_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) @@ -184,8 +184,9 @@ def main(): LED2_pin = 13 Button1_pin = 16 Button2_pin = 18 + power_controll_pin = 37 - LED_status = GPIO_setup(LED1_pin, LED2_pin, Button1_pin, Button2_pin) + LED_status = GPIO_setup(LED1_pin, LED2_pin, Button1_pin, Button2_pin, power_controll_pin) # DAQ setup if True: @@ -273,12 +274,15 @@ def main(): sleep(2) + emergency_LED_t = time() + emergency_LED_interval = 0.5 + LED_t = time() LED_t_interval = 2 temp_t0 = time() next_temp_t = 0 - temp_interval = 10 # sec --> 5 min + temp_interval = 300 # sec --> 5 min disp_eth_power = True @@ -290,20 +294,38 @@ def main(): if 't=' in line: temp = float((line.split('=')[-1].strip())) / 1000 temp_f.write('sec: %.0f; %.3f\n' % (next_temp_t, temp)) + temp_f.flush() break w1_f.close() next_temp_t += temp_interval # 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() + if GPIO.input(power_controll_pin) == GPIO.LOW: + 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() + else: + if time() - emergency_LED_t > emergency_LED_interval: + if LED_status[0] != LED_status[1]: + GPIO.output(LED1_pin, GPIO.HIGH) + GPIO.output(LED2_pin, GPIO.HIGH) + LED_status = [True, True] + else: + if LED_status[0] == True: + GPIO.output(LED1_pin, GPIO.LOW) + GPIO.output(LED2_pin, GPIO.LOW) + LED_status = [False, False] + else: + GPIO.output(LED1_pin, GPIO.HIGH) + GPIO.output(LED2_pin, GPIO.HIGH) + LED_status = [True, True] + # dist & eth0 controll if GPIO.input(Button2_pin) == GPIO.HIGH: @@ -331,6 +353,8 @@ def main(): if (last_idx > index) and (index != -1): np.array(data[last_idx:], dtype=np.float32).tofile(f) np.array(data[:index], dtype=np.float32).tofile(f) + f.flush() + if index == -1: pass else: