Simple relay control PX4

Hi guys, happy to join the community!
I’m pretty new in px4 so you have to bear me if I have some basic doubts. The question is, how can I activate a relay with pixhawk? Or better, which are the rows I’ve to add in the code (for example in px4_simple_app) in order to activate a relay on the main port 1 of pixhawk?
Thank you very much in advance

You could use one of the AUX ports (if a pixhawk) and control it as a regular GPIO.

1 Like

Thank you for the answer dagar,

Yes it is a Pixhawk

in order to control the relay as a GPIO should I include the following library to my sketch?
#include “gpio.h”
if yes, I tried but it gives me error. Same error with:
#include <src/drivers/camera_trigger/interfaces/src/gpio.h>

Moreover, is it sufficient to add the following rows to my script if I want to activate the relay to port AUX 1? Something missing?

#ifdef __PX4_NUTTX
#include <src/drivers/camera_trigger/interfaces/src/gpio.h>
constexpr uint32_t CameraInterfaceGPIO::_gpios[6];

_p_polarity = param_find(“TRIG_POLARITY”);
param_get(_p_polarity, &_polarity);




void CameraInterfaceGPIO::setup()
px4_arch_gpiowrite(_gpios[_pins[1]], !_polarity);

Thank you very much

Hello Michele,

Have you already found a solution that works?