Arduino to Pass Receiver Signal to Pixhawk

So… I’m trying to build a thermal imaging quadcopter as a project. I’ve built acro quads using well tested configurations before, but never something entirely custom. I have assembled the quadcopter portion and it’s been in the air a couple of times, but just for fun. I’ve got Arduino’s laying around. I’m using a Pixhawk Px4 - 2.4.8. I was wondering if I might be able to route the PWM signal from the receiver through an Arduino that is handling the thermal imaging… Then pass it on to the Pixhawk FC? The idea being that I wish to have the quad automatically fly a predetermined route while scanning for thermal anomalies. If it finds a thermal anomaly I’d like to have it override the mission, hover and observe for a moment. If the event seems notable it should return to home and raise the alarm over the Bluetooth link it should have with the ground station. I’m hoping to have this be a routine flight that can be performed without any human intervention. The goal is that I’ll be able to entirely eliminate the receiver and have the Arduino sending PWM signals based on the various sensors inputs. I just thought it best to include it for testing purposes so that I can manually override if things get hairy…

If anybody has any recommendations whatsoever, or any links to any relevant information, I’d be eternally grateful. I’m not entirely sure where to go now that I’ve gotten the easy part out of the way.
Thankyou for taking the time. <3

That sounds like a good idea with terrible implementation.

Don’t intercept the PWM signals. Rather, construct a simple serial message protocol to send over UART.

Read the serial stream with a Lua script onboard the autopilot and act accordingly (like set LOITER mode for whatever timeframe is desired, then back to AUTO).

1 Like

I will try this! I’ve figured out how to read data from the pixhawk using the arduino… But I’m unsure of how I might add a script to the pixhawk. I’m rather inexperienced with coding of any kind. I’ll do some more research and keep this updated!

I’ve looked into this a bit more and refreshed what little information I had on LUA scripting. Now I’m simply trying to get the heartbeat of my Pixhawk using the Arduino so I can confirm that they’re communicating. I’m using the Arduino MAVLink library, and a very basic program that came as an example in the library. All bitrates are synced up, and the output I’m getting is gibberish.

#include <MAVLink.h>


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

void loop() {
  // Send HEARTBEAT message to Serial once a second
  mavlink_message_t msg;
  uint8_t buf[MAVLINK_MAX_PACKET_LEN];

  mavlink_msg_heartbeat_pack(1, MAV_COMP_ID_AUTOPILOT1, &msg, MAV_TYPE_QUADROTOR, MAV_AUTOPILOT_GENERIC, MAV_MODE_FLAG_MANUAL_INPUT_ENABLED, 0, MAV_STATE_STANDBY);
  uint16_t len = mavlink_msg_to_send_buffer(buf, &msg);

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

and the output I’m getting in the serial monitor is this:

I’m not entirely sure that I can confirm that this is a heartbeat and that the Arduino and Pixhawk are communicating.
Weird Update - I can inject words into the output using all of the same code except adding a “serial.write()” at the end of the loop… That prints just fine, but none of the information that should be coming through from the Pixhawk does.
image

You don’t need MavLink for this. Seems like massive overkill. Create your own protocol with a few bytes of whatever info you want to pass. Use a scripted serial port. Parse the data in Lua and use the available bindings to change flight modes. Done.

Mavlink doesn’t use ASCII format: Serialization · MAVLink Developer Guide