Sensor data output to Teensy (or arduino)

I have been looking around the web a bit and keeping hitting a wall. I want to take the live data form the Pixhawk and output it to a Teensy 3.2.

I just want to have the AHRS and Coordinates sent to the Teensy, but I do not know where to begin. Has anyone done this or can you guide me to a starting point?

Thanks!

Your best beat world be to pull it off the serial port over mavlink.

So Pixhawk Serial 4/5 to the Teensy? Then use mavlink?

I have been looking at this

Is this the right track?

Yeah thats about right.

Okay so I got some things figured out. I spent a good bit just figuring out how to compile the MAVLink Arduino example code. Couldn’t figure out how to compile for the Teensy so I’m just gonna stick with the Arduino Mega for now.

Tomorrow I plan on hooking it up to the Pixhawk and reading the heartbeat message. What I haven’t figured out yet is how to read the info from the sensors. The link I posted from earlier is missing too much for comfort.

Right now I have the generic example code from ArduinoMAVLink. Where would I add something like:

case MAVLINK_MSG_ID_VFR_HUD:
{
  mavlink_vfr_hud_t packet;
  mavlink_msg_vfr_hud_decode(msg, &packet);
  heading = packet.heading;
  break;
}

to read the heading?

This is some code I wrote a few weeks ago to read some data off the serial and send it over I2C for a project I was doing.

https://gist.github.com/FLYBYME/acdf66fbd3179b7e03f323f1fa61a341

AHHHH! I see!

Thanks! I’ll try to implement my version tomorrow and I’ll let you know if I get it to work!

Thanks again!!

I actually have another question.

I cannot compile with the mavlink header unless I use FastSerial. Additionally, I cannot compile on the most recent arduino IDE and I have to use 1.0.6.

How did you get around this? Do I have outdated MAVLink libraries?

Edit: I must have the following headers

#include <FastSerial.h>
#include "../mavlink/include/mavlink.h"        // Mavlink interface

I dont know whats up with the mavlink lib. I suspect they use an old version of the IDE. This is my lib that I used. mavlink.zip (333.9 KB)

THAT IS AWESOME!!!

You have no idea how long I looked around the web to get this thing to compile!! I got your code to compile for both the mega and Teensy. The Teensy had some warnings but I can find a way to get around that.

Now I’ll try to write it on my own and reference yours so i can learn more (:

Hopefully this is my last question for a while. When I use the physical hardware, should I connect the I2C from the Pixhawk to the I2C on the Teensy or Arduino?

No just do serial, telem1 or telem2. The I2C was specific to my code and what I was doing. It was sending telemetry to my RC receiver.

Gotcha! I will let you know how it goes tomorrow. Thanks again! This was extremely helpful!

Wanted to let you know I got it to work. Thanks again for all your help!

Yeah no problem. What are you using the code for?

I have another vehicle that navigates based on vision and I wanted to use the Pixhawk to give it outdoor navigation capabilities but I do not want the Pixhawk to be in charge so I have to feed all the info to the current computer on the vehicle so it can make decisions. If that all makes sense.

I got stuck again with extracting some data -.-

I was trying to extract some navigation data (cross track error, distance to waypoint, bearing to waypoint, etc).

I was able to get the stuff from MAVLINK_MSG_ID_NAV_CONTROLLER_OUTPUT just fine using your code as an example.

I later tried to extract additional information:

    case MAVLINK_MSG_ID_POSITION_TARGET_GLOBAL_INT: {
      streamData.lat_target = mavlink_msg_position_target_global_int_get_lat_int(&msg)/1e7;
      streamData.lon_target = mavlink_msg_position_target_global_int_get_lon_int(&msg)/1e7;
      Serial.println(streamData.lat_target);
      Serial.println(streamData.lon_target);
      break;
    }

    case MAVLINK_MSG_ID_POSITION_TARGET_LOCAL_NED: {
      streamData.x_target = mavlink_msg_position_target_local_ned_get_x(&msg);
      streamData.y_target = mavlink_msg_position_target_local_ned_get_y(&msg);
      Serial.println(streamData.x_target);
      Serial.println(streamData.y_target);
      break;
    }

But nothing prints for those cases. Do you know why it’s not printing (why it’s not entering the case)? I have the vehicle in AUTO mode and I can get waypoint distance and bearing updates. I just can’t extract the waypoint location.