Servers by jDrones

How to connect Arduino and Pixhawk together?

(Rjiun RK) #8

you can cut the middle of a telemetry cable and join it with male jumper to connect with arduino.

(stevenette) #9

Ok, I took a break and managed to get absolutely everything working on my boat except the sonar. Apparently the 9600 baud rate of NMEA output is way too slow for pixhawk and would jam everything up. I guess I will still have to go with the pixhawk for navigation, and the arduino for data logging. Please let me know if I am wrong. Thank you!

(rmackay9) #10

Hi Steve,

By the way, which sonar are you using? It seems like a number of people want a sonar connected to their boat so perhaps I/we should write a driver and document the setup on the wiki.

(stevenette) #11

No way!!! You rock my world! I am using (As many other forum users are as well) the airmar DT800 transducer outputting NMEA0183 data. I have gotten it to work on arduino, but then that means I need an arduino board. In addition, the signals are inverted, so I need a serial inverter as well. This requires valuable space and energy on my boat. If there is any way to help, please let me know! The link is here
Airmar DT800 (plastic, not bronze)

(rmackay9) #12


I guess this is a guide for how it can be connected to an Arduino and a similar hardware setup could work with the Pixhawk (or other flight controller).

The 9600 baud rate is very low but that won’t slow down the Pixhawk at all because we do the reads in the background. The SERIALx_BAUD would just need to be set to 9600 I think.

The issue is just that we’d need a new RangeFinder driver that understands NMEA. this NMEA decoding guide describes what messages the DST-800 is outputting:

VWVLW - distance travelled through water
YXMTW - mean temperature of water
SDDPT - depth of water
SDDBT - depth below transducer

So it is probably these last two that are most important.

Writing a driver (and more importantly debugging it) is a little tricky without one on my desk… I know someone at Garmin so I might ping him to see if he can get me one.

(rmackay9) #13


There’s another person who coincidentally wants to connect a NMEA based sonar as well. The other chat is here and at the bottom you’ll see some instructions for a firmware I wrote today that may work with a NMEA sonar.

If you do decide to give it a go, please be careful because it’s mostly untested. It should be safe but it’s hard to be sure. I should be getting a NMEA sonar next week from so I’ll be able to test it myself then. So no pressure!

(stevenette) #14

Hi there,

This is great! Thank you for looking in to this! I actually commented back in August on that first link you sent. The weird thing was that the inverter never worked for me. It worked fine for the GPS I was using, but then started messing everything up once I plugged in the transducer. I also had to plug everything in the exact order I described, or else it also wouldn’t work. It was super super super finicky, and only worked one out of maybe 5 times I power cycled it. Below is the comment if it helps with the pixhawk?

I have a DT800, the RS485 converter that was linked, and an arduino Uno. I hooked up everything to a GPS I have and a serial line was being printed no problem, then trying to hook up to the transducer, and nada. A combination of pulling cables here and inserting cables there, I got lines to finally display, here is what I had to do.

A <=> NMEA+
B <=> NMEA- AND my TX pin of the arduino!
VCC <=> 5V
gnd <=> ground
RO <=> RX pin of arduino
RE <=> Grnd of arduino

Now this initially didn’t work, UNTIL, I unplugged the ground from the ground terminal on the RS485 leaving the RE ground connected. Then serial lines started displaying


I have to plug them in and unplug them in the right order, or else I don’t get anything. If I just hook up the RX and TX to NMEA+ and - respectively, I only get MTW and DBT, but not DPT…No idea why. So confused. Maybe there is a capacitor on there that needs to be charged up, then the ground needs to be taken away?

I will be busy house sitting this week, but if I can find some time before you get your transducer in the mail, I will let you know! Cheers!

(Xenopoulos) #15

Dear ppoirier
I’m facing a similar problem: I must connect a Pixhawk flight controller of a hexa, to an ARDUINO NANO collecting signals from several sensors. The measurements mast be available inside the MP. The hexa is controlled through python scripting inside the MP. Can you please explain in more details, how are you “spoofing” existing drivers to communicate with the Pixhawk either using Telem2, either using I2C? Are there commands for MAVLINK to communicate with serial or I2C? The sentences to be read from ARDUINO are in the form: "1001,41.139234,24.912345,67.25,12,14, …;”?
Thanking you in advance.

(ppoirier) #16

Hello, I suggest you start a new discussion explaining in detail what you are planning to do, this way we will be able to better help. You can post in other hardware

(Xenopoulos) #17

Dear ppoirier, I have already done it here:

Thank you very much for your interest!

(David Ardis) #18

I have been doing something similar with a boat. My approach was was to connect the Pixhawk to the Arduino Mega using Serial.
The Arduino reads the Mavlink messages sent from the Pixhawk and extracts the latitude,longitude,Date, Time and mode.
The sonar has a CAN connection and is connected to the Arduino Mega through a sparkfun CAN Shield.
In the software on the Mega all this data is combined and saved to an SD Card on Sparkfun Shield.

I would have liked to see the depth in mission planner but havn’t figured that out yet.

(rmackay9) #19

related to this, We’ve recently added a DPTH message into the dataflash log so that we record the lat, lon and depth of a downward facing echosounder. This change is included in Rover-3.4.1-rc1.

The key requirements for this to be recorded are:

  • echosounder needs to be connected to the pixhawk (wiki)
  • RNGFND_ORIENT should be set to 25 (pointing down)
  • the vehicle must be a boat (FRAME_CLASS = 2)

Viewing the depth in real-time on the ground station (i.e. mission planner or equivalent) is possible with Rover-3.4 (and earlier even). If using the MP’s “Quick” or “Status” tab (found on bottom left of the Flight Data screen) select “sonarrange”. I tested this last week with the ECT400 echosounder and it seemed to work OK.

(David Ardis) #20

Randy thanks again looks like I will need to do a CAN to serial conversion and feed it back through the serial port as nmea sentence.

(rmackay9) #21


That sounds OK. A more direct approach would be to write a CAN driver but I’m not qualified to do that yet. If the arduino can send mavlink then sending a DISTANCE_SENSOR message would also work because we have a “MAVLink” rangefinder driver.

(Project Orrca) #22

Slightly more complicated and scary sounding solution but - have you tried ROS? ROS uses wrappers to make literally anything compatible with anything. All you need its (1) a computer/PC running Ubuntu of some sort - and ROS installed. Then you can USB both the ardupilot and the arduino into the PC and use ROS to load the data to your Parameter Server, or an ROS Topic, then Ardupilot can take data from anything connected to the PC and then the PC can send control commands to the robot? Just something to look into

(stevenette) #23

Hey there,

I finally got around to setting this entire boat up. I have everything plugged in exactly as you said above, in addition to the parameters listed on the wiki. I have the boat in 0.75m column of water, and can hear the sonar pinging. The only difference I have is that I am using an Airmar DT800 sonar instead of an ECT 400 sonar. I believe the default baud rate for mine is 4800, but I have also tried 115200 and everything in between. I have also swapped the 2 and 3 pins on the serial input side.

Still the sonar range and voltage read 0. Is there something different that should be done for the airmar sonar vs the ect sonar? They both communicate over NMEA 0183.

I am using rover 3.4.0 and mission planner 1.3.56. In addition, rngfnd_type 17 does not exist on the side menu, it stops at 16. Is this an issue at all? I shouldn’t need to change rngfnd_offsets, or scaling right?

Are there any other details I could possibly give to assist? I feel I am so so so close to finally having this project complete, but just one more hurdle.

Thank you!

(stevenette) #24

A thought: I wonder if my voltages are different using the Sparkfun Serial to TTL converter. When I had the DT 800 working with my arduino Mega, I was converting it using a Max 3232 sparkfun board. I can’t find my wiring diagram currently, but that seemed to work. When I got it working on an Uno, I didn’t need any coverter, and plugged the signal cables directly to the digital ports on the Uno, then inverted them using the Uno.

(rmackay9) #25


It’s definitely important that the RNGFND_TYPE is set to “17” (remember to reboot the board after changing this). Without this set, the wrong driver will be loaded and it will use the wrong protocol to try and communicate with the device. if “17” is missing then it is a ground station issue I’m afraid. If using the MP, the parameter descriptions can be updated by going to the flight data screen, pressing Ctrl F, push the “Param gen” button, wait a few minutes then restart the MP.

It’s possible that there is some other issue causing the driver not to work. Maybe if you can grab a sample of the text that the sonar is outputting I can see if our driver should consume it OK…

P.S. it’s really great that you’re giving this a try! I’m pretty sure we can get it working

(Connor Manning) #26

I have been looking at all the questions and answers and i have some clue on what your saying but i do not fully know what some of the answers are so if I could have some help to have a better understanding what to do.
i am working in a team to build an autonomous sail boat using the Arduino and Pixhawk and other components i would like to know some more on what is the best way to do this if there is anyone out there that knows what is the best way to do it i would be thankful for it
many thanks

(Victor Augusto) #27

Could you make the connection between pixhawk and arduino? if so, could you help me with a project similar to yours, except that it is an aeromodelism plane.