User avatar
Ace Rimmer
Posts: 104
Joined: Wed May 27, 2015 1:51 am
Location: Wit's End

Picamera & Interrupts

Mon Aug 28, 2017 5:37 am

Hi, I hope someone can help me solve my problem. I am writing a small script which "interrupts" a video recording and then starts recording to a new file. The script works when I run it in the Python shell, however when I try to run it from the command line it fails in one of two ways -

if run using Python2 when the interrupt occurs it terminates and returns an error -

Code: Select all

sys.excepthook is missing

lost sysstderr 
if run using Python3 when the interrupt occurs the script terminates and doesn't record the second file.

Code: Select all

 #!/usr/bin/env python3.4.2
print ('   INITIALISING >>>>>>')
import io
import picamera
import datetime as dt
from time import *

import RPi.GPIO as GPIO


GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_UP)

def my_callback(channel):
     print ('apogee detected')#+dt.datetime.now().strftime('  %H:%M:%S ')
     apogeedetected()

def apogeedetected():
     with picamera.PiCamera() as camera:
             camera.start_preview()
             fylnaymeB=('B.h264')
             start = dt.datetime.now()
             strrt = time()
             
             camera.start_recording(fylnaymeB)
             while (dt.datetime.now() - start).seconds < 10:#   
                  camera.annotate_text = dt.datetime.now().strftime('  PART B  %d-%m-%y    %H:%M:%S       Recording          ')+ str( round(time()-strrt,0))+(' SECONDS      ' )
             camera.wait_recording()
             camera.stop_recording()


print ( 'initialising complete......')


GPIO.add_event_detect(17, GPIO.FALLING, callback=my_callback, bouncetime=300)
## PART A ##

with picamera.PiCamera() as camera:
    
    camera.start_preview()
    fylnaymeA=('A.h264')
    start = dt.datetime.now()
    strrt = time()
    camera.annotate_background =picamera.Color('green')
    camera.start_recording(fylnaymeA)
    while GPIO.input(17):
         camera.annotate_text = dt.datetime.now().strftime('  PART AAA   %d-%m-%y    %H:%M:%S    Recording ')+ str(20- round(time()-strrt,0))+(' SECONDS       ' )
         camera.wait_recording
         #camera.stop_preview()
    


GPIO.cleanup()           # clean up GPIO on normal exit


Why does it work from the Python shell but not the command line ? :? Any suggestions?
There must be an easier way!!!!!
I hope there is.....I haven't found it yet.

Return to “Camera board”