1

I'm very new to Python / Raspberry Pi and I'm trying to set up a time lapse camera.

Due to the number and size of images, I wish to save to USB.

At first the below program (copied and altered from the Raspberry Pi camera page) worked with a USB stick but the pictures were flipped horizontally. I searched and found the solution was to update my Raspberry Pi, which I did. It took several hours after which horizontally it was correct but vertically it had flipped (I added the rotation command because of this).

Now I get an error message (shown below). The program works fine when using the SD card (saving to home/pi/Pictures for example) but crashes with a USB. Once it's crashed with the USB, the program also ceases to work with the SD card.

Here's what I've tried: -

  • 3 separate USB sticks, ranging from 4GB up to 32GB (all are FAT32, by the way)
  • With and without the "camera.preview" command
  • With and without camera.close() command as I'd read answers to a similar problem saying that the camera might not be closing

Could anybody point me in the right direction but at the same time keeping it as simple as possible?

Many thanks.

Error message when running my program: -

Traceback (most recent call last):
File "/home/pi/Desktop/camera_USBv2.py", line 4, in <module>
   camera = PiCamera(resolution=(1024, 768), framerate=30)
File "/usr/lib/python3/dist-packages/picamera/camera.py", line 433, in __init__
   self._init_preview()
File "/usr/lib/python3/dist-packages/picamera/camera.py", line 513, in _init_preview
   self, self._camera.outputs[self.CAMERA_PREVIEW_PORT])
File "/usr/lib/python3/dist-packages/picamera/renderers.py", line 558, in __init__
   self.renderer.inputs[0].connect(source).enable()
File "/usr/lib/python3/dist-packages/picamera/mmalobj.py", line 2212, in enable
   prefix="Failed to enable connection")
File "/usr/lib/python3/dist-packages/picamera/exc.py", line 184, in mmal_check
   raise PiCameraMMALError(status, prefix)
picamera.exc.PiCameraMMALError: Failed to enable connection: Out of resources
>>> 

My program: -

from picamera import PiCamera
from time import sleep

camera = PiCamera(resolution=(1024, 768), framerate=30)
# Set ISO to the desired value
camera.iso = 100
# Turn image the right way up
camera.rotation = 180
sleep(2)


camera.start_preview()

for i in range(3):    
    sleep(5)
    camera.shutter_speed = camera.exposure_speed
    camera.exposure_mode = 'off'
    g = camera.awb_gains
    camera.awb_mode = 'off'
    camera.awb_gains = g
    camera.capture('/media/pi/114E-1713/image%04d.jpg' % i)

camera.stop_preview()
  • 1
    If it works with the SD card (ext4 filesystem), but not with a USB using FAT32, I'd have to guess it's in that "vicinity". Have you tried any experiments? Have you tried to get your program to write (for example) text files to the USB? Have you tried formatting your USB as ext4? There are many variables, and from where we sit, it's difficult to know where to start looking. – Seamus Aug 11 at 13:23
1

Thanks Seamus - after trying your suggestions successfully, I looked further.

I wasn't testing properly. Once the error occurs, one has to reboot before recreating the correct scenario. I wasn't doing that.

Basically, I tried the camera.close() script after the error had occurred but not before rebooting. Once I added camera.close as the final command, saved and rebooted all worked well.

In summary, without the camera.close() command, you can save as many times as you like to the same media but once you switch (as I was doing between SD and USB in my experiments) the above error occurs.

My program should have been: -

from picamera import PiCamera
from time import sleep

camera = PiCamera(resolution=(1024, 768), framerate=30)
# Set ISO to the desired value
camera.iso = 100
# Turn image the right way up
camera.rotation = 180
sleep(2)


camera.start_preview()

for i in range(3):    
    sleep(5)
    camera.shutter_speed = camera.exposure_speed
    camera.exposure_mode = 'off'
    g = camera.awb_gains
    camera.awb_mode = 'off'
    camera.awb_gains = g
    camera.capture('/media/pi/114E-1713/image%04d.jpg' % i)

camera.stop_preview()
camera.close()
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.