Peripheral Hardware Interfacing

I am looking at incorporating two peripheral devices into my system, an altimeter and scaling lasers.
Browsing through the forum, I have found a few similar topics with some ideas for implementation, but I haven’t seen much for specific details. I will separate out the two items below and see if I have it straight for what is needed for each.

Altimeter: Using a Tritech micron sounder. All I am looking for is the number displayed, but no system control from it (though an alarm would be nice)
I have seen some others using this @jwalser . As I understand it ardusub will take this in as a range finder, and display in the main HUD. What is the best/easiest method for incorporating the RS232 output into the system? USB to serial into RPi, RS232 shifter into Pixhawk serial/GPS input? Then what is needed to read the message in the data string?

Scaling laser: Using a Outland Technology Laser system.
I believe all that I will need to control this is a Relay/MOSFET activated from one of the PixHawk output (Main or Aux?) and map a controller button to turn it off/on. Am I missing anything on that?

1 Like

We need a program to read the data from the altimeter and then pass it to the autopilot.

The simplest approach would be to connect the altimeter to the Pi, and have a python script to parse the altimeter data, then pack it into the MAVLink DISTANCE_SENSOR message and pass it to the autopilot via mavproxy which is already running on the raspberry pi.

The relay/button sounds like a fine way to control a laser.

Should be simple enough to get the RS232 to 3.3V TTL for the Pi.
However software is not my forte. I can work my way through some C code, arduino programming and BASH scripting, but not much work with Python. Would you happen to have any sample code that you could share, to get me pointed in the right direction?
Again, thanks.

I’ve added an explicit example at the bottom of the pymavlink examples. I’ve also added a brief intro on the usage of altimeters in ArduSub here.

1 Like

Jacob @jwalser ,
Thanks for the help.

Sorry for my ignorance (this is my first time dealing with mavlink).
Currently for initial testing, I am trying to get it to display a static value what I assign in the .py file before adding reading the serial value.
I have set ardusub to RNGFND-TYPE MAVLink in setup>parameters and restarted the system.

I am using putty to ssh into the pi and running “python”

# Import mavutil
from pymavlink import mavutil

# Import serial to access Altimeter
import serial

# Import time to query system time.
import time

# Open Serial Terminal, 9600,8,N,1 with 1s timeout.
# This is to connect to Altimeter
ser = serial.Serial('/dev/ttyUSB0')

# Create the connection, Default connection for companion computer
#master = mavutil.mavlink_connection('udp:')
# This endpoint is created with the 
# '--out udpin:localhost:9000' option with MAVProxy
master = mavutil.mavlink_connection('udpout:localhost:9000')

# Wait a heartbeat before sending commands
#x =
#line = ser.readLine()

# Set Message Parameters
# Configure the autopilot to use mavlink rangefinder, the autopilot
# will need to be rebooted after this to use the updated setting
    10, # "MAVLink"

# Replace min and max values.  Default they were 10 and 40, respectively
min = 0 # minimum valid measurement that the autopilot should use 
max = 100000 # maximum valid measurement that the autopilot should use
#distance = ser.readLine() # You will need to supply the distance measurement
type = mavutil.mavlink.MAV_DISTANCE_SENSOR_UNKNOWN
id = 1
orientation = mavutil.mavlink.MAV_SENSOR_ROTATION_PITCH_270 # downward facing
covariance = 0

tstart = time.time()

while True:
    #Read from Serial Device
    distance = 56   #ser.readLine()
    #Pack Msg and Send
        (time.time() - tstart) * 1000,
    #Sleep before reading Serial Port again

Before running this command, do I need to run “ --udpout:localhost:9000”?
Is there anything else I am missing on this?
Thanks again.

Forgot to mention, I currently have a USB to RS232 adapter connected directly to the RPi.
The output format

Baudrate is 9600
8 bits
no parity or flow control
1 stop bit

Before running this command, do I need to run “ --udpout:localhost:9000”?

Not if you are using our Raspberry Pi image. Mavproxy is run with this option at boot.

Check for the current options.

I just tried looking into and nothing shows up.
I can at least see the pages on or /routing.
I am running the version that was shipped about 2 weeks ago (QGround Control Version: v3.2.4-BlueRobotics-Rev4.

I have tried running the above python script with master = mavutil.mavlink_connection(‘udp:’)
but it states that it cannot create the connection.

This is the ip address of the surface computer, you cannot bind an ip that isn’t yours.

I just tried looking into and nothing shows up.

You need to update the raspberry pi software at

I am trying to connect the Rpi so that I can update the companion software. does not show any networks to connect to, but I was able to configure it by SSH command line.
However it still does not give me any options on the /system page for download. I can see where to upload manually, but I thought I remember that I need to use the Blue robotics version and not the one from ardusub, correct?

I thought I remember that I need to use the Blue robotics version and not the one from ardusub, correct?

I think you are mixing up the different software involved in the system.

You can choose this file for the upload update.

Thanks. You are correct, I was thinking that ardusub had branches separate from BlueRobotics. My mistake

It looks like the issues I was having with accessing the companion web interface was due to using IE (at least the version installed with Win7. Chrome works much better.

Hi Ryan,

For what it is worth, I am just mounting waterproof scaling lasers with standalone power. I don’t know if this suits you, but it saves a bit of work.

These are rated to 100m.


Thanks Pete.
I have actually used those exact lasers on a separate project. The main issue I have had with those in the past, is keeping them parallel. I ended up 3d printing a braket using Tech-G and tapping some adjustment screws directly into it.
Incorporating the MOSFET circuit to activate the lasers with a button push was pretty straightforward.

Jacob @jwalser,
The script is working well now, as it the companion web interface.
We found that the script was hanging up while waiting for the heartbeat. Once that line was commented out it ran as expected. What would be the main concern about not waiting for the heartbeat, or any ideas as to why it would hang there?

The reason is that the link on port 9000 is one-directional input-only (the mavproxy option being used here is --out udpin). This means messages from the autopilot including heartbeats are never forwarded to your program.

If you want bi-directional communication, use udpout or just udp.

Hi all
I have almost the same task, an ultrasonic sensor for sending distance measurements to QGC.
And thanks to all of you, and @jwalser … I start with some things to study already !

As far as I understand, @RyanC 's problem was not the rpi image he used, but the “waiting for a heardbeat” python code.

I am facing something else… since I’m using the latest companion image from GitHub - bluerobotics/companion: Companion computer startup scripts and examples I have no communication with nor .
I cannot also telnet to 9000, but the same time I can connect via ssh and run the code at the bottom of Pymavlink · GitBook line by line as a test with no errors.
Is there something missing from the companion system os I am missing smt here ?
thanks in advance

Did you create an sd card according to the instructions here?

Yes, those are the instructions I followed. Used Etcher to burn the image, set ip’s accordingly and ssh to to run the python code.

But looking at the Software Components and comparing to the testing system I use:

  • I have a RPi companion with the proper image
  • Qgroundcontrol on a pc (with proper ip addresses and ssh connection between those two)
  • there is no pixhawk in here (I don’t have one … only testing the code to see distance on qgc)

so is the lack of pixhawk causing problems or I should see anyway ?

I am really new to mavlink and ardusub, so forgive any “newbieness” in the above :slight_smile: