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
@BlkSwanPres, I have a proposed architecture for geotagging with the gopro camera and the PI. I think it will take about 20 to 30 hrs of coding, plus testing time. I may get some time next week to start the project. How soon are you wanting a solution?
Okay. I have added the code to test if already recording if I attempt to change modes and send a stop commend. Here is a copy of my modified script: Click here I have not tried to run it yet.Note - I am going to use pin 3 for the camera mode signal which will come directly from my receiver.
@Brian, You should not have any interference issues. WiFi will stay fixed on a single channel and the Spektrum will hop to find an open one and exclude the WiFI channel. I have flown out to 4 miles using this setup and never had any issues.
I am pretty sure the GoPro will stop recording if you switch modes and save the stream. But you should still send the stop command.
Patrick, you are absolutely right! It didn't occur to me until you suggested bypassing the APM to toggle the camera mode - I will certainly do that.
I have already modified your script - eliminated the argument passing logic and incorporated the check for camera mode at the top of the main loop. But I have a question: If the camera is in video mode and recording and I switch modes to Photo without first stopping the recording, will the camera automatically stop recording? Being somewhat of a defensive coder, I've already added a test to first see if I'm recording when the mode change command is received and I stop the recording before changing the mode.
I can't wait to get the R.P. board - I already have the dongle and a clear plastic enclosure. But I'm concerned about component placement - I'm using a Spektrum AR8000 receiver which is mounted on the forward side of the chassis (the slave rcvr is underneath). I'm thinking I might reposition the receiver to one side, mount the R.P. in front or on the carbon fiber rods where the gimbal is mounted - I can mount it underneath the rods, just behind the gimbal... I'm just worried about interference between the WIFI and receiver...
Thanks again for posting this solution -I'm looking forward to getting this to work and shooting some aerial stills!
@Brian, If you want to control the camera with additional transmitter switches, I would suggest using the Raspberry PI directly connected to the receiver's PPM output. I have done this with a Sony QX10 to control the zooming. The PI can read PPM signals using Python GPIO library. You can then pick any switch on your transmitter to trigger something on you camera, change modes, or whatever, until you run out of channels.
Patrick, I answered some of my questions by downloading your script and trying to follow the logic. I have to figure out how the argument mechanism works that controls which mode the camera is in - that's the part I will want to modify so I can toggle between modes. Otherwise, I believe I should just be able to use the script as is....
Patrick, I like what you did and would like to emulate your solution with a minor additional bit of functionality - I'd like to toggle between video and still modes using a two position switch on my transmitter. I'm thinking I can map a channel to a switch and a servo port on the APM, and then have the R.P. monitor the pin for the camera mode as well as pin 9 for the shutter/record commands.
But I'm Python illiterate and may need some assistance - would greatly appreciate it if you can help me if I get stuck.
I tried to get the list of http commands by following your link but got a 404 response - can you send a new link?
Also, I'm not sure aout the syntax of the example command you used for turning on the camera:
http://10.5.5.9/bacpac/PW?t="wifipassword"&p=%01" Are double quotes supposed to go around the password or is the last double quote not supposed to be there?
Thanks again for your valuable article!
@BlkSwanPres, I am researching it now. I'll comment in the next couple of days as to how long I think it will take.
What do we need to do to start moving forward with this a bit?
Just a note, I was ramping up to use two USB cams, one IR one standard/RGB. The whole point was to do NDVI for crop health imaging. I wasn't even able to get as far as creating a map with the RGB alone, but the tests I did with geotagging images in place was promising. I imagine if you used two USB cams, or even two GoPros (although weight on a multirotor like I was using would end up becoming an issue), you could easily do what I was working on. Probably even a notch filter on any other camera. From my tests, the GPS info from even the standard 3DR GPS unit was much more accurate than any other camera with built in GPS I had experience with (Sony AS30 and AS100, as well as Canon S100(?) coming to mind), and will probably be even more accurate if using a Ublox M8N (I had one to put on said drone, but never got that far) or even Piksi RTK unit. I'm extremely interested in anything y'all might be able to do with what I had been working on