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
@Patrick, I've tried resetting the camera's WiFi - problem is, I canot turn WiFi on WITHOUT pairing it to a device! I bought this camera through eBay as a refurbished device, but the USB port doesn't work, so I cannot update the firmware (perhaps, a firmware update wold solve this problem???).... I've submitted an email to GoPro support and asked them about putting the camera into WiFi mode w/o pairing.
I may have to bite the bullet and buy a new camera, which would be okay. I have to aerial video plaltforms - a highly modified Parallax Elev-8 and a Tarot FY680 Pro hexcopter. I plan to put the R.P. camera control solution on the Tarot (as well as swapping out the 2D gimbal for a 3D gimbal which I've ordered) - I can keep the refurbished camera on the Elev-8 and limit it to shooting videos as I do now...
@Brian, It can be tricky to get the PI to connect to the GoPro. Make sure you don't have any other devices automatically connecting. The camera will only accept one connection. You should not need to pair it, but you may need to reset the WiFi on the GoPro if you connected previousy with your phone.
Cannot connect to GoPro. Another thing came to mind.... When using the app on my iPhone, I had to "pair" it to the camera. There's a setting for pairing with the app and the camera issues a number that you have to enter into the app in order to establish a connection - youalso have to enter the G.P.'s network name and password. Once you've "paired" the camera to the phone you can control the camera with the phone when it's in WiFi mode and you launch the app - it automatically turns the camera on.
I'm wondering if I have to something equivalent to "pairing" on the R.P....
Late flash! Just got off the phone with a buddy of mine - he suspected that I was pinging myself with the 10.5.5.100 address, so with a little experimentation on my mac using network preferences, I determined that the gateway address of the GoPro is, as you said all along, 10.5.5.9.
But I cannot ping 10.5.5.9 on the Raspberry, so I'm still not sure what's going on. He suggested using wget or curl to ascertain whether or not I'm connected to the GoPro - don't know if they're on the R.P. but at least I have some experiments to go on, and I've learned a few things in the meantime!
@Patrick, Yes, I can ping the GoPro - I.P. address is 10.5.5.100. I've got a Hero4 sliver edition camera. It has been refurbished. It works okay except that there is something wrong with the USB port - cannot recharge or download imagery - the computer does not detect the device when I plug it in, so I have a separate battery charger and I have a SD reader, so I remove the SD card after a video mission and download the video to my computer using the separate reader.
I hadn't considered the USB problem to be relevant as I can reliably connect and control the camera via the iPhone app I have.
@Brian, can you ping the camera from the Raspberry Pi? Also, which GoPro are you using? The commands are totally different for the Hero4 and Session+ compared to the Hero3 series.
Latest status:
I forgot to change the IP address in my test script to 10.5.5.100. After fixing it, I ran the script and it completes but errors out. From the traceback it appears that the error is occurring while attempting to create a socket connection.
Oh, I forgot to mention - I forgot to do an apt-get update, so I did this and rebooted, but the problem seems independent of updates.
A thought just occurred to me: my GoPro is paired to my iPhone via the app I installed. Im shooting in the dark here, so if anybody has any suggestions, I'd love to hear from you!
I forgot to mention - the message also indicated that connection was refused. I can connect and send commands to my GoPro via an app I have on my iPhone, so I know that the camera is working. I'm at a loss at this point...
I bought and received an A+ board as well as a "starter kit" from CanaKit for learning/debugging. The CanaKit came with a R.P. 3 Model B board, so it has built-in Wifi as well as four USB ports. I have it all hooked up and went through some initial teething issues, such as changing keyboard mapping from "gb" to "us"...
I am able to connect to my home network as well as my GoPro camera, though the I.P. address turned out to be 10.5.5.100 - I can successfullyl ping this address. and if I turn off WiFi and try to ping, I get the expected "network is unreachable" message...
I brought up the Epiphany web browser after establishing a connection with the camera and attempted to enter the http command to turn it on::
http://10.5.5.100/bacpac/PW?t="mypassword"&p="%01"
But the browser responded with: "Oops! It was not possible to show this website"
@Patrick Duffy, I am not in a huge rush, I was hoping by late October.