As I work from home, overlooking the garden, I decided to build myself a bird table to have something interesting to look at whilst working out whatever network problem has fallen into my lap that day.
|Click for Larger Version|
Next it was time to take some pictures of the visitors I had, this turned out to be very difficult with only a 250mm zoom lens. As soon as you moved the little blighters flew off! plus I had work to do, couldn't do both at the same time.
Having made a DIY shutter release for my Canon1000D camera the obvious next step was to build a remote release and the device most suited to this task was of course my RaspberryPi.....
This post will not cover setting up and updating your RPi, there are plenty of those already, suffice to say, keep your system updated.
There is also a myriad of websites detailing the physical differences between camera shutter release connections, please check your own camera/connectors. Although each one will have at least 3 pins to connect to, these are usually pre-focus, shutter & ground. You'll need to know which is which.
So, let's get to it.....
Step1 : The Circuit
|Click for Larger Version|
The circuit comprises of two transistors which replace the physical buttons used on a standard handheld shutter release, a transistor is a switch after all - just one controlled by electricity instead.
The transistors I used were "2N3440", I decided quite arbitrarily on these (Lots of Googling shows these are quite 'beefy' so not much chance of any power from the camera getting to my RPi) - I'm not an electronics person either, although I do have a soldering iron !
The basic logic is that each transistor has 3 'legs' Base, Collector & Emitter, they usually have a flat edge or a bumb to show it's orientation - again, google it.
We apply current to the 'Base' from the RPi GPIO pin (via software which we'll get to later), which throws the transistor 'switch', the 'Emitter' is ground and the 'Collector' is connected to the respective pin in the 2.5mm jack.
You can see all of the 'grounds' are connected together.
The pictures below show the finished board, and with it connected to the RPi. The 3 grey connector wires, with respect to the diagram above, from top to bottom, GPIO Pin#6(Green), #16(Red) & #18(Yellow)
|Click for Larger Version||Click for Larger Version|
That covers the hardware side of things, next is the software..
The software side of this project is surprisingly simple.
I used a Youtube video to understand how the GPIO is used and what software you need to install in order to write your own routines.
I'm not going to re-invent the wheel here so I suggest you watch it too : GPIO For Beginners
OK, so now you have the software installed and understand a bit more about GPIO.
To fire the camera shutter all we need to do is set the correct pin to 'high' for a specified amount of time and then bring it back down to 'low'
Below is the short script that I used, actually fires the camera for 4 seconds - you can of course change this to whatever you want. I have setup pin 23 as well (shutter half press), although I'm not using it in this script at the moment.
The code (shutter.py):
import RPi.GPIO as GPIO
Make it executable :
sudo chmod +X shutter.py
To actually run the code :
sudo python shutter.py
So you can see that by setting the pin number to 'True' we are in fact delivering current from the RPi GPIO pin to the 'Base' of the transistor which then fires the camera, then switch it off by setting the pin to 'False'.
This short video shows the whole setup working, this was my first YouTube video and the quality isn't great but it gives you the idea : RPi GPIO Controlled Canon DSLR
Next step is make the whole setup battery powered!!
Again, I'm not going to re-invent the wheel here, this site is where I got all the information needed :
RPi Running From Batteries
The only changes I made were getting a 10xAA Battery box and connecting a salvaged micro USB instead of using the GPIO header to connect the power. So far I have had my setup running for about 5 hours on 10xAAs. In the end you then get :
|Click for Larger Version|
We now have an isolated platform (associated with my wireless network) which can be placed in the field.
Set up the tripod, camera etc approx 8-10 feet from the bird table, connect the 2.5mm jack to the remote shutter release port of the camera, SSH to RPi from the comfort of the conservatory and wait.....sometimes for a while.....until something lands on the table. When it is roughly in the area you have setup the camera for then run the script that fires the shutter, and repeat until your satisfied you have enough material to work through. When your finished you can get some good pictures.
Selection of pictures taken with this setup can be found here : Recent Blackbird Pictures
Next we want to fire the camera only when motion has been detected, so we don't have to sit there waiting, ie: automate the process.
Software we need for motion detection is called 'Motion', so first of all we need to install it, which is as simple as :
sudo apt-get install motion
Motion has its' own configuration file, 'motion.conf', we need to edit that to make a few changes, so....
sudo nano /etc/motion/motion.conf
Motion.conf is a long file, lines starting with a "#" are comment lines and are ignored. Listed next are the parameters I changed :
# Image width (pixels). Valid range: Camera dependent, default: 352
# Image height (pixels). Valid range: Camera dependent, default: 288
# Maximum number of frames to be captured per second.
# Valid range: 2-100. Default: 100 (almost no limit).
# Image File Output
# Live Webcam Server
# Restrict webcam connections to localhost only (default: on)
# Command to be executed when an event starts. (default: none)
# An event starts at first motion detected after a period of no motion defined
on_event_start sudo python shutter.py
So when we start 'motion' you can use your favorite browser to go to your RPi's IP address and port 8081 eg: http://192.168.1.50:8081 to see what the webcam can see. Once motion is detected then the script shutter.py is called and fires the camera - that's it !!
The short video below shows the setup working, this was before the battery pack was completed:
RPi Controlled Canon DSLR Motion Detect
This does work 'in the field' but is a bit restrictive by the length of USB cable from the webcam to the RPi. To overcome this we need the webcam independent of our RPi running motion.
We'll use another program called 'mpeg-streamer', details and instructions of which are found here :
There is information regarding other programs in there but we are interested only in mpeg-streamer for this.
All we do then is edit motion.conf again and add the line
In the NetCam section of the file, amending the IP address according to whatever your second RPi's address is.
I have had this working on the bench but no video available.
So that's it, you should now be able to get 'up close & personal' with whatever you want to get pictures of, without having massive lens or sitting around getting bored, hope it's useful.
Thanks go to people who I have linked to, it's thanks to their efforts that this work has been possible.
I'd also like to add my personal gratitude to Adam Kovacs for supporting me in this piece of work - Thanks Adam - Top Man !!