You've got your flight computer set up. Chosen between PX4 and ArduPilot. But now... you need to connect a companion computer to do advanced control.
Thankfully, this process is straightforward!
Find it easier to watch a video for tutorials? Hit play below:
Since this tutorial covers BOTH Raspberry Pi and NVIDIA Jetson Nano, I'll show you how to connect to each individually.
Look out for these boxes:
Raspberry Pi
NVIDIA Jetson Nano
For the Jetson Nano, I'm using the A203 Carrier board provided by Seeed Studio 👍 You can find a link to that here.
By this end of this tutorial, you will have MAVLink messages arriving over the serial port. I'll be showing you how to setup MAVProxy to recieve and display these.
Creating a Connection CableSerial is the name of the game. To make the physical connection, you'll need to build a serial to 6-pin connector cable.
If you're not using a PixHawk, you'll need to adjust how you create this cable to match your hardware's serial port. Check its schematics for more information.
In the pack of wires that came with your PixHawk, there should be a 6-pin connector. It looks like this:
With the red wire on the left, the pinout is as follows:
- Wire 1 (Red) = 5V
- Wire 2 = TX (out)
- Wire 3 = RX (in)
- Wire 4 = CTS (Clear to Send)
- Wire 5 = RTS (Request to Send)
- Wire 6 = Ground (GND)
Cut all 6 wires close to one side of the connector. These will be spliced into later.
Next, remove wires 4 and 5, as well as the 5V wire.
We do not require the control flow pins, and I'm assuming you're powering the companion computer from an external source.
Take your 3 female jumper wires, and choose which you will splice into the remaining wires of the 6-pin connector. Make a note of this - it will be useful later.
Mine are coloured, so I chose:
- Purple for TX
- Blue for RX
- Black for Ground (GND)
Like for the 6-pin connector, cut each of the jumper wires close to one plug.
Next, we need to strip the ends of all the cut wires. I used a craft knife to carefully slice through the plastic insulation, and then was able to pull off a small section exposing metal.
Once all wires are stripped, we can splice them together.
I started with Ground - as a reminder, this is wire 6 and the black jumper wire. My preferred approach is to twist the exposed wires together, and then solder them.
Finally, cover each soldered joint with heatshrink.
Done!
Now that we have our cable, we can move on to connecting devices up!
Let's start with the PixHawk. Take the serial cable, and plug it into the port marked TELEM2. This port exposes a serial interface for a MAVLink connection in software.
Connecting to the companion computer is done via the GPIO header, which exposes a serial port.
The key thing to remember is that the RX connection on the PixHawk goes to theTXGPIO, and the same for TX which goes to theRXGPIO.
Grab your notes from earlier for jumper wire colours.
Raspberry Pi
The connections are as follows:
- Ground (black) to GPIO 9 (GND)
- 6-pin TX (purple) to GPIO 10 (RX)
- 6-pin RX (blue) to GPIO 8 (TX)
NVIDIA Jetson Nano
If you're not using the A203 carrier board, make sure your board is in this orientation:
This diagram then shows how to connect the serial cable:
The connections are the same as the Raspberry Pi:
- Ground (black) to GPIO 9 (GND)
- 6-pin TX (purple) to GPIO 10 (RX)
- 6-pin RX (blue) to GPIO 8 (TX)
To make sure everything is working, we'll be using MAVProxy to check that we can send/receive MAVLink messages over the serial port.
Power on your companion computer. I used SSH to connect over WiFi to a terminal session, but you can run all of these commands on-device with a keyboard and monitor.
I'm assuming you've already gone ahead and done any initial setup of your chosen OS; for example, network connectivity.
Raspberry Pi
Before we can install MAVProxy, you'll need to change some settings relating to the serial port.
You'll need to open up raspi-config:
sudo raspi-config
This will bring up a keyboard-based UI like so:
Navigate to InterfaceOptions with the arrow keys, and hit Enter.
Then, select SerialPort:
Select No for the login shell:
And Yes for the serial port hardware:
Hit Enter on the final prompt, which will take you back to the main menu.
Navigate to the Finish button using the tab key, and hit Enter once more to exit.
If your Raspberry Pi has built-in Bluetooth hardware, you will need to disable it. To do that, open up /boot/config.txt:
sudo nano /boot/config.txt
And add the following:
enable_uart=1
dtoverlay=disable-bt
Here's what the file should look like:
Hit CTRL + O then CTRL + X to save and exit.
Now, go for a reboot!
sudo reboot
Once your Raspberry Pi is back online, make sure to do a:
sudo apt-get update
(I didn't do this and apt tried to download an old package no longer available on the remote repo 🙄)
MAVProxy is available via pip, make sure that's installed via:
sudo apt-get install python3-pip
Next, its the dependencies for MAVProxy:
sudo apt-get install python3-dev python3-opencv python3-wxgtk4.0 python3-matplotlib python3-lxml libxml2-dev libxslt-dev
Finally, install MAVProxy (and PyYAML):
sudo pip install PyYAML mavproxy
I'm installing MAVProxy via sudo to ensure that it is placed into /usr/local/bin. This makes it a lot easier to start it on boot via systemd later on. You can find more info on that here.
At this point, you're ready to run it! The serial device associated with the GPIO header is /dev/ttyAMA0, which you'll need to pass to MAVProxy like so:
sudo mavproxy.py --master=/dev/ttyAMA0
You should now start to see MAVLink messages coming through:
NVIDIA Jetson Nano
The process for the NVIDIA Jetson Nano is shorter than for Raspberry Pi - there's no hardware options to configure!
Start off with:
sudo apt-get update
Then, install pip for Python package management - MAVProxy is available from here:
sudo apt-get install python3-pip
Next its the dependencies for MAVProxy:
sudo apt-get install python3-dev python3-opencv python3-wxgtk4.0 python3-matplotlib python3-lxml libxml2-dev libxslt-dev
Finally, install MAVProxy (and PyYAML):
sudo pip install PyYAML mavproxy
Again, I'm using sudo to install MAVProxy to /usr/local/bin for usage with systemd later on.
... and we're ready to roll! For the Jetson Nano, the serial device associated with the GPIO is /dev/ttyTHS1, which we'll pass to MAVProxy like so:
sudo mavproxy.py --master=/dev/ttyTHS1
Provided all went well, you should now get MAVLink messages appearing!
By this point, you should now have a working serial connection to build your application upon.
I pulled together this information whilst building my own custom AI drone, Stanley!
Looking where to go next? Have a look at these links from ArduPilot and PX4:
https://ardupilot.org/copter/docs/initial-setup.html
https://docs.px4.io/v1.12/en/flight_controller/
Happy aerial hacking!
TroubleshootingSome tips for if things aren't working properly:
- Are the TX and RX wires connected to their inverse on the companion computer? e.g., TX wire to the RX GPIO pin
- Is each wire spliced with a good solder connection?
- Have you got all the dependencies for MAVProxy installed? If not, double check them on the project's page here.
Comments