How to control a GoPro Camera on APM/Pixhawk with a Raspberry PI using WiFi

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.

gopro.py

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:

rc.local

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.

Views: 36373

Comment by Checkers on May 10, 2015 at 2:49am
Cool idea as a workaround not being able to control the gopro over USB but depending on your setup the WiFi might cause issues with fpv / controlling the aircraft.
Comment by Patrick Duffy on May 10, 2015 at 3:06am

Somehow my post got published when I saved as a draft. I'll be updating it with the rest of the info later.

Comment by Patrick Duffy on May 10, 2015 at 3:09am

@Checkers, yes it could interfere with a 2.4ghz radio, but this has not happened on my tests.  The channel selection of your radio should see the WiFi and pick a clear channel. It's no different than you flying with other folks with nearby radios.

Comment by Tobias Witting on May 10, 2015 at 5:14am

this is awesome! Well done! I've just completed a HD FPV setup following your posts from a while back. Not yet using ubiquiti gear but only a cheap 5GHz wifi dongle on the PI. Only ground tested so far, but I am blown away by the HD video compared to analog FPV. Being able to control a gopro also seems like a really useful thing for mapping etc. Now all we need is hdmi in for the PI and one could stream gopro video...

Comment by Stuart Brookes on May 10, 2015 at 6:57am

I have seen reports of people losing radio due to the WiFi. Its not exactly the same as flying with other people on 2.4. The gopro is much much much closer to the receiver, and wifi uses wider bandwidth and isn't frequency hopping/spread spectrum.

Comment by Stuart Brookes on May 10, 2015 at 6:58am

gopro wifi at that

Comment by Patrick Duffy on May 10, 2015 at 10:24am

@thomas Butler.  So far I have not had an issue with the radio using DMSX. But it could also be because I have a 33dbm transmitter, which is close to 5x the power of most radios. Your analysis could be correct, as I happen to work in the wireless testing industry and work with cellular/wifi and bluetooth devices in a lab environment.  The wifi won't hop, once a channel is established, and since the radio is using a CDMA (code division and spread spectrum technology), it can stand a lot of noise. The radio will try to pick a clear channel, and if I am not mistaken DSMX has a 80db intermediate channel rejection ratio, so you have to have an adjacent channel that has 80db higher strength, and be close to the same channel to kill it.  You would be surprised how close these channels can get before you drop the connection. We do intermediate channel tests quite frequently where I work with both CDMA and LTE and you can practically stomp on the same channel before it drops.  It will also depend on the WiFi device's power output.  It's possible to set this to the lowest level to minimize this effect, but I have not experimented with that yet.

    However, this is all 'theory'.  If it does not work in the field, none of the math makes a difference.

Comment by Patrick Duffy on May 10, 2015 at 10:28am

@Stuart,  true that Wifi is not hopping, but the radio is.  All of this (of course) will depend on the quality of your receiver, and how much noise/power the dongle is putting out. So far, I have not had a problem, even out to 1.5 miles.

Comment by Patrick Duffy on May 10, 2015 at 10:33am

@Tobias,  I am also using a 'cheap' 5.8ghz dongle for this example, but still have the Ubiquity radio on the ground. It works very well with an antenna tracker.  I am trying a 2 mile test tomorrow.  Ran some tests yesterday to 1.5 miles and my RSSI was still above 50%.  I was amazed that I got that kind of range using a wifi dongle I bought at Fry's electronics.   Here's the link to the dongle I am using: 

http://www.amazon.com/Netis-WF2561-Wireless-Supports-Antennas/dp/B0...

I swaped out the standard antennas with planar wheels, but the dipoles also work pretty good.

Comment by Patrick Duffy on May 10, 2015 at 10:41am

@thomas, one other note about your comment. $8000 for 'real time' HD. You mean zero latency by real time? Even at 30 fps, the theoretical minimum is 33 ms. 60fps, is 15 ms.  

But you can have something around 120ms for less than $200 using the raspberry pi setup with WiFi.  That means you are paying $7800 to drop 100 ms.  That's $780 per millisecond.  Pretty expensive!

Comment

You need to be a member of DIY Drones to add comments!

Join DIY Drones

© 2019   Created by Chris Anderson.   Powered by

Badges  |  Report an Issue  |  Terms of Service