Digital cameras are fun. They're smaller than a DSLR, and while not usually offering that great cameras, they're significantly cheaper and have good image quality compared to majority mainstream smartphones.
What if you didn't want to buy one, but you just happened to have a small PiTFT, a camera module, and a Raspberry Pi?
You can consider making a Digital Camera. Especially if there just happens to be a Photography Project14
Currently, my prototype does not have charging, power, or anything else. The screen is touchscreen but for controls you will use the 4 buttons connected via the PiTFT.
Here is a quick, (and ugly) demo.
BOM:
Raspberry Pi, Any Model with 2x20 pin header(preferably with WiFi, if Pi 0, camera adapter required)
Raspberry Pi Camera, any model(Preferably HQ camera, using 8mp)
Adafruit PiTFT 2.8" - No touch, Resistive, or Capacitive(using resistive)
SD Card, Power, CSI 15 pin cable
Useful knowledge for the project:
Basic Linux terminal commands
Basic Python Experience
First, we will make a Python script that will be run to make a simple button-based controller for the Camera. The PiTFT has 4 tactile switches, wired to GPIO 17, 22, 23, and 27.
This is the Python Script I wrote. It is simple and has only basic functions, and that is for camera preview, 2800x2100 still images(interestingly enough, the software wouldn't allow full resolution images at the full 8MP), and 1280x720@15fps.
from gpiozero import Button from picamera import PiCamera from time import sleep from time import strftime import datetime camera = PiCamera() camera.framerate = 15 softwareOn = Button(17) softwareOff = Button(22) takeImage = Button(23) takeVideo = Button(27) software = False video = False def capture_photo(file_capture): print("\r\nImage Capturing\r\n") sleep(2) camera.capture(file_capture) print("\r\nImage Captured! \r\n") while True: if softwareOn.is_pressed: software = True camera.start_preview() if softwareOff.is_pressed: software = False camera.stop_preview() if takeImage.is_pressed: camera.resolution = (2800, 2100) date = datetime.datetime.now().strftime('%m-%d-%Y_%H.%M.%S') capture_img = '/home/pi/Photos/' + date + '.jpg' capture_photo(capture_img) if takeVideo.is_pressed: camera.resolution = (1280, 720) if video == False: video = True print("video recording") date = datetime.datetime.now().strftime('%m-%d-%Y_%H.%M.%S') camera.start_recording('/home/pi/Photos/' + date + '.h264') while video == True: sleep(0.25) if takeVideo.is_pressed: video = False print("Video Recorded") camera.stop_recording() sleep(3)
I have tried to format this to the best of my ability. However, the built-in syntax highlighting feature is quite buggy and slow to use. If you are copy-pasting the code, you may need to format the indents and stuff yourself.
A quick explanation of the code:
We first import our necessary libraries. gpiozero Button is our library for interfacing with the GPIO buttons(in this case, 17, 22, 23, and 27). We have PiCamera, for camera interface, time, for delays, strftime and datetime to determine the time you are taking the photo/video. By default, preview and video recording is off. There is a while loop(While True, so it runs infinitely), which tries to detect your button presses. If you press GPIO 17, the software will begin to start preview and show a fullscreen real-time view of your camera feed. When 22 is pressed, this is turned off. When 23 is pressed it sets resolution to 2800x2100(PiCamera defaults to your screen size, so we don't want a 320x240 image, do we?)
Lastly, there when GPIO 27 is pressed it will set video recording to True. This will set resolution to 1280x720, and start recording. The minimum record time is 1/4 second, but this is mainly to work out any longer presses. In addition, when you press the button again, it will stop recording and sleep for 3 seconds(so you do not accidentally trigger another recording).
Lastly, datetime and strftime will check the exact time on-demand to add to the end of your file names. No more pesky IMG_4280582085280450240 filenames.
We will probably want the program to run upon boot.
One such way is rc.local.
First, we save the file(I saved as camera.py in ~/Home/Pi/)
Open up a terminal, type in
sudo nano /etc/rc.local
Now, we type in, just before "exit 0",
sudo python /home/pi/camera.py
Of course, this is assuming if you are using Python and your path to your file is /home/pi/camera.py. It may be different for you.
Now, we restart, and the program is working perfectly on boot!
Thanks to Tariq for sending me a Raspberry Pi 4, a HQ Camera and a 16mm lens!
Initially, I was able to software render 320x240 video at 30FPS. While this was a low resolution, it was quite smooth. However, this lead to increased power draw and the CPU temperatures increased to 75 degrees C, as I was unable to implement active cooling. Due to this, the camera's preview will likely be set to 10FPS for lower power consumption and heat.
I am currently designing a flexible case design that can incorporate either a Raspberry Pi 4, or a Raspberry Pi 0. I will hopefully be making two versions of the camera: one that has a built in battery, powered with a Raspberry Pi Z, and passive cooling. It will have a render of 10fps for the preview, and will take 1080P still images, and record 720 video at 15FPS. I have already ordered a raspberry Pi 0 for this purpose.
The second design will use a Raspberry Pi 4, 8GB. There will be active cooling, as the Pi 4 generally emits greater heat, and external power, as it has a massive energy draw. 30FPS, or possibly even higher, will be attempted thanks to the lack of restraint on power and heat. I will also attempt to run OpenVino along with an Intel Neural Compute Stick 2 to run some basic machine learning on the camera.
One issue I have faced with the 8MP camera(on my POC) and my experiments with the HQ camera, was that I was unable to take still images at or even close to the maximum resolution of the camera modules. After some investigation, I realized that the GPU of the Raspberry Pi shared the RAM with the CPU. However, that set RAM rate must be increased to increase the still resolution.
By default on my Raspberry Pi, the memory was set to 128MB. The maximum for the Pi 4 is 256MB shared RAM. After bumping it up to 256MB(thanks to 8GB ram on the Pi, 256MB is no big deal.) After this, the Raspberry Pi worked perfectly and was able to capture images at the HQ camera's maximum resolution(somewhere around 4000x3000.) However, while 256MB may be insignificant for a Raspberry Pi 4B, this is certainly an issue for a Raspberry Pi 0. Both the Raspberry Pi 3A+ and 0 were considered, and the 0 was more economic and had the least energy draw. One tradeoff for it's small size and cost was the RAM. The Raspberry Pi 0 only has an integrated 512MB of RAM. Due to this, it will be likely only possible to take images at a maximum of 2K. This is assuming you set 128MB as the GPU memory allocation. It is possible to run with Swap memory but that will decrease performance, possibly.
Top Comments