You Are Viewing

A Blog Post

control your DSLR with a Raspberry PI

The semester vacation is over and at the end I made first steps with the libgphoto2. It is my goal for quite a while to control my DSLR remotely and without any cable connections. The solutions which you can buy have no possibility to change the camera settings. That’s the reason why I have bought a Raspberry PI Model B and a Wi-Fi nano stick. Therefore was enough performance available to handle the image data.

In the past I have tried my luck with Python and node.js but the project failed because of problems with the wrapper-libraries. Thus I wrote the application in C++ for the Raspberry. This gives me more control to find a problem because I use libgphoto2 directly. The software is a backend and provides a small REST functionality. It is “small” because at the moment only “GET” is implemented. Anyway you can send a HTTP command to the Raspberry, that will be executed and you get a JSON or XML file as response.  For example the trigger-command sends you the image data as base64 string in the response file when the command was successfully executed.With this kind of process it is platform independent. Only the streaming functionality of the live view is based on the client/server principle. If the application receives a live view command you get the socket connection data as response. The socket sends the data as soon as someone is connected. The process of the stream is simple. The first 4 bytes (big endian) determine the size of the coming image. You can see on the example client on github how it works. À propos github, you can find the project under the following url There you will also find a readme file with an overview of the implemented features.

I have recorded a movie because picture speaks louder than words.

The following functions are to be implemented in the future:
– time lapse
– continuous shooting
– bulb mode

I have tested the application with a Nikon D90 and at the moment it isn’t a stable software. Actually  I’m just  beginning but for this the application works well.

If I have caught your interest, feel free to work at the project!


The following packages have to be installed on your Raspberry to compile this project

sudo apt-get install build-essential libgphoto2-2-dev libexif-dev libboost-dev libboost-system-dev libmicrohttpd-dev
  • zoel on Wednesday October 16th, 2013

    Hi, I want to know about it, in raspbian wheezy we must install webserver like LAMP and we will use webserver ip to remote it? thanx and sorry for my english 😉

    • Tobias Scheck on Thursday October 17th, 2013

      Hey zoel, I hope I understand correctly. All what you have to do is starting the application. Inside the application is an own webs- erver (libmicrohttp) which answer to your requests. You can setup the listen-port in the settings.xml. For example, if your port is 8888 you have access to the api with http://device-ip:8888/. A valid list with all commands can you find in the available git repository.

  • Yannik on Wednesday October 23rd, 2013

    Hi, während des Compilens tritt bei mir immer dieser Fehler auf:
    In file included from Api.h:12:0,
    from Server.h:14,
    from main.cpp:13:
    CameraController.h:59:29: error: ISO C++ forbids initialization of member ‘_save_images’ [-fpermissive]
    CameraController.h:59:29: error: making ‘_save_images’ static [-fpermissive]
    CameraController.h:59:29: error: ISO C++ forbids in-class initialization of non-const static member ‘_save_images’
    make: *** [main.o] Fehler 1

    Was mache ich falsch?

    • Tobias Scheck on Wednesday October 23rd, 2013

      Hi Yannik,

      der Fehler lag bei mir. Ich hatte die ganze Zeit unter XCode auf dem Mac gearbeitet und die Updates ins git Repository geschoben. Leider hatte ich das nicht weiter überprüft, da es auf dem Mac ohne Probleme lief. Die Fehler habe ich eben auf dem Raspberry behoben und das kompilieren ging dann auch. Die Änderungen sind nun im Repository online. Beachte, dass nun noch die libfreeimage-dev zum kompilieren benötigt wird (thumbnail erstellung). Bei dem webif gibt es gerade noch ein Speicherzugriffsfehler…

      • Yannik on Thursday October 24th, 2013

        Ok, danke. Hatte es schon auf dem Mac compiled, da lief es auch, wollte es aber nun doch lieber auf dem Raspberry haben.

  • Olarn U. on Sunday November 17th, 2013

    Your project is so cool!!! I want to try it with my D700 but I’m not familier with c++. Would you please provide instructions to make it works? I have Mac and Xcode if needs, but it should be great if it can do everything on RPi.


  • Andre on Thursday August 7th, 2014

    Hey Tobias, ich würde gerne deine Api testen und mir einen Photobooth für meine Hochzeit bauen. Mit gphoto2 kann ich schonmal Bilder machen und speichern auf dem Raspberry mit meiner Canon, nun wollte ich deine Api testen und mir ein Webinterface dafür bauen. Nur leider weiß ich nicht, wie ich deine Api compile. Kannst du mir sagen, wie das geht?


    • Tobias Scheck on Saturday August 30th, 2014

      Hey André, entschuldige die späte Antwort. Ich war jetzt für 5 Monate auf Malta für ein Auslandspraktikum und kam nicht so richtig dazu mich um meinen Blog und die Kommentare zu kümmern.

      An sich musst du nur den Befehl “make” ausführen und das hinterlegt Makefile macht den Rest für dich. Als Resultat sollte dann eine Datei erstellt werden “CameraControlerApi”. Diese Datei ist dann auf dem Raspberry ausführbar.

      Um den Source erfolgreich zu kompilieren benötigst du noch die Bibliotheken: libboost-dev, libgphoto2, libmicrohttpd-dev, libexif-dev.

      Sollte es Probleme geben, einfach ein Zeichen geben. Dann muss ich noch mal schauen. Ich habe den Raspberry PI gerade nicht am laufen um genau zu schauen.

      Viel erfolg!

  • Jose Maria Camara on Saturday August 30th, 2014

    Hi, it’s really great your project and when I was lloking this video I started to thinking to try to do that. I have a nikon d90 too. Now I want to start to buy the hardware. Raspberry pi and wireless usb I ordered yet but I have a doubt with the camera cable, could you send me where I can buy that cable? I suppose that the cable is gps port (d90) to usb raspberry, is it OK, Thanks so much and well done ¡¡¡

    • Tobias Scheck on Saturday August 30th, 2014

      Hey Jose, actually you just need a USB to Mini-USB cable because you connect your camera over USB to the Raspberry PI.

      • Jose Maria Camara on Saturday August 30th, 2014

        Thank you so much, in few days Ill have the hardware and I will to try the software ¡¡ Ill tell you my advances . Thank you so much Tobias ¡¡

      • Jose Maria Camara on Wednesday September 3rd, 2014

        Hi Tobias , I am starting but I have a little problems with c++ and the initial configuration on Mac, but step by step I am getting it :). Now my problemas are with the libraries, I dont know what are the rigth versions of them. Could you tell me what are the libraries’ versions that you use. If you could ,I am really regarded, Ifyou could send to me the source code of these libraries. Now I have source code for: Libgphoto2-2.5.2,libmicrohttpd-0.9.37 and FreeImage3160. boost libraries I haven’t get yet. Thanks to much ¡¡

        • Tobias Scheck on Thursday September 4th, 2014

          Hey Jose,

          for my MAC I use macports to install all required libraries.

          With the following command you can install the dependencies:
          sudo port install boost libmicrohttpd libexif libgphoto2

          If everything is installed you have to add this libs to your Xcode project like the following screenshot:

          and add this libs to the search path of you project:

          Good luck!

          • Jose Maria Camara on Thursday September 4th, 2014

            Thanks god ¡¡¡¡¡ I was install¡ng each libary one by one. i have macports, but I am not using it, I spent several hours resolving conflicts between libraries and now with a simple line sudo port install boost libmicrohttpd libexif libgphoto2 all the libraries installed. Thank you Tobias, I’ll continue and I’ll keep you informed

          • Jose Maria Camara on Thursday September 4th, 2014

            Sorry Tobias, Now I find the libraries and I can add them.

          • Jose Maria Camara on Thursday September 4th, 2014

            Build Succeed. This weekend I ll try to connet the camera with the raspberry and so on¡¡

    • Jose Maria Camara on Sunday September 7th, 2014

      Hi Tobias, when I build the project in Xcode the result is buid succed but in the cosole log appear: Error: settings.xml: cannot open fileProgram ended with exit code: 0

      I was looking the code and the name ‘settings.xml’ is ok and the file is in the same directory and have the right permissions. could you help me with this error? maybe is something related to my Xcode project’s configuration?


        • Jose Maria Camara on Monday September 8th, 2014

          Hi Tobias , thanks for yout help and for being patien with me, thanks a lot.

          I have configured these values but the problem continues.

          I have recorded a video , fron 0 to compile the application to try to give you all the information about the process that I make. I get used to other IDE and programming languages and with Xcode and c++ I am a little bit lost. Thanks so much and sorry for answering all the time

          The video is about 9 minutes

          • Tobias Scheck on Tuesday September 9th, 2014

            You were right, there was an error with the path to the xml files. I’ve updated the repository.

  • Andre on Friday September 19th, 2014

    Hi Tobias, habe alles ans laufen bekommen, allerdings bekommen, danke dafür schonmal! Nun meine nächste Frage:

    Ist es möglich, dass man das Live-Bild auch im Web anzeigen kann? Ich würde nämlich gerne einen Photobooth bauen, bei dem man erst sieht was fotografiert wird, dann ne taste drückt und dann soll das Bild gemacht werden. Ohne Live-View funktioniert das ja schon recht toll. Würde mich über eine Antwort freuen, ob du das Video irgendwie in ein lesbares Format bekommst.

    Ansonsten, hast du irgendwo die Java-Application da? Zur Not würde ich sonst gerne probieren, das Ganze mit der Java-App zu bauen und dann an mein Win 8 Tablet anschließen.


    • Tobias Scheck on Monday September 22nd, 2014

      Hi Andre,

      also im Moment ist es noch nicht möglich den den Stream per WebSocket ins Web zu bringen, da die Implementierung des Liveviews auf einem einfachen TCP Socket basiert und nicht auf einem WebSocket.

      Es gibt im Projekt einen ExampleClient welcher auf Java basiert und dieser hat die Funktonalität implementiert zur Anzeige des LiveView-Streams.

      • Andre on Tuesday September 23rd, 2014

        Hi Tobias, danke für die Antwort. Den Client habe ich gesehen, weiß nur leider nicht was ich machen muss um das wie in deinem YT Video zum laufen zu kriegen.

        Kann man den Socket denn umbauen auf einen WebSocket?


  • Yongjun Moon on Friday September 26th, 2014

    Hi, Tobias. thank you for your nice work.

    I got two problems:
    1) When I try to compile your code, I got the error below. I searched on Web so added “-lpthread” at the end of the LDFLAGS line, and it seemed to work.
    /usr/bin/ld: CameraController.o: undefined reference to symbol ‘pthread_getspecific@@GLIBC_2.4’
    //lib/arm-linux-gnueabihf/ error adding symbols: DSO missing from command line
    collect2: ld returned 1 exit status
    Makefile:11: recipe for target ‘CameraControllerApi’ failed
    make: *** [CameraControllerApi] Error 1
    2) However, when I execute CameraControllerApi, I got the second error which I cannot fix.
    $ ./CameraControllerApi
    Segmentation fault

    The interesting part is that there is no execution error when I try this on Ubuntu. (I still got the pthread error but fix it like I explained.)
    I even formatted my SD card, reinstall Rasbian, but it does not work.
    Do you have any idea to solve this?

    I’m looking foward your help.


  • Pablo on Friday October 3rd, 2014

    Hello, I felt in love with your project. Is there a way to control the camera via iPad? Maybe some app compatibility? I want to use my camera (Canon 7D) and raspberry pi to live view from iPad, so I can control it by distance.

    I made my raspbery pi into a router already. So it made easier to carry only it where I’m going to. Now I need to find a way to stream.
    The pics you took (using your program) are stored inside the camera (on the memory card), right?

  • Sven on Sunday November 9th, 2014

    Hi Tobias, hab erst ein Kommentar unter deinem YT-Video geschrieben und seh jetzt das hier noch aktive an der Sache gewerkelt wird 🙂

    Ist es Möglich das du eine Anleitung machst für Leute die nicht so routiniert sind mit dem Pi bzw. Linux …

    Finde die Möglichkeit echt super da man ja auch mit jedem Gerät einfach per Webinterface zugriff hat und nicht auf ein OS wie bei dslrControler angewiesen ist …

    Hab zwar schon ein wenig mit dem Pi gebastelt aber alles was mit neu ist und englisch ist anstrengend für mich zu begreifen 😀

    Danke schon mal und gut das es jemand gibt der so ein Projekt betreibt !

  • Guillaume on Monday November 17th, 2014

    Great code ! I like the idea of an web API for remoting. However on my Pi CameraControllerApi is crashing.
    What libboost and gPhoto version are you using ? With boost 1.49 and gphoto 2.5.5 I got :
    terminate called after throwing an instance of ‘boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector >’
    what(): conversion of type “Ph” to data failed

    when requesting /settings?action=list ?


  • Jan on Friday December 5th, 2014

    Hallo Tobias,
    Ich habe heute versucht alles auf meinem Rasperry zu kompilieren, und das Klappt auch sehr gut bis:

    g++ -g -lboost_system -lgphoto2 -lmicrohttpd -lexif main.o Api.o Base64.o CameraController.o Command.o Helper.o Server.o Settings.o -o CameraControllerApi
    /usr/bin/ld: CameraController.o: undefined reference to symbol ‘pthread_getspecific@@GLIBC_2.4’
    //lib/arm-linux-gnueabihf/ error adding symbols: DSO missing from command line
    collect2: ld returned 1 exit status
    Makefile:11: recipe for target ‘CameraControllerApi’ failed
    make: *** [CameraControllerApi] Error 1

    Was mache ich falsch ? :c

  • Alvaro on Sunday January 4th, 2015

    I´m new in this “planet” and I have a raspberry pi but I dont know if I have to install any OS and if I hace to.. I do not know how to instal that API…
    A noob guide is possible? 😀

  • Erti on Monday February 23rd, 2015

    Hi Tobias,
    You have done a great job and I really do appreciate it very much. But nevertheless I have some very stupid questions.
    Where do I get the files downloaded ?
    How do I get them compiled ?
    How do I get them in the Pi and get it up and running ?

    Please be so kind to give a detailed advice or let me know where I can more detailed information. For someone who is trying to do his first steps this seems to be quite complicated.
    Thanks alot for your patience.

  • Antonio on Monday March 16th, 2015

    Hi Tobias and everyone,

    Have you ever gotten the following error when compiling in X-Code?

    “3 duplicate symbols for architecture x86_64”

    Best regards,

  • Tobias Scheck on Thursday March 19th, 2015

    Hey guys, sorry that I did not answer you. I’d no time for this project (that annoys me as well) because of one semester abroad (Malta) and a stressful 5th semester with a lot of lectures and tasks. That’s the reason why I’d no time to work on the project.

    As you can see and what I see is that C++ not really comfortable for such a project. Because of this I’m working on a newer version of this project. This newer Version is also my Bachelor thesis and this means I’ve more time which I can spent on it. The newer version uses Python as developing language and libgphoto2 (again :)) as interface between Python and your DSLR.

    Hopefully you have time to wait for a newer version which is easy to handle and more comfortable.

Leave a Reply

“The higher the technology, the higher the need for contact.”
John Naisbitt

do not hesitate

Contact me

Contact Info