Being able to connect to PX4 via Serial is essential for development. It allows you to run individual apps in PX4 and it provides a straight forward interface for debugging. I have successfully connected to a HK Pilot 32 using a FTDI breakout adapter in Ubuntu, and here is how I did it.
A quick summary:
- Connect FTDI cable and USB cable
- Install putty, launch and configure
- Run some applications
1. Connect FTDI cable
PX4 serial connection works a bit different than Ardupilot. If you connect your Pixhawk to the computer via a micro USB cable, you will only see gibberish in the console. The correct way is to use the serial port on Pixhawk and connect to the computer via a FTDI cable. A FTDI cable is something like this:
The breakout adapter is the same as the cable, except you need to bring your own micro USB cable to connect it to the computer. The tricky part is to get the pin out match correctly.For the serial connection you only need three wires, the RX, TX and GND.
The complete setup is shown below.
The official guide can be found here: PX4 serial connection
So far I have only successfully connected a Pixhawk/HK Pilot 32 to Ubuntu. I haven’t found a way to connect a Pixfalcon to the console, as there is no serial port.
Update: it turns out you can connect to serial via micro USB cable if you remove the micro SD card.
2. Install putty, launch and configure
There are many serial console applications on Ubuntu (e.g. screen, minicom, piocom etc.). Putty is the preferred application in UAB lab. To install putty, open a terminal window, and type:
sudo apt-get install putty
If it is installed correctly, launch putty by using the command (use the sudo prefix to make sure you have access to all the ports):
sudo putty
Now you should see a window like this:
The key configurations here are connection type and serial line as circled in red. For connection type choose Serial. The serial line is usually /dev/ttyUSB0 or /dev/ttyACM0 on Linux. If you want to check which one is it you can type “ls /dev/tty*” in the terminal before and after you plug in the cable, and see which one has changed. You can save your session by clicking the save below so you don’t have to configure every time you launch putty.
Now click open at the bottom to start the session. You should see a new window with title “/dev/ttyXXXX – PuTTY”.
3. Run some applications
To check if your connection is established successfully, type “help” into the PuTTY console. If you see something like the screen shot below, congratulations! You can also play around some of the Builtin Apps from help, such as “tone_alarm” and “rgbled”.
hi,Zi hao
If I dont have a FTDI adapater, can I connect the Pixhawk with its initial USB in the putty?
Hi Mao
I assume you mean using the micro-usb cable and the micro-usb port on the Pixhawk to establish serial connection,
The good news is yes you can, you just need to take the SD card out and connect to ttyACM0 (the port on Ubuntu).
the bad news is I couldn’t get it to work normally, the console just prints gibberish for whatever the baud rate I have tired. But the strange thing is, if you take the SD card out and connect to ttyACM0 (that’s the Pixhawk usb port on Ubuntu) again, it will work. But obviously there will be other problems with the SD card not installed.
I highly recommend you to get a FTDI cable adapter, they are really cheap and reliable.
Hello Mao/ Zi hao,
I didn’t have an FTDI cable so tried connecting to nsh over MAVLink. It works. Not sure if this helps you in any way but here is the link
http://dev.px4.io/advanced-system-console.html
Hi Ayesha
Thanks for the info. I shall add this method to my blog once I have verified it is working on my system.
Hi zihao,
Have you found a way to get the debug prints from the PX4 codebase without using the hardware serial port ?
I am trying to get some prints using NSH over MAVLink. No luck so far.
Might really help if you have an idea.
guys if i use the open source pcb design and print a Pixhawk Newly
how do i upload the firmware ?
My board is not getting detected via usb
please help me out
You probably have to install the bootloaders and the entire nuttx system for it to work. We have never tried that, though.
Thanks. I used Dronecode probe (http://nicadrone.com/index.php?id_category=12&controller=category) and both the procedures on https://dev.px4.io/advanced-system-console.html and your procedure worked for me. The only problem I faced was that I had to find the correct serial port. I typed ls /dev/tty* before and after plugging the usb and saw the difference. The new change, ttyACM1 was my usb port.
Hi Zihao! Your tutorials are very helpful!
I’m having a problem with this step though. I only get the gibberish when connecting with the FTDI. With or without the SD card. Any idea what the problem is?
thanks for what you share,it is realy helpful.
and recentely
i found that there is a way using the micro-usb cable and the micro-usb port on the Pixhawk to establish serial connection,but you do not have to take the sd card out.
console command:
cd /Firmware/Tools
./mavlink_shell.py /dev/ttyACM0
push enter
That’s wonderful, thanks for sharing!