I'd like to use my DSLR camera for the following use cases:

  • record a timelapse, e.g. shoot a picture every second (or every minute, or every hour).
  • take a group photo (including me) or self portrait with a DSLR, with several takes, without running back and forth to the camera after each take.

How could I leverage the USB interface of my camera to achieve this, say with a headless Raspberry Pi?

Hint: If you're reading this and you can afford to spend $15, you might as well skip the effort to set it up and buy an intervalometer - a specific hardware that does exactly this.


Use gphoto2 to trigger continuous periodic capture

This solution uses gphoto2 to remote control the DSLR and converts a Raspberry Pi to an intervalometer. It sets up the continuous capture as a systemd service so that your camera will start shooting as soon as the Raspberry Pi is ready.

  1. Download Raspbian lite and write it to an SD card, e.g. with Etcher.
  2. Assuming you have a spare keyboard and monitor, plug them to your Raspberry Pi - otherwise you'd have to perform the next steps remotely with SSH.
  3. Insert the SD card into your Raspberry Pi, connect it to the network, and login with user pi and password raspberry.
  4. Optionally, configure your Raspberry Pi with sudo raspi-config, for instance:
    • Configure the keyboard layout under 4 Localisation Options.
    • Setup a console autologin under 3 Boot Options in order not to have to type your password after reboot.
    • If you're using a Wi-Fi connection, you can configure it under 2 Network Options.
  5. Install gphoto2:

    sudo apt-get install gphoto2
  6. Create a systemd service: sudo nano /lib/systemd/system/gphoto2capture.service with the following contents:

    Description=gphoto2 DSLR Remote Control - Continuous Capture
    ExecStart=/usr/bin/gphoto2 —set-config capturetarget=1 && /usr/bin/gphoto2 —capture-image -I 1 - F 0

    Save and exit with Ctrl+X. This service triggers continuous capture to the memory card (capturetarget=1), ad-infinitum (-F 0), every second (-I 1).

  7. Activate the service:

    sudo chmod a+x /lib/systemd/system/gphoto2capture.service
    sudo systemctl --system daemon-reload
    sudo systemctl enable gphoto2capture.service
  8. Now, if you plug your camera to the Raspberry Pi USB port, you can test if the capture works by starting the service:

    sudo systemctl start gphoto2capture.service

    To stop the capture:

    sudo systemctl start gphoto2capture.service

    If this goes well, you have successfully converted your Raspberry Pi to a headless intervalometer. From now on, every time it finishes booting (it takes approx. 1 min 40 sec for me), the attached camera will start shooting pictures. Congratulations!

  9. Optionally, you can ensure that the capture takes place every time you plug in the camera, without having to reboot your Raspberry Pi, by writing a udev rule to track USB connections: sudo nano /etc/udev/rules.d/plug_usb.rules. The rule below stops the capture when the camera is disconnected or shut down, and restarts it when it is connected or switched on, assuming a Nikon camera:

    ACTION=="add", SUBSYSTEM=="usb", ATTR{manufacturer}=="NIKON", PROGRAM="/bin/systemctl restart gphoto2capture.service"
    ACTION=="remove", SUBSYSTEM=="usb", ATTR{manufacturer}=="NIKON", PROGRAM="/bin/systemctl stop gphoto2capture.service"

    Save and exit. Changes in the rules.d folder are tracked by udev, so there's no need to reload the configuration and the changes are active right away. If you unplug and plug the DSLR, it should start shooting after a few seconds.

That's it. You don't need the network connection, keyboard or monitor anymore. Just power up your Raspberry Pi and connect the camera to have it shoot a picture every second.

(Should you need to troubleshoot, check the system logs: tail -f /var/log/syslog).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.