# Reading Pixhawk's pins

**URL:** https://discuss.bluerobotics.com/t/reading-pixhawks-pins/11334
**Category:** General Discussion
**Created:** [January 13, 2022, 8:28am UTC](https://discuss.bluerobotics.com/t/reading-pixhawks-pins/11334 "2022-01-13T08:28:53Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![ugurdemirezen](https://avatars.discourse-cdn.com/v4/letter/u/9de053/32.png) [@ugurdemirezen](https://discuss.bluerobotics.com/u/ugurdemirezen)
#### Post date: [January 13, 2022, 8:28am UTC](https://discuss.bluerobotics.com/t/reading-pixhawks-pins/11334/1 "2022-01-13T08:28:53Z")

</div>

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

---

<div class="post-metadata">

### Author: ![EliotBR](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/eliotbr/32/6937_2.png) [@EliotBR](https://discuss.bluerobotics.com/u/EliotBR)
#### Post date: [January 14, 2022, 4:27am UTC](https://discuss.bluerobotics.com/t/reading-pixhawks-pins/11334/2 "2022-01-14T04:27:54Z")

</div>

Hi @ugurdemirezen,

> [@ugurdemirezen](#):
>
> Is there any way that we can read the pixhawk’s aux pin datas?

What do you mean by this?

Our [RC Outputs documentation](https://www.ardusub.com/developers/rc-input-and-output.html#rc-outputs) 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](https://discuss.ardupilot.org/t/solved-how-to-get-input-signal-from-aux-channels/26281) for the kind of file and code you could make for specifying a GPIO pin as an input, and reading its value.

---

<div class="post-metadata">

### Author: ![ugurdemirezen](https://avatars.discourse-cdn.com/v4/letter/u/9de053/32.png) [@ugurdemirezen](https://discuss.bluerobotics.com/u/ugurdemirezen)
#### Post date: [January 14, 2022, 7:25pm UTC](https://discuss.bluerobotics.com/t/reading-pixhawks-pins/11334/3 "2022-01-14T19:25:13Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![EliotBR](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/eliotbr/32/6937_2.png) [@EliotBR](https://discuss.bluerobotics.com/u/EliotBR)
#### Post date: [January 17, 2022, 2:09am UTC](https://discuss.bluerobotics.com/t/reading-pixhawks-pins/11334/4 "2022-01-17T02:09:14Z")

</div>

> [@ugurdemirezen](#):
>
> I want to get the leak data from pixhawk’s aux pin if any there is any leakage with pymavlink.

Right. I don’t believe the pin value is provided by MAVLink. If you’ve got the [leak failsafe](https://www.ardusub.com/reference/ardusub/safety-setup-page.html) set to “warn only” (the default) then your system should be notified of leaks by the `STATUSTEXT` message, e.g.

```python
from pymavlink import mavutil

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

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

---

<div class="post-metadata">

### Author: ![ugurdemirezen](https://avatars.discourse-cdn.com/v4/letter/u/9de053/32.png) [@ugurdemirezen](https://discuss.bluerobotics.com/u/ugurdemirezen)
#### Post date: [January 21, 2022, 4:57pm UTC](https://discuss.bluerobotics.com/t/reading-pixhawks-pins/11334/5 "2022-01-21T16:57:28Z")

</div>

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

---

<div class="post-metadata">

### Author: ![ugurdemirezen](https://avatars.discourse-cdn.com/v4/letter/u/9de053/32.png) [@ugurdemirezen](https://discuss.bluerobotics.com/u/ugurdemirezen)
#### Post date: [January 26, 2022, 12:24pm UTC](https://discuss.bluerobotics.com/t/reading-pixhawks-pins/11334/6 "2022-01-26T12:24:08Z")

</div>

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 ?

```python
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':
                     print("LEAK!!")
...

```

Thanks!

---

<div class="post-metadata">

### Author: ![EliotBR](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/eliotbr/32/6937_2.png) [@EliotBR](https://discuss.bluerobotics.com/u/EliotBR)
#### Post date: [January 26, 2022, 8:39pm UTC](https://discuss.bluerobotics.com/t/reading-pixhawks-pins/11334/7 "2022-01-26T20:39:16Z")

</div>

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

```python
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":
        print("LEAK!!")
    ...

```

* * *

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](https://discuss.bluerobotics.com/t/how-to-use-the-blue-robotics-forums-please-read/10521#formatting-a-postcomment-15) section of the “How to Use the Forums” post 🙂
