adapted LED flashing in all script. Recording is possible in infinity loop when executing grid main.py

This commit is contained in:
tillraab 2019-09-18 15:56:56 +02:00
parent f91e2b780d
commit bb0f00d1a9
3 changed files with 107 additions and 68 deletions

View File

@ -50,7 +50,6 @@ class plot():
gs.update(left=0.05, bottom=0.05, top=1, right=1, hspace=0, wspace=0) 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): def GPIO_setup(LED1_pin, LED2_pin, Button1_pin, Button2_pin):
# LED output pins # LED output pins
GPIO.setmode(GPIO.BOARD) GPIO.setmode(GPIO.BOARD)
@ -197,34 +196,19 @@ def main():
print('cfg file missing !!!') print('cfg file missing !!!')
quit() 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 # read and edit config file
channels, rate, n_cols, n_rows, max_v = read_cfg(init_cfgfile, now) 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 LED1_pin = 11
LED2_pin = 13 LED2_pin = 13
Button1_pin = 16 Button1_pin = 16
Button2_pin = 18 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 # DAQ setup
if True: if True:
# channels = 16
status = ScanStatus.IDLE status = ScanStatus.IDLE
@ -235,7 +219,7 @@ def main():
low_channel = 0 low_channel = 0
high_channel = channels high_channel = channels
samples_per_channel = 20000 # * channels = Buffer size samples_per_channel = rate * 2 # * channels = Buffer size
# rate = 20000 # rate = 20000
scan_options = ScanOption.CONTINUOUS scan_options = ScanOption.CONTINUOUS
flags = AInScanFlag.DEFAULT flags = AInScanFlag.DEFAULT
@ -298,13 +282,14 @@ def main():
# f = open('/media/pi/data1/test_file.raw', 'wb') # f = open('/media/pi/data1/test_file.raw', 'wb')
# LED on when here ... wait for switch to start data aquisition # LED on when here ... wait for switch to start data aquisition
GPIO.output(LED1_pin, GPIO.HIGH)
LED_status[0] = True # GPIO.output(LED1_pin, GPIO.HIGH)
while GPIO.input(Button1_pin) == GPIO.LOW: # LED_status[0] = True
sleep(.1) # while GPIO.input(Button1_pin) == GPIO.LOW:
sleep(2) # sleep(.1)
GPIO.output(LED1_pin, GPIO.LOW) # sleep(2)
LED_status[0] = False # GPIO.output(LED1_pin, GPIO.LOW)
# LED_status[0] = False
LED_t = time() LED_t = time()
LED_t_interval = 2 LED_t_interval = 2
@ -319,36 +304,35 @@ def main():
Plot.create_axis() Plot.create_axis()
init_fig = True init_fig = True
try: try:
while GPIO.input(Button1_pin) == GPIO.LOW: while True:
# blinking LED # blinking LED
if time() - LED_t < .1 and LED_status[0] == False: # if time() - LED_t < .1 and LED_status[0] == False:
LED_status[0] = True # LED_status[0] = True
GPIO.output(LED1_pin, GPIO.HIGH) # GPIO.output(LED1_pin, GPIO.HIGH)
if time() - LED_t >= .1 and LED_status[0] == True: # if time() - LED_t >= .1 and LED_status[0] == True:
LED_status[0] = False # LED_status[0] = False
GPIO.output(LED1_pin, GPIO.LOW) # GPIO.output(LED1_pin, GPIO.LOW)
if time() - LED_t >= LED_t_interval: # if time() - LED_t >= LED_t_interval:
LED_t = time() # LED_t = time()
#
# dist & eth0 controll # # dist & eth0 controll
if GPIO.input(Button2_pin) == GPIO.HIGH: # if GPIO.input(Button2_pin) == GPIO.HIGH:
if disp_eth_power == True: # if disp_eth_power == True:
subprocess.run(['tvservice', '-o']) # subprocess.run(['tvservice', '-o'])
subprocess.run(['vcgencmd', 'display_power', '0']) # subprocess.run(['vcgencmd', 'display_power', '0'])
#
subprocess.run(['sudo', 'ip', 'link', 'set', 'eth0', 'down']) # subprocess.run(['sudo', 'ip', 'link', 'set', 'eth0', 'down'])
disp_eth_power = False # disp_eth_power = False
else: # else:
if disp_eth_power == False: # if disp_eth_power == False:
subprocess.run(['tvservice', '-p']) # subprocess.run(['tvservice', '-p'])
subprocess.run(['vcgencmd', 'display_power', '1']) # subprocess.run(['vcgencmd', 'display_power', '1'])
subprocess.run(['sudo', '/bin/chvt', '6']) # subprocess.run(['sudo', '/bin/chvt', '6'])
subprocess.run(['sudo', '/bin/chvt', '7']) # subprocess.run(['sudo', '/bin/chvt', '7'])
#
subprocess.run(['sudo', 'ip', 'link', 'set', 'eth0', 'up']) # subprocess.run(['sudo', 'ip', 'link', 'set', 'eth0', 'up'])
disp_eth_power = True # disp_eth_power = True
# Get the status of the background operation # Get the status of the background operation
status, transfer_status = ai_device.get_scan_status() status, transfer_status = ai_device.get_scan_status()
@ -387,7 +371,7 @@ def main():
last_idx = index last_idx = index
except KeyboardInterrupt: except KeyboardInterrupt:
embed() plt.close()
pass pass
# f.close() # f.close()
@ -406,7 +390,7 @@ def main():
subprocess.run(['sudo', '/bin/chvt', '7']) subprocess.run(['sudo', '/bin/chvt', '7'])
# subprocess.run(['sudo', 'ip', 'link', 'set', 'eth0', 'up']) # subprocess.run(['sudo', 'ip', 'link', 'set', 'eth0', 'up'])
GPIO.cleanup() # GPIO.cleanup()
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -1,4 +1,5 @@
import os import os
from time import sleep
try: try:
import RPi.GPIO as GPIO import RPi.GPIO as GPIO
except: except:
@ -32,15 +33,45 @@ def main():
LED_status = GPIO_setup(LED1_pin, LED2_pin, Button1_pin, Button2_pin) 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 LED_status[1] = True
GPIO.output(LED2_pin, GPIO.HIGH) GPIO.output(LED2_pin, GPIO.HIGH)
while True: 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.output(LED2_pin, GPIO.LOW)
GPIO.cleanup() GPIO.cleanup()
os.system('python3 /home/pi/code/Rasp_grid/rasp_grid.py') 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() quit()

View File

@ -18,7 +18,7 @@ from IPython import embed
from uldaq import (get_daq_device_inventory, DaqDevice, AInScanFlag, ScanStatus, from uldaq import (get_daq_device_inventory, DaqDevice, AInScanFlag, ScanStatus,
ScanOption, create_float_buffer, InterfaceType, AiInputMode) 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 # LED output pins
GPIO.setmode(GPIO.BOARD) GPIO.setmode(GPIO.BOARD)
@ -31,7 +31,7 @@ def GPIO_setup(LED1_pin, LED2_pin, Button1_pin, Button2_pin):
# switch controlled input # switch controlled input
# GPIO.setup(Button1_pin, GPIO.IN) # 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(Button1_pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(Button2_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 LED2_pin = 13
Button1_pin = 16 Button1_pin = 16
Button2_pin = 18 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 # DAQ setup
if True: if True:
@ -273,12 +274,15 @@ def main():
sleep(2) sleep(2)
emergency_LED_t = time()
emergency_LED_interval = 0.5
LED_t = time() LED_t = time()
LED_t_interval = 2 LED_t_interval = 2
temp_t0 = time() temp_t0 = time()
next_temp_t = 0 next_temp_t = 0
temp_interval = 10 # sec --> 5 min temp_interval = 300 # sec --> 5 min
disp_eth_power = True disp_eth_power = True
@ -290,20 +294,38 @@ def main():
if 't=' in line: if 't=' in line:
temp = float((line.split('=')[-1].strip())) / 1000 temp = float((line.split('=')[-1].strip())) / 1000
temp_f.write('sec: %.0f; %.3f\n' % (next_temp_t, temp)) temp_f.write('sec: %.0f; %.3f\n' % (next_temp_t, temp))
temp_f.flush()
break break
w1_f.close() w1_f.close()
next_temp_t += temp_interval next_temp_t += temp_interval
# blinking LED # blinking LED
if time() - LED_t < .1 and LED_status[0] == False: if GPIO.input(power_controll_pin) == GPIO.LOW:
LED_status[0] = True if time() - LED_t < .1 and LED_status[0] == False:
GPIO.output(LED1_pin, GPIO.HIGH) LED_status[0] = True
if time() - LED_t >= .1 and LED_status[0] == True: GPIO.output(LED1_pin, GPIO.HIGH)
LED_status[0] = False if time() - LED_t >= .1 and LED_status[0] == True:
GPIO.output(LED1_pin, GPIO.LOW) LED_status[0] = False
if time() - LED_t >= LED_t_interval: GPIO.output(LED1_pin, GPIO.LOW)
LED_t = time() 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 # dist & eth0 controll
if GPIO.input(Button2_pin) == GPIO.HIGH: if GPIO.input(Button2_pin) == GPIO.HIGH:
@ -331,6 +353,8 @@ def main():
if (last_idx > index) and (index != -1): if (last_idx > index) and (index != -1):
np.array(data[last_idx:], dtype=np.float32).tofile(f) np.array(data[last_idx:], dtype=np.float32).tofile(f)
np.array(data[:index], dtype=np.float32).tofile(f) np.array(data[:index], dtype=np.float32).tofile(f)
f.flush()
if index == -1: if index == -1:
pass pass
else: else: