Pixhawk read analog source ADC 6.6V

Hello to all members,
I am currently working on ArduPlane 3.6.0 code in order to read an analog voltage across Pixhawk’s virtual pin 15 (in ADC 6.6 Volt port). To do this, i followed the example provided in the AP_HAL -> AnalogIn.cpp to get the voltage average across this pin. Following this sketch, i had a few lines of code to the original ArduPlane v3.6.0.
The code lines that i added are the following:
In file Plane.h, between lines 379 and 388 (between receiver RSSI and Graound Speed) i add this:
float tracao_value;
AP_HAL::AnalogSource* tracao_analog_source;
where “tracao_value” is the voltage value that i want to read across ADC 6.6V port.
In file “ArduPlane.cpp” between lines 100 and 105 (at the bottom of the void Plane::setup) i add this:
tracao_analog_source = hal.analogin->channel(15);
In file Sensors.cpp between lines 126 and 131 (inside read_battery loop) i add this:
tracao_value = tracao_analog_source->voltage_average();
I then compile the code using make on windows (px4 console) and the compilation process runs succesfully without compile erros. However, when i upload the firmware onto the Pixhawk, the main led initializes, blinks yellow and then stops blinking. Furthermore, i when try to connect to mavlink, it wont connect.
Could this problem be related to the pointer AP_HAL::AnalogSource?
Could anyone please help me.
Thanks so much in advance

1 Like

do you find any solution I have same problem :frowning:

Hi there Hamid,

Finally i solved the problem. After an insane brainstroming i found that this code is correct. My problem was that i was compiling ArduPlane using Windows 10 using make with px4 toolchain. Then i decided to try Ubuntu. I installed a Virtual Box in my machine, compiled the same code (the one that is on my post) using make and then i uploaded the firmware onto pixhawk. Voilá… Problem solved :smiley:

Hope this is helpfull :smiley:

thanks a lot :grinning:
i upgrade my linux and problem solved :laughing:

Glad to hear it Hamid :smiley:

Sorry, I have another question about reading an analog voltage. I just want to ask that if I can link a potentionmeter directly to the adc 6.6 Volt pot?