Reading the pixhawk gpio and Adc inputs in pymavlink/ in python

Hello, I am trying to read the voltage from a custom made battery indicator . I need to read the voltage applied to the pixhawk using software and turn that voltage into readable bits. Is there a way to read the Pixhawk gpio, ADC3.3, ADC6.6 inputs through pymavlink or generally using python/any other programming language.
I appreciate your response. Thanks.

Hi @VioletCheese,

Assuming this is taking the place of our Power Sense Module, you most likely want to use the power module connector, where pins 3 and 4 can be used for voltage/current measurement (also called virtual pin 2 and 3, with positions in the connector shown here). Note the measured voltage for each pin is max 3.3V, so your custom indicator needs to output voltages in the valid range or you can damage the Pixhawk.

You can set up the monitor type and any custom scaling factors/offset on the Power Setup Page in QGroundControl (or directly using the BATT parameters, but it’s easier through QGC), after which the battery voltage (and current, if you’re measuring it) readings are available in the SYS_STATUS or BATTERY_STATUS MAVLink messages.

I don’t believe ArduSub has support for sending the GPIO pins or ADC values directly via MAVLink, and if that’s correct then the only way to achieve this would be to make a modified version of ArduSub that sends those values in a suitable message.

For what it’s worth, I tried requesting the AP_ADC message but got a MAV_RESULT_FAILED acknowledgement, and since there was nothing pending/wrong at the time I assume that’s just not supported in ArduSub (at least in version 4.0.3, which is the only one I tried).