覆盆子pi python冻结

时间:2015-04-03 00:17:08

标签: python python-3.x raspberry-pi

在我的覆盆子pi上,我正在运行一个时间推移相机,而不是它保存到USB闪存驱动器,它已经工作正常,直到几天前。当我启动它时,它将运行,打印出所拍摄的照片数量,然后重复,这是正常的,但现在它会这样做,然后停止。过了一会儿,它会冻结并停止一切。我无法通过远程桌面连接等连接到它,但奇怪的是我仍然可以访问它托管的网站。这是代码:

#!/usr/bin/env python


import time
import picamera
import RPi.GPIO as GPIO
from subprocess import call
from datetime import datetime
import math


green = 16 #Running 
red = 20 #wating for sunset
startProgram = 21 #button to start every thing


GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.IN, GPIO.PUD_UP) #push button
GPIO.setup(green, GPIO.OUT)
GPIO.setup(red, GPIO.OUT)


d = datetime.now()
initYear = "%04d" % (d.year) 
initMonth = "%02d" % (d.month) 
initDate = "%02d" % (d.day)
initSec = "%02s" % (d.second)

GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.IN, GPIO.PUD_UP) #push button
GPIO.setup(green, GPIO.OUT)
GPIO.setup(red, GPIO.OUT)

folderToSave = "timelapse_" + str(initYear) + "_" + str(initMonth) + "_" +  str(initDate) + "_" + str(initSec) + "/"
folderToSave2 = "timelapse_" + str(initYear) + "_" + str(initMonth) + "_" +  str(initDate) + "_" + str(initSec) + "/"
os.mkdir(folderToSave)


var = 1
while var == 1 :  # This constructs an infinite loop
    with picamera.PiCamera() as camera:
        i =datetime.now()                   #what time is it
        now = i.strftime('%Y%m%d-%H%M%S')   #how to format the time
        photo_name = now + '.jpg'           #what the photo will be called
        camera.resolution = (1920, 1080)
        camera.led = 0

        GPIO.output(red, GPIO.LOW)
        GPIO.output(green, GPIO.HIGH)
        camera.capture(folderToSave + photo_name) #takes the photo to the lochal disk
        camera.capture(folderToSave2 + photo_name) #takes the photo to the lochal disk
        GPIO.output(green, GPIO.LOW)
        GPIO.output(red, GPIO.HIGH)


        time.sleep(10)

感谢您的帮助

这里还有一个相机曝光器,可以工作约3秒钟,然后冻结同样的问题

#!/usr/bin/python
#+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#|R|a|s|p|b|e|r|r|y|P|i|-|S|p|y|.|c|o|.|u|k|
#+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#
# pi_camera_options.py
# Takes a sequence of photos with the Pi camera
# using a range of Exposure and White Balance
# settings.
#
# Project URL :
# http://www.raspberrypi-spy.co.uk/?p=1862
#
# Author : Matt Hawkins
# Date   : 21/06/2013
import os
import time
import subprocess

# Full list of Exposure and White Balance options
list_ex  = ['off','auto','night','nightpreview','backlight',
            'spotlight','sports','snow','beach','verylong',
            'fixedfps','antishake','fireworks']
list_awb = ['off','auto','sun','cloud','shade','tungsten',
            'fluorescent','incandescent','flash','horizon']

# Refined list of Exposure and White Balance options. 60 photos.
#list_ex  = ['off','auto','night','backlight','spotlight','fireworks']
#list_awb = ['off','auto','sun','cloud','shade','tungsten','fluorescent','incandescent','flash','horizon']

# Test list of Exposure and White Balance options. 6 photos.
#list_ex  = ['off','auto']
#list_awb = ['off','auto','sun']

# EV level
photo_ev = 0

# Photo dimensions and rotation
photo_width  = 640
photo_height = 480
photo_rotate = 0

photo_interval = 0.25 # Interval between photos (seconds)
photo_counter  = 0    # Photo counter

total_photos = len(list_ex) * len(list_awb)

# Delete all previous image files
try:
  os.remove("photo_*.jpg")
except OSError:
  pass

# Lets start taking photos!
try:

  print "Starting photo sequence"

  for ex in list_ex:
    for awb in list_awb:
      photo_counter = photo_counter + 1
      filename = 'photo_' + ex + '_' + awb + '.jpg'
      cmd = 'raspistill -o ' + filename + ' -t 1000 -ex ' + ex + ' -awb ' + awb + ' -ev ' + str(photo_ev) + ' -w ' + str(photo_width) + ' -h ' + str(photo_height) + ' -rot ' + str(photo_rotate)
      pid = subprocess.call(cmd, shell=True)
      print ' [' + str(photo_counter) + ' of ' + str(total_photos) + '] ' + filename    
      time.sleep(photo_interval)

  print "Finished photo sequence"

except KeyboardInterrupt:
  # User quit
  print "\nGoodbye!"

ps使用Raspberry Pi 1 b +

0 个答案:

没有答案
相关问题