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
FYI, for anybody that has implemented a wireless link to their UAV and you want to also control the GoPro from the ground. After experimenting with GStreamer and the GoPro, the current version of GStreamer has a bug in the needed decoder and the live video is choppy and the stream freezes. Using ffplay however does work.
ffplay is available here: http://ffmpeg.zeranoe.com/builds/
The command to show the GoPro live stream is :
ffplay -i http://192.168.1.2:8080/live/amba.m3u8
The ip address should be the address of your RPi with port 8080 forwarded to 10.5.5.9:8080
If you also forward port 80, you can directly control the GoPro using the utility here: http://cam-do.com/WiGo/
@Bjoern, I am investigating how to geotag the images on the RPi, store them locally, and/or send them over the link as you described. Maybe in a week or two I'll have something to publish.
If you grab the pic from camera to raspberry pi, you could geotag it on the RPi which might also run MavLinkProxy. Add to the cam trigger event a saveaction of last seen gps coordinates from Mavlink.
You can send the geotagged picture asynchronous using UMTS/3G,LTE/4g or WiFi or any other dateline to you ground station using ftp or scp. The ground station could poll for new files or get a notification.
Same could be done with Hires video.
Just an idea... ;)
@Tobias, That Connex solution claims 1ms latency. I think they are fudging the numbers. Sampling the CCD takes 15 ms for one frame at 60fps, so you can't ever get 1ms latency. The 1ms they claim is the time it takes to send the data over their link, not including any pre or post processing to display the video. Without any compression, it's possible to get sub 50ms latency. I don't believe the true latency of the Connex solution is 1ms.
@Teemu Launis, Anything that can do WiFi will work, including Arduino. The A+ model raspberry pi is about half the size of the other models, so it's competitive as far as the size is concerned. If you could get an Arduino that has a USB port, or one with WiFi native, it should work.
@benbojangles, yes there is a way to transfer the images on the fly. The setup I describe here is just for controlling the GoPro from the PI. To get the functionality you want, you need a 2nd connection to the GCS, and a port forwarding configuration on the PI that will allow you to communicate with the GoPro from the GCS. I am working in this and will update my post when I have the setup working. In my current setup, I have a 2nd WiFi interface (high power 5.8ghz) that is connected to the GCS via a Ubiquity Rocket M5 mounted on an antenna tracker. In theory you can even preview the GoPro, but the latency will be much poorer than the raspi-cam, probably around 500 ms to 1 s, but it's good enough to help you point the camera if it's on a gimbal. I'll let you know when I have something to publish.
Is there any way to wifi transfer the gopro images to Rpi on the fly? And is there anyway to use existing gps with Rpi to geotag the transferred images?
In these days i interface to VR Alter Ego OS the GoPro and all the Sony camera compatible with Sony API :
Sony Qx 10 Camera
https://www.youtube.com/watch?v=yGHxWHcKq4Q
Sony HDR AS20 Camera
https://www.youtube.com/watch?v=BBK6MpiYugM
I totally Agree with Patrick about the managment of advanced payload by a wifi Adhoc network ...
In my work i interface and retrasmit to vr pad station the preview , video with good latency depend of limit of payload this is an example using 3G connection
https://www.youtube.com/watch?v=ssfB8hdFdmk
Best
Roberto