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 installed my gimbal - it is working fine. Also installed the R.P. but have a question: Don't I need a connection from the receiver to the APM for the camera trigger? If I use CH7, which is AUX2 in my setup, don't I need to connect the AUX2 channel to the APM? Would it be the #7 Input port?
@Patrick, I experienced some "yaw jitter" which occurred when a cross breeze pushed the copter off course and the autopilot tried to correct. A three axis gimbal removes minor yaw movements by keeping the camera stationary and only following the aircraft when the yaw angle increases - it sorta lags behind the aircraft. For this reason, I prefer the extra motor. But I would be happy with simply having tilt control.
The problem with the Tarot T4 3D gimbal was that I could not get tilt control at all. Thinking it was defective, I purchased a second from another supplier, but it vibrated and I could not stop the vibrations, even by messing with the torque settings. So I returned both. The U.S. Tarot distributor has ordered a TL3T01 gimbal, which I hope will work.
@Brian, I use the Turnigy X8 transmitter which has 3 pots and a bunch of switches. I use a 2 axis gimbal, so I am only controlling camera pitch with the pot. Yaw is controlled by the copter rotating with the rudder control on the transmitter. I don't see a reason to have a yaw servo unless you are doing some sort of filming where you need it absolutely stable. My experience is that it's not needed. I would go with a 2-axis gimbal, but the Turnigy 8x should still work for your 3-axis setup.
@Patrick, I have a Spektrum DX8 with only a single rotating pot.(AUX 3). I tried to use a Tarot 3 axis gimbal but could not get either pan or tilt to work. I had to return it and I'm waiting for another Tarot model. I could get away with just having tilt control and "pan follow" to get rid of yaw jitter.
does your transmitter have two pots?
@Brian, Glad to hear you got it working. I use an 8 channel receiver, and control the pan/tilt with programmable knobs on the transmitter, and the modes with the programmable switches. You should be able to control everything with one transmitter.
Latest status: I modified my python script to test the functions camera modes (toggling between photo and video) and triggering the shutter (in photo mode) as well as start/stop recording (in video mode). I modified the program so that I entered a command: "video", "photo", "snap", "quit". - simulating the polling of the R.P. pins. My program works! I can command the camera to go into photo or video mode and I can start/stop recording as well as take still photos.
So now, all I have to do is connect a receiver to the I/O pins on the R.P. and see if I can control the camera via my transmitter.
I am waiting for delivery of a 3 axis gimbal for my hexcopter and I'm considering using a 2nd transmitter to control the gimbal - 2 channels (pan, tilt), and the camera - 2 channels (mode, shutter). Using a 2nd transmitter shouldn't be too onerous as the autopilot will be flying the aircraft anyway so I can focus on controlling the camera.
Patrick, I came back to this project and thought I'd try again to see if I could make some progress connecting to one of my GoPro cameras. I examined my copy of the /etc/network/interfaces file and discovered that I fat-fingered the network name that my GoPro was broadcasting. After fixing that and rebooting, I was still unable to ping the camera however using the network command I could see 10.5.5.9 as the gateway on wlan0. The camera was turned on while I was doing this.
I opened up a browser on my R.P. and typed in the gateway I.P. address 10.5.5.9 and I saw this:
In the browser's command window, I typed the http command to put the camera into photo mode and it worked!
I then turned off the camera and tried to turn on the camera from the browser but that failed. However I'm encouraged - I'm okay with making sure the camera is turned on - if I can toggle between photo and video modes and trip the shutter as well as start/stop video recording then I'd be a happy camper!
@BlkSwanPres, I have not done any work on geotagging, or anything else hobby related for that matter.
Any updates on the geotagging aspect?
@Patrick, the link you provided for setting up the GoPro in wifi mode doesn't work - seems GoPro has taken the page down. I just had a chat session with a guy from GoPro - says the camera was not designed to connect w/o usig the app on a device. Of course, he's getting this secondhand as he doesn't know. But I'm not confident that I'll get any help from them...