This post will describe how to control a GoPro camera (usually mounted on a gimbal), via a Raspberry Pi with a USB WiFi dongle.
The ideal Raspberry PI for this setup is the A+ model because it is small and has the needed single USB port for the WiFi dongle.
Parts List:
1 GoPro Camera
1 Raspberry PI (suggest A+ model, but any PI will work)
1 USB WiFi dongle (PI approved) Suggest this one: AirLink N150
2 Jumper wires or 1 servo header that can plug into 1/10th center pins (with center power pin removed)
1 APM or PixHawk board
Of course, all of this is mounted on your Quad or Plane or whatever. On my hexicopter, the PI is powered by one of the ESCs UBEC outputs, where I cut a micro-usb cable and soldered the 'red' and 'black' wires to the power output of the UBEC of the same color. The other two USB wires are not used.
Setup:
Step 1: Enable the GoPro WiFi access:
The first step in making all of this work is to configure your GoPro camera to accept a WiFi connection. The camera is actually a WiFI access point.
The details on how to setup your camera is here. If you can connect the GoPro App to the camera, then you can connect the Raspberry PI. You should verify that the GoPro WiFi is working with the GoPro App BEFORE proceeding to connect the PI. You can pick a unique access point name for your camera and use the same name in the Raspberry PI configuration when connecting to the camera with the PI.
Step 2: Connect the Raspberry PI to the GoPro Camera's WiFi:
Once you have established the camera's access point and assigned a name and password, you can make an entry in your PI's network configuration file to configure the connection.
From a shell prompt type the command: sudo nano /etc/network/interfaces
Add some lines to the file as follows:
allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-ssid "mygopro"
wpa-psk "mypassword"
Reboot the PI and it should automatically connect to the GoPro.
Step 3: Communicate with the GoPro
The GoPro camera should have the standard IP address of 10.5.5.9. If you can ping this address, you have successfully connected to the GoPro so now you are ready to send it commands.
The list of commands are here. The camera is controlled by sending HTTP request commands in the form of a header string.
for example, this string turns the camera on:
http://10.5.5.9/bacpac/PW?t="wifipassword"&p=%01"
Where 'wifipassword' is the password you set when configuring your GoPro.
You can experiment with sending commands with a web browser to get familiar with how to control the camera with web requests or write your own scripts.
Step 4: Use a Python Script to Control the Camera
Attached is a sample python script that will listen for a signal on GPIO pin 5 on the PI header, and send a request to the camera to take a picture when triggered.
To use the code, start the python script after connecting to the camera with the following command:
sudo python3 gopro.py -photoMode
This will start the script with the camera set to take pictures. If you want it to trigger a video instead, leave out the '-photoMode' option.
Step 5: Configuring APM or Pixhawk to send the signal to the PI
To use this setup with the APM or PixHawk control board, you need to connect the output of the 'relay' pin (A9 on the APM), to the GPIO pin 5 on the PI (or the pin of your choice). The script is configured to use GPIO pin 5.
Here is a picture of the APM board from This link
The PI pinout is here
Connect Pin 29 (GPIO 5) on the PI to A9 (S) on the APM, and GND pin 30 on the PI, to GND A9 (-) on the APM. Check the link on the APM website for the PixHawk settings for the relay output pins as I have not used PixHawk (yet).
Step 6: Configure your Radio to Trigger the Camera
In Mission Planner, you will need to select which channel on your radio to assign to trigger the camera input.
This link describes how to configure the shutter.
Select "Relay" for the Shutter output (not RC10 as shown in the above image example).
Then set the Ch7 option to "Camera" as shown here:
This can also be set on the "Advanced Parameters" setup area.
Step 7: Start Script on Boot:
To make all of this automatic, you can configure your PI to always connect to the GoPro and start the script when the PI boots. Or you can do it manually when you want to fly.
To make it automatic, you can modify your '/etc/rc.local' file to make the script start on boot. Here is a sample rc.local file:
Once you have completed all of these steps, you should be able to trigger the camera to take a picture with a switch assigned to Ch7 on your radio.
If you want to GeoTag your images, you can follow the instructions at the ArduCopter GeoTagging page.
Happy flying.
Comments
Okay, let's see if I can vaguely remember how it went (unfortunately I don't have access to my original code, long story but the drone I was working with wasn't mine)
I used pyexiv2 (http://tilloy.net/dev/pyexiv2/) for the actual geotagging. This is actually an outdated package, and requires you to run using Python 2.6/2.7. I got the actual code (modified a bit) from this post (http://stackoverflow.com/questions/10799366/geotagging-jpegs-with-p...) on stackoverflow. I had used DroneKit to easily pull the GPS info from the Pixhawk, although I can't fully remember the code for that part, although I remember I pulled the info shortly before calling the camera. I had used USB webcams, and experimented with the PiCam as well. But you should have an easier time since you're planning to use a stand-alone camera. I had to call the camera to take the photo, then send it to a background process that would apply the geocoding to it. Thinking back on it, I was probably relying on the Rasp Pi too much. I had it set up for livefeed via @Patrick Duffy's method, and using it to issue Mission Planner commands to the Pixhawk on top of camera control and geotagging.
Hopefully this information can help you on your mission. I want to eventually get into this type of stuff, I just don't have the funds for it currently.
@BlkSwanPres, Somebody else may have already implemented this (L. Michael any comment?). But if not I would consider working on it. My main focus has been on flight video not photos, so I have pushed this to lower priority, but if there is enough demand for it, I may move it up in the queue.
For the Sony camera, I have the QX10 working with remote flight control, but the QX1 should work also as I believe they have the same API.
I am looking to use a GoPro and hopefully a QX1 in the future if it is possible.
@BlkSwanPres, I have not done any additional work on the geotagging feature. Please give some details about your configuration, what kind of camera are you trying to use?
@Patrick Duffy, @L Michael, Any progress with this? I have been searching for a way to use a Pi 3 or Pi Zero to geotag photos triggered by a pixhawk while in flight. I would be willing to help out financially to make this a reality.
@L Michael: Great!! please share the experience :)
@L Michael, if you have it working with the PI cam, it should be fairly easy to extend for the GoPro or other cameras. With the GoPro, you can access the last picture taken via the WiFi connection and update the metadata. It would be great if you would share your experience, and possibly we could create a one-stop-shopping area for folks that want to do mapping and tagging.
@Waladi I've been messing around with it a bit, and have had success using pyexiv2 to write the location data to the metadata of a photo. I haven't been using a GoPro, however, but have been doing this with both a PiCam and a USB webcam. I might do a post on it one of these days.
@Waladi, I have not tried real-time tagging yet, but it's on my list of things to do. You can do post-processing and tag the images after you download them by grabbing the MavLink data and using the utility built into Mission Planner. There is a tutorial on how to do this on the Mission Planner website.
Hi Patrick,
Just wondering, have you play/develop the automatic geo-tag image using Pi?
It would be awesome if you share it to complete the "cycle" of control camera + geo-tag while flying :)
Thanks in advance