Monday 4 August 2014

Triggering GoPro using a webcam

This project makes use of a cheap webcam and a Raspberry Pi (purchase) to provide a motion detection unit capable of triggering a GoPro Hero 3+ Black Edition (purchase) camera connected to the Raspberry Pi using WiFi (using a small WiFi adaptor).

Using this setup it is possible to achieve a number of things that cannot be achieved by using a motion detection system based solely on the webcam.
  1. The GoPro camera has much better resolution and clarity than the cheap webcam used here.
  2. Burst mode on the GoPro has rates of up to 30 frames per second, great for photographing wildlife.
  3. The motion detection area can be different to the area where the photograph is taken. The arrangement below used during testing shows a system that is triggered by the cat (Phoenix) coming up the stairs, but the GoPro is situated in a slightly different location. Imagine the webcam being used to detect motion in the area around a bird feeder, with the GoPro focussed entirely on the bird feeder.
Test setup, the Raspberry Pi and cheap webcam (left) detect the cat as it reaches the top of the stairs. The Raspberry Pi then triggers the GoPro (set in burst mode) to take a quick succession of photographs as the cat walks past.

For this project I used the Raspbian Linux distribution on the Raspberry Pi but similar instructions will apply on other distributions. For setting up the project connect the Pi to a wired network as both USB ports are used (one for webcam, the other for the WiFi adaptor).

These assume you are running a *nix system.
  1. Turn on the GoPro and enable its WiFi functionality (GOPRO APP).
  2. Connect the WiFi adaptor to the Raspberry Pi. Connect to the Raspberry Pi from your computer (ssh -X pi@xx.xx.xx.xx) and configure the Pi to connect to the GoPro's WiFi network (easiest way is to run wpa_gui).
  3. Install the motion application and php: sudo apt-get install motion php5-cli
  4. Make it so motion can run without errors: chmod +r /etc/motion/motion.conf
  5. In the /etc/motion/motion.conf file change the following lines:
    target_dir             /home/pi/motion
    on_start_event         php /home/pi/goprophp.php SHOOT
  6. Download and extract the GoProPHP tool into your home directory (or clone the project using git).
  7. You can test that everything is setup correctly by putting the GoPro into burst mode:
    php /home/pi/GoProPHP/goprophp.php BURST
  8. To launch motion when the Pi is powered on add motion after the comments in /etc/rc.local
  9. Plug in the webcam and restart the Raspberry Pi. If all goes well you have your motion-detecting camera working.
The /etc/motion/motion.conf has numerous options you can use to customise the behaviour of the system. Video can be recorded using the START and STOP commands of GoProPHP and the on_event_start and on_event_stop lines in motion.conf.

Here is the first photo of Phoenix taken using the setup illustrated above, obviously potential for better lighting but it illustrates how the two-camera solution may be useful.