Home        Store        Learn        Blog

Reading Pixhawk's pins

hey guys ! Is there any way that we can read the pixhawk’s aux pin datas? Thanks.

Hi @ugurdemirezen,

What do you mean by this?

Our RC Outputs documentation discusses how the BRD_PWM_COUNT parameter can be used to change the AUX pin modes. By default AUX pins 1-4 are allocated as servo outputs, and AUX 5-6 are allocated as GPIO, so can be used for controlling relays or as digital input (e.g. pin 6 is by default the leak detector input).

As far as I’m aware, pins assigned as GPIO can only be read by relevant modules within the firmware, so if you need to access their values for some functionality then you’ll need to implement that functionality within a customised version of ArduSub. There’s a general example in the ArduPilot forum for the kind of file and code you could make for specifying a GPIO pin as an input, and reading its value.

1 Like

Thanks for your help Eliot.

I want to get the leak data from pixhawk’s aux pin if any there is any leakage with pymavlink.

I have arm, disarm, temperature, gain and recording datas with different ways. I will write a post about them soon.

Right. I don’t believe the pin value is provided by MAVLink. If you’ve got the leak failsafe set to “warn only” (the default) then your system should be notified of leaks by the STATUSTEXT message, e.g.

from pymavlink import mavutil

# connect to the vehicle from the surface computer
vehicle = mavutil.mavlink_connection('udpin:')
# wait for connection to be established/confirmed

while "program running":
    message = vehicle.recv_match(blocking=True)
    if message.name == 'STATUSTEXT' and message.text == 'Leak Detected':
    ... # otherwise, do other things
1 Like

Hi Eliot thanks a lot. I couldn’t try it yet but it will work for me.

Hi again,

My code is going like that. But it is not working because of the code in quotes. But I am controlling the heartbeat with that so I have to use all together. How can I fix that ?

while True:
        "message = master.recv_match(type="HEARTBEAT", blocking=True, timeout=3)"
        if message is not None:
                message2 = master.recv_match(blocking=True)
                if message .name == 'STATUSTEXT' or message .text == 'Leak Detected':


You can wait for multiple message types at once, e.g.

useful_types = ("HEARTBEAT", "STATUSTEXT")

while "waiting for messages":
    message = master.recv_match(type=useful_types, blocking=True, timeout=3)
    if message is None:
        # no messages of interest detected within timeout, including heartbeat
        print("Heartbeat lost!")
    elif message.name == "STATUSTEXT" and message.text == "Leak Detected":

By the way, I’ve edited your comment to include a code block, so it’s easier to read/understand. You can read about how to make them in the Formatting a Post/Comment section of the “How to Use the Forums” post :slight_smile: