Skip to main content

ADC

ADC example

In this example, ADC continuously measures voltage on all six channels available on Navio2. The first two channels are responsible for board voltage and servo rail voltage. Channels 2 and 3 show voltage and current levels in the POWER connector respectively. The last two channels are present in ADC connector.

Download Navio2 drivers and examples code here.

C++

note

If you have not build the examples yet, perform the following commands:

cd C++
make

To check the ADC example, you need to run this command:

cd Build
./ADC

Python

Move to the folder with the source code and run the example:

cd Python
python ADC.py

The program performs measurement of all six ADC channels and outputs measured values in volts in six columns. When channels inputs are not connected to anything, there would probably be a little bit of potential.

A0: 4.7480V A1: 0.0860V A2: 0.0240V A3: 0.0200V A4: 0.0300V A5: 0.0140V 
A0: 4.7980V A1: 0.0860V A2: 0.0140V A3: 0.0220V A4: 0.0080V A5: 0.0160V
A0: 4.7940V A1: 0.0860V A2: 0.0100V A3: 0.0100V A4: 0.0300V A5: 0.0140V
A0: 4.7980V A1: 0.1040V A2: 0.0100V A3: 0.0200V A4: 0.0080V A5: 0.0300V
A0: 4.7960V A1: 0.0900V A2: 0.0220V A3: 0.0080V A4: 0.0300V A5: 0.0140V
A0: 4.7960V A1: 0.0860V A2: 0.0100V A3: 0.0220V A4: 0.0080V A5: 0.0320V

Mapping between A0 - A5 and ADC:

  • A0 - board voltage (shows 5V)
  • A1 - servo rail voltage
  • A2 - power module voltage (ADC0, POWER port)
  • A3 - power module current (ADC1, POWER port)
  • A4 - ADC2 (ADC port)
  • A5 - ADC3 (ADC port)

Numbers of A0 - A5 channels correspond to ArduPilot's ADC channels.

The real values of power module voltage and current could be calculated by multiplying to the respective coefficients. The multiplier for voltage (A2) is 11.3. Coefficient for current (A3) is 17.0.

note

The coefficient for current above is offered as a recommended value. The relationship between current and voltage is not linear, and the coefficient will vary with the hardware setup. Please verify it following your hardware setup.

For further information, see source code.

tip

Pay attention to adc.init() and adc.read() functions. adc.init() function initialize six ADC channels. After that, it is possible to read value of channels 0-5 with adc.read() function. It takes channel number as an argument.