What does float adc_voltage_v[10]; mean? Where would I apply these changes?

Working on Nuttx code for Pixhawk to transfer data from ADC 3.3 channel to the logging files. I found someone who accomplished this a few years ago, but I’m not sure what some changes do or if they are still applicable.

First one can be found in sensor_combined.h
float adc_voltage_v[10];

In his explanation, he changes it from float adc_voltage_v[4]; to float adc_voltage_v[8]; which “allows the adc_voltage array to be filled with this extra information during the sensor polling routine.” The current version has “10” in the value. Does that mean I don’t need to made this modification.

The second change is in sensors.cpp and " is the counterpart to increasing the size of the adc_volatge
array. This change is located at the interface between the ADC driver and the Pixhawk’s polling
routines, and it ensures that the signal from all eight channels will be accessible to other

if (i <= (sizeof(raw.adc_voltage_v)) / sizeof(raw.adc_voltage_v[0])) {

I don’t know what this is supposed to do or where the change needs to be made.

Out of curiosity, are you wanting to log every ADC channel or some specific ones?

I’m wanting to log two channels from the 3.3V ADC port. That should be pins 12 and 13 on the Pixhawk.

Okay awesome. Fair warning, my hardware is Pixhawk V2. Also I’m not sure how the ADC is read in sensor sensor_combined.h but I can demonstrate to you how to read those ADC channels if you are interested.

In one of my projects I have an IR sensor that outputs analog voltage and is connected to pin 2 of the 3.3V ADC port (which is ADC channel 14). The code is in my fork of the firmware repository here from lines 151-197.

My code talks to the ADC driver using the DevMgr class from DevMgr.hpp. My code is based off of modules/sensors/sensors.cpp

The ADC driver samples the pins and puts the conversions into a buffer of adc_msg_s structs. My code reads 10 values from the buffer, and then uses only the messages where am_channel corresponds to channel 14, or pin 2 of the ADC port (the driver returns adc messages from all of the ADC channels, so you have to filter them for the channel that you want).

You could read the adc messages this way, and then just keep the messages from channel 12 and 13. Once you have read the data, you can then set it up to be logged on the SD card (thats another step, which I’m note sure how to do).

I hope that helps!

There is a simpler way to do this. You can subscribe to the adc_report topic and just take the analog data from there. Tutorial how to create an app and subscribe to a topic: http://dev.px4.io/tutorial-hello-sky.html

1 Like

Oh, cool! That’s a neat addition. Thanks!

I can understand adc_report will contain the data for the pins, but I’m not sure where the subscribe to it or how to pull the data from pins 13 and 14 specifically. Do I just need to add the subscription to the sdlog2 file? If so, what is the code that stores the values for the pins?

Please look at the definition of the topic (tip: you will find that in Firmware/msg/adc_report) how to identify the pins.