Open up your favorite editor and save the following code as lowlight.py

First we import the libraries we need. You don't need to install anything special since these libraries are included with Raspberry Pi OS.

from picamera import PiCamera
import time
from fractions import Fraction
import datetime

Create the timestamp string used to build the output file name.

cur_time = datetime.datetime.now()
stub = cur_time.strftime("%Y%m%d%H%M_low")

Next, create an instance of the Camera object. This is where the magic is, since it allows us to change the default frame rate to 1/6 of a second.

camera = PiCamera(framerate=Fraction(1,6))

Now we can set the shutter speed and ISO in the Camera object instance. The shutter speed is in milliseconds, so for a six second exposure you would use 6000000.

# You can change these as needed. Six seconds (6000000)
# is the max for shutter speed and 800 is the max for ISO.
camera.shutter_speed = 1750000
camera.iso = 800

Next, we let the camera collect available light to auto-detect other camera settings. We also turn off the exposure mode so the auto-detection won't change our shutter speed and frame rate.

time.sleep(30)
camera.exposure_mode = 'off'

Now we set the output file name and take a picture!

outfile = "%s.jpg" % (stub)
camera.capture(outfile)

The last step is to close the Camera object so the operating system properly releases the camera controls.

camera.close()

Full Example Code

from picamera import PiCamera
import time
from fractions import Fraction
import datetime

cur_time = datetime.datetime.now()
stub = cur_time.strftime("%Y%m%d%H%M_low")

camera = PiCamera(framerate=Fraction(1,6))

# You can change these as needed. Six seconds (6000000)
# is the max for shutter speed and 800 is the max for ISO.
camera.shutter_speed = 1750000
camera.iso = 800

time.sleep(30)
camera.exposure_mode = 'off'

outfile = "%s.jpg" % (stub)
camera.capture(outfile)

camera.close()

This guide was first published on May 18, 2021. It was last updated on May 18, 2021.

This page (Python Code) was last updated on May 17, 2021.

Text editor powered by tinymce.