Read ADC and GPIO17/18 into Python script while APM running


I have built a drone using the Navio2 where I have a potentiometer connected to ADC (A4) and an encoder connected to GPIO 17/18 (the free pins) in the UART connector. I have made a python script from the ADC example where I am reading these potentiometer and encoder values and moving servos accordingly.

Now I want to be able to run this script while I’m flying the drone but I get the “APM is running. Can’t launch the example” error.

Ultimately I want my pot/encoder/servo script to be a part of the whole code which controls the drone with Dronekit but can move servos based on the pot/encoder values.

Are these pins blocked by the Arducopter thread like the sensors?

What is the best way to accomplish this?

Ok, I removed the navio.util.check_apm() from my pot/encoder code and it seems to be working fine and running alongside the APM.

Is there any harm in this? How does the threading work with the APM, Does it run on it’s own dedicated thread and if I run my code in another thread it would be fine? How does that work?

All help appriciated :slight_smile:

Usually this is not recommended. In your very specific use case it won’t hurt, though. Because this ADC channel is unused in ArduPilot. The same applies to the GPIO pins. The right approach would be to get ADC information from telemetry with either ROS or dronekit and then drive pins with a logic similar to a logic that is used for shutter.

I’m very interested what is done with GPIOs. Could you please elaborate on this one? Couldn’t you just control servos using PWM?