Overview
Have you ever wished you could take pictures at night with the sweet Raspberry Pi High Quality (HQ) Camera?
Using the raspistill command line program is tricky because the auto setting determination usually results in a black picture.
Now, though, with a little Python, you can take pictures up to six seconds long at ISO 800! That'll turn a dark night lit only by a few house lights into a bright, well-saturated picture!
This image was taken at one in the morning with a Pi4 and HQ Camera with 6mm lens.
There are a wide range of options you can use to implement this. I wanted a compact, portable system to do astrophotography, so I built the system specifically to do that. If you want, you can just use the code with an HQ Camera setup you already have. It's totally up to you how sophisticated you want to be. (For example, I don't go into motorized star tracker equatorial mounts even though I'm doing astrophotography.) The mounting solution is up to you, again, depending on your use cases!
Page last edited March 08, 2024
Text editor powered by tinymce.
Assembly
Collect all the parts in one place, and it's time to start the build. (You'll notice some of the parts in the picture are already partially assembled.)
First, attach the included ribbon cable to the HQ Camera, or use one you have handy. Then attach the HQ Camera to the HQ Camera Mount Pro. You can put the lens on now, or wait a while, whichever you prefer. It doesn't get in the way. The official HQ Camera Mount Pro assembly instructions are available here (they're helpful for finding the right bolts to use).
Attach the camera ribbon cable to the Pi 4. Remember, the silver connectors face towards the HDMI ports on the Pi.
Attach the ICE Tower to the Raspberry Pi 4 following the enclosed instruction booklet. Leave off the lower base plate, though, since that's where we'll attach the camera mount.
Now take a break and use the Raspberry Pi Imager on a separate computer to burn the Raspberry Pi OS onto the flash drive. I recommend using the 32-bit release. The Pi 4 now supports booting from USB, so this will work with new Pi 4s. If you have an older Pi 4 without the updated firmware, you'll need to follow a procedure to update the firmware yourself (not documented here). Spoiler: it's a lot easier to use a new Pi 4.
Once the flash drive is ready, put it in one of the two USB-C ports on the Pi 4. Those are the ones with the blue spacers.
Now that the bits are in place, we can go back to assembling.
Connect three 20mm brass standoffs together so they are long enough for the Hack3r plate to clear the fan. Make two of these.
Things are coming together now! Press the tall Pi headers into one end of the Black Hat Hack3r ribbon cable. This provides the clearance to connect the Hack3r to the Pi.
Next, attach the Hyperpixel display to the Hack3r panel. It will protrude to the left in the above picture. Be very careful not to press down on the glass. Grasp the PCB at the sides and slowly wiggle it onto the pins. You can see the final position here.
Last assembly step! Use a red and a black wire to extend the fan power connections to the Hack3r plate header row that's still open.
That's it! Now you have a camera that, with the power bank and USB-C cable, is portable to the locations you want to shoot.
Page last edited March 08, 2024
Text editor powered by tinymce.
Software Configuration
Step one is to configure the operating system on the Pi. Connect the external monitor, and mouse and keyboard. Then apply power and configure as you normally would for a Raspberry Pi. The Pi should boot automatically from the flash drive.
Follow the on-screen instructions. When you have the install done, run Preferences->Raspberry Pi Configuration. I recommend changing the Pi's name. Then configure the interfaces. Be sure to enable SPI, I2C, and Camera.
When you click OK you should reboot the Pi.
Step two is to configure the Hyperpixel 4 display. Run this command as the user pi, not root (i.e., don't use sudo):
curl https://get.pimoroni.com/hyperpixel4 | bash
When it runs, it will ask for your display. Pick the correct one. If you are following this guide to the letter, you'll want the Pi 4 Square option.
When the script has finished running, it will ask if you want to reboot. Say yes.
Step three is to make the system usable. The display will be upside down when the Pi comes back up, which makes it a bit difficult to use. Fortunately, there is a command that will fix it. You'll only need this once:
hyperpixel4-rotate inverse
Now the display will be right side up and you can use it like any other Raspberry Pi.
Taking Pictures
Copy the following text to a file called lowlight.py. You can click the Download Project Bundle link to get a zip file containing the Python file:
# SPDX-FileCopyrightText: 2021 Anne Barela for Adafruit Industries
#
# SPDX-License-Identifier: MIT
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()
Run the program on your py to take a picture. It will save a jpg in the current directory with a timestamp.
$ ./lowlight.py
Adjust the shutter speed to get the exposure you want.
Page last edited March 08, 2024
Text editor powered by tinymce.
Python Code
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()
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()
Page last edited March 08, 2024
Text editor powered by tinymce.
Future Work
There are some things we could do to enhance the project.
- To enhance portability, we can configure the Raspberry Pi as a WiFi access point. This would create a local wireless network so you can control the system with an iPad with a VNC Client installed.
- Modify lowlight.py so you can specify the shutter speed and ISO with options.
- Build a small LED light and use it for light painting.
- Use velcro and piggyback it on a motorized telescope, then do astrophotography.
Use your imagination!
Page last edited March 08, 2024
Text editor powered by tinymce.