Receive data in Mission Planner form companion computer

Hello,

I want to send data from an Arduino to Mission Planner.
To do so I have written this code and connected the rx/tx port of the Arduino to the Telem2 port of my Pixhawk flight controller.
In Mission Planner I configured the following options for the telem2 port (see images).



I’m trying to send dummy data from the Arduino with this code:

#include "mavlink.h"
// RAW DATA SEND
// Pixhawk System ID und Component ID
const uint8_t pixhawk_sysid = 1;      // Set your Pixhawk's System ID
const uint8_t pixhawk_compid = 1;     // Set your Pixhawk's Component ID

void setup() {
  Serial.begin(115200);  // Kommunikation über den seriellen Monitor 
}

void loop() {
  sendRawPressureData();
  delay(1000);  // Nachricht alle 1 Sekunde senden 
}

void sendRawPressureData() {
  mavlink_message_t msg;

  uint64_t time_usec = micros();
  int16_t press_abs = 1000;
  int16_t press_diff1 = 500;
  int16_t press_diff2 = 300;
  int16_t temperature = 250;

  // Packen der RAW_PRESSURE-MAVLink-Nachricht
  mavlink_msg_raw_pressure_pack(pixhawk_sysid, pixhawk_compid, &msg, time_usec, press_abs, press_diff1, press_diff2, temperature);

  // Senden der MAVLink-Nachricht über die serielle Schnittstelle
  uint8_t buf[MAVLINK_MAX_PACKET_LEN];
  uint16_t len = mavlink_msg_to_send_buffer(buf, &msg);
  Serial.write(buf, len);

  // Debug-Ausgabe auf dem seriellen Monitor
  Serial.println("Nachricht gesendet.");
}

I would be very thankful for further instructions and help to complete this!
BTW is this the right way to do this?
Thanks

You’re sending a packet to the pixhawk, claiming you are the pixhawk.
You should use your own pixhawk_compid.

Then you could use Mavlink Inspector (find it using Ctrl + F menu on MissionPlanner) to see the messages.

1 Like

Thanks for your reply!
I think you mean this part?

 uint8_t _system_id = 255; // id of computer which is sending the command (ground control software has id of 255)
  uint8_t _component_id = 2; // seems like it can be any # except the number of what Pixhawk sys_id is
  uint8_t _target_system = 1; // Id # of Pixhawk (should be 1)
  uint8_t _target_component = 0; // Target component, 0 = all (seems to work with 0 or 1

Each mavlink component has its own compid + sysid combination.
Sometimes you need to specify who is the sender, and sometimes who is the receiver of messages.

When using mavlink_msg_raw_pressure_pack(), as far as I can see from the libraries, the first two parameters are “this” ids, meaning your companion computer’s ids (should not be the same as your Ardupilot).

1 Like

Thanks again for your help, I have received the messages!!

Hi, I am doing a project somehow like this project. I want to do it exactly with ComponentID=1, I am adding a new mavlink messageID=188,
Although I modified ap_message.h in pixhawk source code, my data is not appeared in mission planner. in mavlink inspector, my custom_data isn’t shown.
However, by setting ComponentID=191, I is added. Can you help me please?