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.
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!
Time to work on a better source of power, possibly better camera, and a case.