I am currently making a data logging system using raspberry pi and I am using a push button to start/stop data logging. I am able to execute the python script "3ldrdatalog.py" by os.system(), but I cannot find a specific command to stop the script on the second button press.
Kindly help me with the code ! Thanks in advance
import RPi.GPIO as GPIO
from Adafruit_CharLCD import Adafruit_CharLCD
GPIO.setmode(GPIO.BCM)
GPIO.setup(13,GPIO.IN)
input = GPIO.input(13)
import time
import os
lcd = Adafruit_CharLCD()
#initialise a previous input variable to 0 (assume button not pressed last)
prev_input = 1
try:
lcd.message('Press button')
while True:
#take a reading
input = GPIO.input(13)
#if the last reading was low and this one high, print
if ((not prev_input) and input):
print("Button pressed")
lcd.clear()
#this is the script that will be called (as root)
os.system("python /home/pi/3ldrdatalog.py")
#update previous input
prev_input = input
#slight pause to debounce
time.sleep(0.05)
except KeyboardInterrupt:
file.close()
pass
finally:
GPIO.cleanup()