How to use ADC port to read a generic analog sensor

Hello guys! Can someone help me with a question?

I want connect a potentiometer in the adc port of the pixhawk CubeBlack. The data that I want to get is position data. So, I connected the potentiometer in a cable and connected it to the ADC3,3V port. But, how do I use this port to get position data instead of airspeed? IN Mission Planner only have option airspeed.

For example, I put a cable with a load, when this load swings it will move the potentiometer that is connected to the ADC 3,3V port CubeBlack. But how do I use this port to get position data instead of airspeed.

Thank you in advance!!

Use lua scripting to do that

After connecting potentiometer in the ADC port, I entered Mission Planner, went to setup and airspeed it had found - pin: Pixhawk analog AS port , Type: Analog, as see below:

This is correct?

How Lua scripting input here? Can you explain more?

https://ardupilot.org/copter/docs/common-lua-scripts.html

Lua scripting will allow you to read the ADC input, process it and do whatever you want with it.

All right, so I don’t need enable to airspeed? I don’t need to use it?

No, you do not. :slight_smile: Lua in enough

Oh, ok thank you. I was thinking about changing airspeed code.

Because the sampling time is very small, always 4 samples per second. And I want as many samples as possible to get as close to a continuous curve.

Thank you, @amilcarlucas!

I recall others using the analog fuel level function with the battery monitor to read a generic analog voltage. You can scale it with the available parameters. You can use RSSI input also.

On most H7 autopilots, you can get a script to update around 100Hz.

RSSI input is this?

Sorry for the silly question, I’m still learning about hardware and electronic.

…

RSSI
Fuel Level

Thank you very much!!

Thanks, @Yuri_Rage for your reply!

@amilcarlucas in this link: https://discuss.ardupilot.org/t/reading-adc15-value/60290/4? @iampete says it isn’t possible to read ADC in lua.

How to get around this? Do you (or @Yuri_Rage and @dkemxr ) have annathor alternative using ADC port? (@dkemxr provided the possibility RSSI input but yet wanted to try ADC port)
Can python read the ADC port and store the data in the log?

Then use the Analog Fuel level scheme.

Ok, right! Thanks for your support!

ADC now works in lua, that post is 3 years old.

See:

3 Likes