Part Two: Here is the original picture of the finished product:


This is the second part of a 2-part series on 'How to build a High-Definition FPV UAV using a Raspberry PI with HD camera, using a high speed WiFi link.

In my first post on the subject (located here), I discussed the parts I used, and how to install them into a Hobby King Go-Discover FPV model. 

In this post, I will discuss installing the Raspberry PI and the PI camera in the Go-Discover gimbals, and the software configuration for both the Raspberry PI and the ground station PC.

From the previous post, step 3 was completed by installing the Ubiquity Rocket M5 in the model.  Now onto step 4:

Step 4: Install the Raspberry PI and PI Camera

Here is a photo of the position of the PI in the Go-Discover model:


The PI fits nicely just behind the camera gimbals, with the USB and HDMI ports on top. In the right side you can see the Cat5 network cable attached. This cable connects to the ethernet switch, which is also connected to the Rocket M5 input port.  

The two cables shown on top are the servo control wires for the gimbals, which I have directly connected to channel 4 and 5 on my radio.  I am using channel 4 (normally the rudder stick on my radio. Since there is no rudder on a flying wing, this is a convenient channel to use to move left and right with the camera. I have not (yet) moved to a head tracker, but if you already have that setup, just assign the channels accordingly.

To install the PI camera, remove the stock plate from the gimbals (for a GoPro), and mount the PI camera as shown in this photo:


The PI camera case fits very nicely into the slot, and again I used a small piece of velcro to hold it down. You could use a couple of small screws instead if you want a more secure hold.  The two gimbals servos are also shown here. They are simple to install, just follow the Go-Discover instructions.

Here is a front view of the PI camera installed:


Here is the block diagram describing all the connections:


Some comments on my previous post suggested that it is possible to eliminate the ethernet switch and serial-to-ethernet converter using the Raspberry PI and a serial port on the PI. I believe this post describes how to talk to the PI via the NavLink, but in this case, I want to use the PI to bridge the connection from the ground station to the APM/PixHawk. Somebody please comment on this if you know more about it.   I believe it would require a TCP/IP to serial link from the PI to the telemetry port on the APM, and some software on the PI to act as the bridge.  The main connection to the ground station is via the Rocket M5 and TCP/IP, not through a telemetry link (900 Mhz or Zigbee like I used on my other models).

Step 5: Getting it all to work with software configuration (the really fun part starts now).

Check out this post on what others have done with streaming and the PI.  My experiments showed that using GStreamer on both the PI and on Windows gives really good results with very low latency, if you use the right parameters. 

Get GStreamer on the PI by following this blog.   This is the same version of GStreamer that I am using on my setup. 

Make sure your PI camera works ok by plugging in the PI to a standard monitor using the HDMI port and follow the instructions on the Raspberry PI website on how to get the camera up and running (without GStreamer).  Once you have a working PI and camera, you can then proceed to stream things over the network.  

Note: It is suggested that you first get the PI streaming video by plugging it directly into your local network where you can also connect your ground station PC with the correct IP addresses (without the Rocket M5).   For my PI, I picked,  and for the ground station,    Make sure you can ping the PI from your PC and the PC from the PI.  

For streaming, you will also have to make sure all the ports you intent to use are open on the firewall (described later).

For the ground station PC,  you can download GStreamer here.  Make sure when you install, select to install everything , or full installation (not the default). 

Here is the command I use for the PI to pipe the camera output to GStreamer:

raspivid -t 0 -w 1280 -h 720 -fps 30 -b 1700000 -o - | gst-launch1.0 -v fdsrc ! h264parse config-interval=1 ! rtph264pay ! udpsink host = port= 9000

The command is explained as follows:

raspivid is the command to start the camera capture on the PI.  The -w switch is for the width in pixels, and the -h switch is for the height.  In this case, I am using 1280 X 720, but you can try any combination that fits your needs. 

The -b switch is the bit rate for the sampling. In this case I chose 1.7mbs to send over the stream. Again you can experiment with higher or lower values. This settings seems to work good for me, and the latency is almost unnoticeable.  

the "-o - |" is piping the output to gstreamer.  Make sure you include the dash before the pipe "|" symbol. 

For the GStreamer command, all the filters are separated with an exclamation point "!", as these are individual drivers that are part of GStreamer.  Since the PI has hardware accelerated video, the output is in a format called "H264", which is a highly-compressed stream. The GStreamer filters are configured to transport the output via a UDP socket connection to the target PC. Notice the 'udpsink' element which specifies the host - in this case your ground station, and the UDP port.  I am using port 9000, but you can use any open port on your system, but be sure to open the firewall or it won't work!  You can also use TCP instead of UDP, but for such a data stream, I chose to use UDP since dropouts are certainly possible, and with UDP this is ok, but with TCP, you could have socket problems and higher latency. 

Note: to get the PI to execute this command on boot, make a shell script with the above command and add it to your local.rc boot sequence. That way when the PI boots, you get the stream without having to log into the PI remotely. 

For the ground station PC, once you have installed GStreamer and opened the correct ports, use this command (from the command prompt) to view the stream:

c:\gstreamer\1.0\x86_64\bin\gst-launch-1.0 udpsrc port=9000 ! application/x-rtp,encoding-name=H264,payload=96 ! rtph264depay ! avdec_h264 ! videoconvert ! autovideosink

If all goes well, you should see the PI camera output on your PC screen in a popup window.  For those of you what want to use FPV goggles, you can connect to the HDMI port on your PC to display the output if your goggles support HDMI. 

I have this command in a batch file (with a PAUSE) statement at the end to keep the window open.

WHEW!  If you got this far, you are amazing. 

The last step to complete the build is to connect to the APM from mission planner.  The method I used to connect was to install a utility that converts a TCP connection to a virtual serial port, but I also think that directly connecting the mission planner to the TCP port will also work, however I have not tried it. I will post back later after trying it.

Here is the link to setup the serial to ethernet device to have an IP address and port.

Here is the link to the configuration utility for installing the virtual serial port.   

Once you have a serial connection over TCP/IP working to the APM, you should be able to connect with Mission Planner. On the maiden flight, it worked perfectly, and I didn't see a single drop in the telemetry data or anything noticeable in the video transmission, however my first flight was limited to 2km.

The last step is to connect the Rocket M5 to the Nano M5 and test everything using the OTA (over the air) connection. If all is well, you are ready to fly!  But be careful on your maiden, you just spent $700. 

Finally, here is a photo of my Antenna Tracker with the Nano M5 attached. My next update will include a video of a longer flight.  


Happy Flying!

E-mail me when people leave their comments –

You need to be a member of diydrones to add comments!

Join diydrones


  • @Cap,  should be fairly straightforward to modify mavproxy to intercept commands and run a script.  However, if you are wanting to design a more generic interface, you might consider writing something in native code instead of using python.  I am using a modified version of Ser2Net, which could easily be modified to listen for commands and run shell scripts.   It may also be of use to add custom messages to the mavlink protocol that are specific to the application, such as 'arm-video', instead of just assuming that a normal 'arm' command starts the video.  That way you have the flexibility of turning things on or off without necessarily arming or disarming the vehicle. 

  • @Patrick I'm using mavproxy on the companion board.

    My reasoning is for the following scenario, mind you I'm leaving out all irrelevant details of a much bigger concept... A UAV that is geographically separated from the operator, even at launch. The UAV will need to be in a low power "stand by" mode at all times, ready to receive a command link over 4G and be armed. I wouldn't want that stream running at all times, chewing up all the allotted data usage so I need a way to enable at arm, and essentially disable at disarm.

  • @Cap,  what are you using for the companion program, mavproxy or ?  Your proposal seems like it should work, although I am not sure what you are gaining by having the ability to start and stop the stream. Is there a functional reason why you don't want the stream to start when the BBB boots up?  

  • @Patrick, since I'm using BBB, there's not raspivid element... The command I use is just the gstreamer portion and I've only ever stopped/started it using an SSH session to execute a script.

    I haven't tried it yet, but I assume I should be able to execute that same script via a MAVLink command (Arm?). I still have some research to do before I can say for sure. Unless someone here has experience with this :)

    Essentially what I'm trying to do is send a MAVLink command to the UAV which is first intercepted by the onboard companion (BBB) which is listening for that specific command and executes a script upon seeing it. So an "Arm" command would in essence not only arm the FC, but also start my video feed.

  • @Cap,  If you need to start/stop gstreamer remotely, you can use a terminal, however, I think there may be an issue with raspivid unless it's started on the console terminal.  I always start the stream in the boot sequence in /etc/rc.local since I always want the video stream to be running so I have not tried remotely starting and stopping the stream.

  • @Roberto -- correction to my post above, the link now mysteriously works ;) probably something I was doing.

  • @Patrick, my thoughts exactly. I knew that the standard telem radios only supported ~57k so I figured pushing that through modern broadband would make negligible difference on the delivery.

    @Roberto , not sure what I am doing wrong, but clicking that blog link simply refers me to the master blog list at

    No matter what I do, I keep just landing on that page and cannot read the blog post... (Noob mistake I'm sure)

    That said, I am very interested in your app as well. I was also researching a method to start/stop the gstreamer feed remotely but figured I'd have to resort to some sort of remote execution of a script, either mavlink triggered or otherwise. I read somewhere that there is support builtin for APM to trigger scripts located on a companion board (RPi or BBB)

  • @Roberto, nice work.     Is there a link to your Java app?     Just wondering what board you are using for the HDMI in for the PI.  I have seen this one but don't know of anybody who has actually tested it:

  • Moderator

    @Cap @Patrick Duffy

    In this post you can see our last result using 1 single channel with low latency video and mavlink ovverride control ... instead to use mavproxy we implemented a custom application in java for reduce the latency and control the activation of the stream on the drone ... the result is very good on pc ... and we are working on android platform for integration in vr pad station of gstreamer lib for video and optimizing the mavlink control over ip .. 

  • @Cap,  considering the baud rate of the typical serial connection, there should not be a measurable latency that is significant to the telemetry transmission rate.  This is true whether you use MaxProxy or Ser2Net.   I am using Ser2Net, which has been patched to use UDP.  You can use TCP, but if you experience any drops in the wireless link, then you will notice latency until the stream catches up.  The problem with using TCP is that packets get queued between lost connections. If you have a significant drop period, it could be many seconds of latency. 

    I don't see any performance reason to pick either Ser2Net or MavProxy.  It's a matter of preference on what you want to support. 

This reply was deleted.