What i am trying to achieve is to have the Mega transmit mavlink commands to the TELEM1 port of the Pixhawk autopilot. Using the Mega as a ground station.

I have a code that appears to be working.
Inspecting the packets that i am sending with qGroundControl i get the following output :

vUSGpb3.png
(some of the params on heartbeat packet have been changed since the picture was taken).

I have connected the Mega to TELEM1 of Pixhawk as shown in the picture bellow

rFzQi1J.png

What i am trying to do with the resistors is a voltage divider because the Pixhawk is 3.3v for TX, RX but the Mega outputs 5V.

I have measured the voltage of TX0 on the Mega and it's 3.2 - 3.3 V with the circuit i have above.
But when sending data i do not see any significant drop to the voltage, it will drop to something like 3V from 3.2V. So i believe i am doing something wrong. How can the Pixhawk know when we have a logical 0 or 1 if the difference is only 0.2 Volts?

I am using the following code to test the connection.



#include "mavlink.h"
#define bRate 115200


void setup() {
 
  Serial.begin(bRate);
}

void loop() {

 command_heartbeat();
 command_waypoint();
}

void command_heartbeat() {

  int sysid = 1;                  
  int compid = MAV_COMP_ID_MISSIONPLANNER;    
 
  uint8_t system_type = MAV_TYPE_GCS;
  uint8_t autopilot_type = MAV_AUTOPILOT_INVALID;
 
  uint8_t system_mode = 0;
  uint32_t custom_mode = 0;                
  uint8_t system_state = 0;


  mavlink_message_t msg;
  uint8_t buf[MAVLINK_MAX_PACKET_LEN];
 

  mavlink_msg_heartbeat_pack(sysid,compid, &msg, system_type, autopilot_type, system_mode, custom_mode, system_state);
 
  uint16_t len = mavlink_msg_to_send_buffer(buf, &msg);
 
  delay(1000);
  Serial.write(buf, len);
}

void command_waypoint() {

  uint8_t _target_system = 1; // Target drone id
  uint8_t _target_component = 0; // Target component, 0 = all

  uint16_t seq = 0; // Sequence is always set to 0
  uint8_t frame = MAV_FRAME_GLOBAL; // Set target frame to global default
  uint16_t command = MAV_CMD_NAV_WAYPOINT;
  uint8_t current = 2; // Guided mode waypoint
  uint8_t autocontinue = 0; // Always 0
  float param1 = 0; // Loiter time
  float param2 = 1; // Acceptable range from target - radius in meters
  float param3 = 0; // Pass through waypoint
  float param4 = 0; // Desired yaw angle
  float x = 52.464217; // Latitude - degrees
  float y = -1.280222; // Longitude - degrees
  float z = 200; // Altitude - meters

  mavlink_message_t msg;
  uint8_t buf[MAVLINK_MAX_PACKET_LEN];

  mavlink_msg_mission_item_pack(1,1, &msg, _target_system, _target_component, seq, frame, command, current, autocontinue, param1, param2, param3, param4, x, y, z);

  uint16_t len = mavlink_msg_to_send_buffer(buf, &msg);

  delay(1000);
  Serial.write(buf, len);
}


Running this code i do not see any changes to the Pixhawk, the rotors do not start to spin, reading the waypoints from the pixhawk using mission planner does not show the waypoint i am trying to send.

I am unsure as to what the drone id should be.

Both the Pixhawk and the Mega are powered by their usb connected to a computer.

Any help would be greatly appreciated. Thank you for your time.

You need to be a member of diydrones to add comments!

Join diydrones

Email me when people reply –

Activity