Trouble connecting RaspberryPi 3 with Pixhawk

I’ having troubles to connect the Raspi3 to the Pixhawk via python script.
I used this manual:

If i connect via terminal as shown in the manuel everythig is more or less working: --master=/dev/ttyS0 --baudrate 57600 --aircraft multi

But when i try to write ja .py-script and connect with the following lines, it doesnt work:

connection_string       = 'udp:'
# Parse connection argument
parser = argparse.ArgumentParser()
parser.add_argument("--connect", default="")
args = parser.parse_args()

# Connect to the Vehicle
print "Connecting to vehicle on: %s" % args.connect
#vehicle = connect(args.connect, baud=57600, wait_ready=True)
vehicle = connect (args.connect, wait_ready = True, baud = 57600)

In the Terminal i cal the script with the follwing command.
# python --connect=/dev/ttyS0

This is the respond
Connecting to vehicle on: /dev/ttyS0
Sometimes there is the 5 seconds time out… depending on if an set “Wait_ready on True”

I’m trying around a lot, but couldn’t make it work …
Any ideas?

Hi, couple of things:

thank you for the quick response.
I Tried to deactivate BT(added:enable_uart=1; dtoverlay=pi3-disable-bt) before but not together with disable the flow control (BRD_SER2_RTSCTS=0). That Info was new to me! Thank you very much.

This is my new Response:

 $ python --connect=/dev/ttyAMA0
Connecting to vehicle on: /dev/ttyAMA0
>>> Link timeout, no heartbeat in last 5 seconds
>>> restored.
>>> PreArm: Throttle below Failsafe

At a second try I turned on the radio as well to get rid of the Throttle Failsafe.

Then the Response was:

$ python --connect=/dev/ttyAMA0
Connecting to vehicle on: /dev/ttyAMA0
>>> EKF2 IMU0 Origin set to GPS
>>> EKF2 IMU1 Origin set to GPS
>>> EKF2 IMU0 is using GPS
>>> EKF2 IMU1 is using GPS

But nothing happens after that. :-/
So then I discovered that core_freq=250 was in the config.txt as well and deleted that.

Now the Output is:
$ python --connect=/dev/ttyAMA0
Connecting to vehicle on: /dev/ttyAMA0
>>> Link timeout, no heartbeat in last 5 seconds
>>> …link restored.

Nothing happens after that. But it should. The Script should give me a few parameters:

print " Type: %s" % vehicle._vehicle_type
print " Acrmed: %s" % vehicle.armed
print " System status: %s" % vehicle.system_status.state
print " GPS: %s" % vehicle.gps_0
print " Alt: %s" % vehicle.location.global_relative_frame.alt

I also tried to change ttyAMA0 to serial0.

Kind a frustrating … something else I might have missed?

OK well that’s kind of encouraging - you’re getting data back from the flight controller. I suspect it’s timing out downloading the params, a problem I’ve hit many times. Try setting wait_ready to False and trying again.
I gave up with dronekit as I found it too unreliable and resource heavy.

Hi Fnoop,
actually settings the timing to false did work… Thought I tried that before.

My current output is:
$ python --connect=/dev/ttyAMA0
Connecting to vehicle on: /dev/ttyAMA0
>>> APM:Copter V3.5.5 (27229c83)
>>> PX4: 0384802e NuttX: 1bcae90b
>>> Frame: QUAD
>>> PX4v2 003A001F 31334702 38383835
Type: 2
Acrmed: False
System status: STANDBY
GPS: GPSInfo:fix=3,num_sat=5
Alt: 2.01

So nice, thank you very much!
What do you mean you give up on DroneKit? Do you have a proper alternative? I Want to use the Raspberry to control the drone. e.g. Object avoidence, but more advanced than pixhawk.

I use ROS/MAVROS now. It’s a bit of a pain to set up, but more reliable and much less resource intensive once you get going.

All right, i will look into that as well. Any recommantations?
Because today in the field i was not able to connect Raspi und Pixhawk. Kind of annoying-
Thank you very much again.

Sorry I have to reopen it…i thought it worked, but it doesnt. I am able to make a connection via terminal, but cant give any commands to pixhawk … see code Below:

> root@raspberrypi:/home/pi# --master=/dev/serial0 --baudrate 57600 --out --aircraft Copter
> Connect /dev/serial0 source_system=255
> Running script (/root/.mavinit.scr)
> Running script /root/.mavinit.scr
> -> module load droneapi.module.api
> Failed to load module: No module named google.protobuf.internal. Use 'set moddebug 3' in the MAVProxy console to enable traceback
> -> module load droneapi.module.api
> Failed to load module: No module named google.protobuf.internal. Use 'set moddebug 3' in the MAVProxy console to enable traceback
> -> module load droneapi.module.api
> Failed to load module: No module named google.protobuf.internal. Use 'set moddebug 3' in the MAVProxy console to enable traceback
> no script /mavinit.scr
> Log Directory: Copter/logs/2018-03-20/flight6
> Telemetry log: Copter/logs/2018-03-20/flight6/flight.tlog
> MAV> Waiting for heartbeat from /dev/serial0
> online system 1
> mode
> mode Stabilize
> STABILIZE> mode Loiter
> STABILIZE> arm throttle

Also i can connect with MissionPlanner, but cant load Parameter List … really Weird…!

Then i decided to reinstall everything … which was a step back. no i get the following error:

Traceback (most recent call last):
  File "/usr/local/bin/", line 12, in <module>
    import serial, Queue, select
ImportError: No module named 'Queue'

i googled around and found out that i need: sudo apt-get install python-serial
Turns out i already have it on the raspberry.
So next i found was to change Queue to queue.
But then i get this:

Traceback (most recent call last):
  File "/usr/local/bin/", line 989, in <module>
    mpstate.logqueue = Queue.Queue()
NameError: name 'Queue' is not defined

So changing that brought me to some other issues, so can’t be the real issues, can it?

Any idea what I can do?

Thanks again

You absolutely shouldn’t be hacking, so change back whatever you changed (or just reinstall it).

That’s really wierd. Make sure you don’t have a file called getting in the way somewhere, otherwise your python install is borked.

yeah i know. I was just trying around to find the mistake.
i don’t think there is a anywhere.How do i know if there is a file in my way?

Strangely it was working before reinstalling…
is there any way to delete “python” from the raspberry? Because it seems like i have multiple versions of python on the system

If you have a in the directory that you’re trying to run your script from, it might try and import it as the Queue module which will then fail. To check if your python Queue is still available, do:
dpkg -S
which will probably return something like:
libpython2.7-stdlib:amd64: /usr/lib/python2.7/
(except will say something like armhf instead of amd64)
Make sure that file still exists.
Also make sure you’re not trying to run mavproxy with python3 - Queue doesn’t exist in python3, it was renamed as queue. Mavproxy tries to use /usr/bin/python as the interpreter which should be python2:

ls -l /usr/bin/python
lrwxrwxrwx 1 root root 9 Nov 24 00:52 /usr/bin/python -> python2.7

Thank you for your reply:
I am getting the following:

$ dpkg -S
python3-pygame: /usr/lib/python3/dist-packages/pygame/threads/
pypy-lib:armhf: /usr/lib/pypy/lib-python/2.7/
python-pygame: /usr/lib/python2.7/dist-packages/pygame/threads/
libpython2.7-stdlib:armhf: /usr/lib/python2.7/

And in /usr/lib/python2.7 there is a “”.

So i trief if MavProxy wants to run Python2:
$ ls -l /usr/bin/python
lrwxrwxrwx 1 root root 9 Jan 24 2017 /usr/bin/python -> python2.7

i run the script from /home/pi and in the whole pi directory there is no file “” -.-

Could be a physical problem.

Could also be a mavlink1 vs mavlink2 issue.

Try tacking --mav10 to the mavproxy commandline. If that doesn’t work,
try --mav20 :slight_smile:

Which OS are you using? Does this work with the latest Raspbian (Stretch)?

@fnoop Could you please post the link to the instructions for installing ROS/MAVROS? Thanks!!

However the one major bug the last raspberry image had was broken mavros. The stated ‘supported’ ROS version for debian stretch is supposed to be lunar, but mavros doesn’t work with lunar on raspbian stretch (, so going back to kinetic does work despite it not being the officially stated version.
I’m compiling a new version of maverick at the moment to fix this, should be released today or tomorrow.

1 Like

@fnoop Thanks!! Could you also post the link to the new version of maverick as soon as it is released?

Also, I had a question regarding the original topic: Connecting Raspberry Pi and Pixhawk with Mavlink. I pretty much did everything I could find on this ardupilot forum but I am still getting the dreaded “Waiting for heartbeat” output. Would it be possible for you to compile a short checklist for getting this running? Which OS should I be using (currently on Raspbian Stretch)?

@Dhruva_Bansal - I’ve uploaded new versions of Maverick for the raspberry (1.1.6) that have working ros/mavros now.

I did the same thing on my Mac. I updated the libraries and now I get this Queue error. Did you resolve it?

Hello Hello i wanted you help for /EZ-WifiBroadcast if you spare 5 minutes :frowning:

How can I contact you ?