Introduction: Raspberry Pi Camera

Here is a very basic raspberry pi camera setup that you can use as you wish. While it my be less sophisticated as some other rpi camera projects I hope to slowly improve my designs. If you go ahead and make this I'd love to hear about it as well as any other rpi camera projects you may have done.

Step 1: Materials

You will need:
-Raspberry Pi
-a rechargeable power bank
-a computer mouse
-a usb webcam

-instead of using a sub webcam you could use the rpi camera module though this will require some changes in the python code

Step 2: The Code

--here is the python code--


#program will be the code to make a camera take a picture when a mouse butten is pressed

import time
import pygame
import pygame.camera
import random
keeper = 0
pygame.init()
import sys
(width,height) = (1100,700)#how will this fair without a monotor pluged in?
play = True
something = 0
nothing = 0
i = 0
counter = 1
while (play == True) and (i < 30):#do I really need the play variable
key = pygame.mouse.get_pressed()#does need to happen inside loop
screen = pygame.display.set_mode((width,height))#makes the pygame window
if key[0]==True:#zero is the left butten on the mouse
print "Something"
keeper = (random.randint(0,100))
keeper = str(keeper)
something = something +1
i = i +1
pygame.camera.init()
cam = pygame.camera.Camera("/dev/video0",(640,480))
cam.start()
img = cam.get_image()
pygame.image.save(img,'/home/pi/Desktop/camPics/'+str(counter)+"pic"+keeper+'.jpg')#you may wish to change where the photo is saved
cam.stop()
counter = counter +1
elif (key[1]==True) or (key[2]==True):
play = False
else:
print "Nothing"
nothing = nothing +1
#i = i +1#just thought of something: could use i to ensure user never takes over a certian amount of pictures
print something, "!!!!!!!!!!!!"

pygame.display.quit()#closes pygame window

Step 3: Running on Boot

So your going to want your program to run as soon as the camera is turned on. This can be quiet annoying and you may want to ensure you've backed up important files on your rpi (seriously though who keeps important files on a raspberry Pi?)

Your going to add a line of code to /etc/roc.local

Follow these steps:
1. Open the terminal
2. Type sudo nano /etc/rc.local and press enter
3.just above the line exit 0 add

python /home/Pi/Desktop/CameraCode.py &

Note: CameraCode.py is the name of my program

4.save your work.

Step 4: Use

Press the left mouse button to take a picture and the right mouse button to end the program. After turning on the camera it may take a while for the program to start running. Take your pictures but please read the next step as it explanes how to retrieve them.

Step 5: Getting Back on the Pi

Now to get back into the desktop to view your pictures your going to have to unplug the usb camera and turn on the raspberry Pi. You'll see a black screen with a mouse. Move the mouse around a bit and press the left button. You should now see the desktop environment. Open your folder and view your pictures.

Step 6: Next Steps

Things I want to change:
1.I'd like to do this with my Pi 3 so I can save the photos to a usb stick and view them on my computer quicker
2. Replace the webcam with the raspberry Pi camera module
3. Try using the night vision raspberry Pi camera module
4. Get a touch screen working so I can view my photos and eliminate the need for a mouse
5. Add a physical button through the gpio pins instead of using a mouse
6. All round slim the thing down
7. Have the photos saved to google photos over wifi automatically