Point and Shoot Raspberry Pi Digital Camera
Previously we covered GPIO with motors and servos, what about buttons?
The classic example is to light up an LED on a button press, but we can do better than that!
I am using the TFT Hat from Adafruit, but the same principle applies whichever buttons you use, just match the correct pin number.
import os
import picamera
import gpiozero
from gpiozero import Button
import time
import datetime
from time import sleep
camera = picamera.PiCamera()
button = Button(23)
def snap():
print("Snap!")
datestamp = datetime.datetime.now().strftime('./camera/%Y-%m-%d-%H-%M.jpg')
camera.capture(datestamp)
os.system("sudo fbi -T 2 -d /dev/fb1 -noverbose -a {}".format(datestamp))
while True:
if button.is_pressed:
snap()
# do nothing
sleep(0.1)
We start with the usual import section. We need to execute commands, do some time stuff, and take pictures. For the button we will use GPIOZero.
The official camera has a nice PiCamera module, and GPIOZero has a friendly Button object that makes this project crazy easy.
Our Snap function works out the text version of the date and time, starting with year, and on down to minute. I just slapped my forehead when I spotted that I should have not been so silly, overwriting my images , but for demo purposes, you get the idea.
If you were going to use this for real you would need to add seconds or more granularity :)
Once we take the picture using camera.capture
we then execute FBI on the command line. No, we are not calling the cops, but using the frame buffer tool to output the just taken picture to the small TFT screen.
We have a small infinite loop to check the button is_pressed
property, but we could have easily used the more event-based approach of supplying our function as the method for the when_pressed
feature instead.
Our tiny delay is just to stop the Pi from trying to do too much too fast, have a play with how fast you can run it before problems arise!
It would be really cool to build a dashcam with a Rasberry PI.
Nice article btw
I am planning on doing that because my GoPro overheats and will only run for so long even plugged into power. With a pi zero it would not take much space, and it can use dropbox or rsync for when on wifi to upload the images
Awesome idea. Looking forward to that post. We have some really bad taxi drivers in my country think I can get some cool footage if I have a dash cam :)
Can I use Raspberry Pi Zero??
Yep, should work fine :)
Sure is convienent that the Frame Buffer Interface happens to have those letters. You even suggested improvements for the Name Sequencing Algorythm. :P
Nice little basic write-up. You should consider doing something with more generic cameras, or LCD's.
This one uses a USB camera https://steemit.com/programming/@makerhacks/very-simple-pi-webcam
I still have to get a Ras Pi. I've always loved seeing all the DIY projects one can do with these. Top of my list is a Pi-Hole. Although I do enjoy the DIY Google Home speaker (that doesn't spy on you) built with a Ras Pi!
Great project camera.
Camera connect to raspi
I think it's pretty cool that you are programming your camera, the fact that you have that skill. That's a pretty rare talent. You've opened my eyes to the many possibilities out there. To see the process that goes into the camera is very fascinating. You know we are just used to pressing the button and taking a picture, without caring for what's happening in the background, but after seeing this post I now think differently about cameras. Very interesting.
This post which has a payout in excess of $50.00 has utlized one or more bidbots.
minnowbooster payout in the amount of $26.15 USD.
earthnation-bot payout in the amount of $0.29 USD.
This information is being presented in the interest of transparency on our platform.
Please consider the long term effect on our platform before using bidbots!
You can read more about how bidbots are affecting our platform here.
This comment is by no means a judgement of your work @makerhacks, only an earnest appeal, that we might all work together to build a great platform by letting the community curate our work and not bidbots.
Please consider supporting @transparencyBot by upvoting this comment.
You have a typo in your bio - Network is spelled incorrectly
What is
earthnation-bot
? Never heard of that, but I did use Minnow Booster :)