Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v5x: add support for ADS1115 #19145

Merged
merged 3 commits into from
Feb 9, 2022
Merged

v5x: add support for ADS1115 #19145

merged 3 commits into from
Feb 9, 2022

Conversation

bkueng
Copy link
Member

@bkueng bkueng commented Feb 8, 2022

Allows to use an external ADC for battery sensing.

bkueng and others added 3 commits February 8, 2022 08:18
This is the case for boards with digital readout, like v5x, but still
enable the battery_status module for external analog driver options.

An alternative would be to not run battery_status depending on config.
@@ -2,7 +2,13 @@
#
# PX4 FMUv5X specific board sensors init
#------------------------------------------------------------------------------
board_adc start

if param compare -s ADC_ADS1115_EN 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ads1115 start via parameter could be done centrally in rc.sensors so other people could potentially use it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you want to move out the board_adc start as well?
I was considering handling multiple adc reports and then extend the battery source param for user selection.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like we can come back to this later for a more unified user configurable ADC solution.

I had some other analog things in mind I was thinking of exposing as standalone fully configurable drivers/modules like analog airspeed, angle of attack, etc.

@dagar
Copy link
Member

dagar commented Feb 8, 2022

We should do a pass later where we start battery_status per board or create some other mechanism. There are enough special cases that I don't think we should be doing it generally.

@dagar dagar merged commit b6607a7 into master Feb 9, 2022
@dagar dagar deleted the ads1115_param branch February 9, 2022 21:54
@AntonioAguilera
Copy link

hi I'm testing the analog input on holybro pixhawk 5x, I connected the analog battery voltage vbat 0-3.3 to AD input.

the parameters as follows:

nsh> param show BAT*
Symbols: x = used, + = saved, * = unsaved
x + BAT1_A_PER_V [2,27] : 17.0000
x BAT1_CAPACITY [3,28] : -1.0000
x BAT1_I_CHANNEL [4,30] : -1
x BAT1_N_CELLS [5,31] : 4
x BAT1_R_INTERNAL [6,32] : -1.0000
x BAT1_SOURCE [7,34] : 0
x BAT1_V_CHANNEL [8,35] : -1
x BAT1_V_CHARGED [9,36] : 4.0500
x + BAT1_V_DIV [10,37] : 5.6000
x BAT1_V_EMPTY [11,38] : 3.5000
x BAT1_V_LOAD_DROP [12,39] : 0.3000
x BAT2_A_PER_V [13,40] : -1.0000
x BAT2_CAPACITY [14,41] : -1.0000
x BAT2_I_CHANNEL [15,42] : -1
x BAT2_N_CELLS [16,43] : 0
x BAT2_R_INTERNAL [17,44] : -1.0000
x BAT2_SOURCE [18,45] : -1
x BAT2_V_CHANNEL [19,46] : -1
x BAT2_V_CHARGED [20,47] : 4.0500
x BAT2_V_DIV [21,48] : -1.0000
x BAT2_V_EMPTY [22,49] : 3.5000
x BAT2_V_LOAD_DROP [23,50] : 0.3000
x BATMON_DRIVER_EN [24,52] : 0
x BAT_CRIT_THR [25,54] : 0.0700
x BAT_EMERGEN_THR [26,55] : 0.0500
x BAT_LOW_THR [27,56] : 0.1500
x + BAT_N_CELLS [28,57] : 4
x BAT_V_CHARGED [29,58] : 4.0500
x BAT_V_EMPTY [30,59] : 3.5000
x BAT_V_LOAD_DROP [31,60] : 0.3000
x BAT_V_OFFS_CURR [32,61] : 0.0000
nsh> param show ADc*
Symbols: x = used, + = saved, * = unsaved
x ADC_ADS1115_EN [0,0] : 0
800/1951 parameters used.
nsh> ads1115 status
INFO [SPI_I2C] Not running
nsh> board_adc status
INFO [board_adc] running
nsh> board_adc test
DeviceID: -1
Resolution: 4096
Voltage Reference: 3.300000
0 : 2045 4 : 2043 8 : 2034 9 : 3077 10 : 2163 12 : 2050 13 : 3583 18 : 986
0 : 2042 4 : 2032 8 : 2036 9 : 3080 10 : 2154 12 : 2051 13 : 3583 18 : 987
0 : 2043 4 : 2068 8 : 2039 9 : 3089 10 : 2135 12 : 2059 13 : 3591 18 : 985
0 : 2044 4 : 2031 8 : 2036 9 : 3081 10 : 2153 12 : 2051 13 : 3570 18 : 986
0 : 2044 4 : 2031 8 : 2036 9 : 3079 10 : 1915 12 : 2050 13 : 2896 18 : 987
0 : 2043 4 : 2032 8 : 2037 9 : 3081 10 : 1765 12 : 2050 13 : 2430 18 : 986
0 : 2043 4 : 2047 8 : 2039 9 : 3076 10 : 1644 12 : 2054 13 : 2153 18 : 986
0 : 2044 4 : 2032 8 : 2036 9 : 3080 10 : 1583 12 : 2051 13 : 1894 18 : 985
0 : 2044 4 : 2031 8 : 2036 9 : 3081 10 : 1632 12 : 2051 13 : 2010 18 : 985
0 : 2043 4 : 2032 8 : 2037 9 : 3080 10 : 1659 12 : 2050 13 : 2069 18 : 986
0 : 2043 4 : 2032 8 : 2036 9 : 3081 10 : 1653 12 : 2051 13 : 2052 18 : 986
0 : 2044 4 : 2031 8 : 2036 9 : 3132 10 : 1414 12 : 2051 13 : 1220 18 : 985
0 : 2043 4 : 2031 8 : 2037 9 : 3124 10 : 1408 12 : 2050 13 : 1133 18 : 986
0 : 2042 4 : 2031 8 : 2035 9 : 3127 10 : 1390 12 : 2051 13 : 1007 18 : 987
0 : 2044 4 : 2031 8 : 2035 9 : 3076 10 : 1381 12 : 2050 13 : 949 18 : 987
0 : 2043 4 : 2031 8 : 2036 9 : 3083 10 : 1394 12 : 2052 13 : 953 18 : 986
0 : 2043 4 : 2031 8 : 2036 9 : 3082 10 : 1405 12 : 2050 13 : 951 18 : 987
0 : 2044 4 : 2043 8 : 2033 9 : 3052 10 : 1375 12 : 2048 13 : 931 18 : 986
0 : 2044 4 : 1997 8 : 2034 9 : 3086 10 : 1392 12 : 2046 13 : 953 18 : 987
0 : 2045 4 : 2068 8 : 2034 9 : 3078 10 : 1410 12 : 2054 13 : 949 18 : 987
ADC test successful.

I manually decreased the voltage input to the board and i see the vbat and i inputs decreasing (dont know if as expected but seems logical due to the fact one is 3.3 and the other 6.6) i see the input 10 and 13 going down but still no battery readings on qgroundcontrol.

So far I tested changing BAT1_V_CHANNEL to 13 and 10 with no evident results.

What im missing?

Thanks

@AntonioAguilera
Copy link

image

image

@vincentpoont2
Copy link
Member

Per @bkueng .
@AntonioAguilera can you enable ADC_ADS1115_EN and try again?

@AntonioAguilera
Copy link

DONE... same result

NuttShell (NSH) NuttX-10.2.0
nsh> param show BAT*
Symbols: x = used, + = saved, * = unsaved
x + BAT1_A_PER_V [2,27] : 17.0000
x BAT1_CAPACITY [3,28] : -1.0000
x BAT1_I_CHANNEL [4,30] : -1
x BAT1_N_CELLS [5,31] : 4
x BAT1_R_INTERNAL [6,32] : -1.0000
x BAT1_SOURCE [7,34] : 0
x BAT1_V_CHANNEL [8,35] : -1
x BAT1_V_CHARGED [9,36] : 4.0500
x + BAT1_V_DIV [10,37] : 5.6000
x BAT1_V_EMPTY [11,38] : 3.5000
x BAT1_V_LOAD_DROP [12,39] : 0.3000
x BAT2_A_PER_V [13,40] : -1.0000
x BAT2_CAPACITY [14,41] : -1.0000
x BAT2_I_CHANNEL [15,42] : -1
x BAT2_N_CELLS [16,43] : 0
x BAT2_R_INTERNAL [17,44] : -1.0000
x BAT2_SOURCE [18,45] : -1
x BAT2_V_CHANNEL [19,46] : -1
x BAT2_V_CHARGED [20,47] : 4.0500
x BAT2_V_DIV [21,48] : -1.0000
x BAT2_V_EMPTY [22,49] : 3.5000
x BAT2_V_LOAD_DROP [23,50] : 0.3000
x BATMON_DRIVER_EN [24,52] : 0
x BAT_CRIT_THR [25,54] : 0.0700
x BAT_EMERGEN_THR [26,55] : 0.0500
x BAT_LOW_THR [27,56] : 0.1500
x + BAT_N_CELLS [28,57] : 8193
x BAT_V_CHARGED [29,58] : 4.0500
x BAT_V_EMPTY [30,59] : 3.5000
x BAT_V_LOAD_DROP [31,60] : 0.3000
x BAT_V_OFFS_CURR [32,61] : 0.0000

797/1951 parameters used.
nsh> param show ADC*
Symbols: x = used, + = saved, * = unsaved
x + ADC_ADS1115_EN [0,0] : 1

797/1951 parameters used.
nsh> ads1115 status
INFO [SPI_I2C] Not running
nsh> board_adc test
nsh> board_adc status
INFO [board_adc] not running
nsh> board_adc start
nsh> board_adc status
INFO [board_adc] running
nsh> board_adc test
DeviceID: -1
Resolution: 4096
Voltage Reference: 3.300000
0 : 2042 4 : 2011 8 : 2038 9 : 3070 10 : 1612 12 : 2054 13 : 1567 18 : 963
0 : 2043 4 : 2031 8 : 2035 9 : 3069 10 : 1638 12 : 2049 13 : 1575 18 : 963
0 : 2043 4 : 2031 8 : 2035 9 : 3069 10 : 1650 12 : 2050 13 : 1575 18 : 964
0 : 2043 4 : 2031 8 : 2035 9 : 3069 10 : 1641 12 : 2050 13 : 1572 18 : 964
0 : 2043 4 : 2031 8 : 2035 9 : 3070 10 : 1676 12 : 2050 13 : 1683 18 : 963
0 : 2042 4 : 2031 8 : 2035 9 : 3068 10 : 1821 12 : 2050 13 : 2139 18 : 963
0 : 2042 4 : 2031 8 : 2034 9 : 3069 10 : 1915 12 : 2050 13 : 2468 18 : 964
0 : 2043 4 : 2031 8 : 2035 9 : 3068 10 : 1951 12 : 2050 13 : 2645 18 : 964
0 : 2042 4 : 2031 8 : 2035 9 : 3067 10 : 1983 12 : 2050 13 : 2786 18 : 964
0 : 2044 4 : 2043 8 : 2036 9 : 3069 10 : 2161 12 : 2054 13 : 3443 18 : 964
0 : 2043 4 : 2031 8 : 2035 9 : 3069 10 : 2267 12 : 2050 13 : 3688 18 : 964
0 : 2042 4 : 2031 8 : 2035 9 : 3068 10 : 2252 12 : 2050 13 : 3678 18 : 965
0 : 2043 4 : 2032 8 : 2035 9 : 3070 10 : 2244 12 : 2050 13 : 3679 18 : 963
0 : 2043 4 : 2031 8 : 2035 9 : 3067 10 : 2243 12 : 2051 13 : 3683 18 : 963
0 : 2042 4 : 2031 8 : 2035 9 : 3068 10 : 2239 12 : 2050 13 : 3681 18 : 965
0 : 2043 4 : 2031 8 : 2035 9 : 3070 10 : 2242 12 : 2050 13 : 3681 18 : 965
0 : 2043 4 : 2031 8 : 2035 9 : 3070 10 : 2231 12 : 2049 13 : 3683 18 : 965
0 : 2042 4 : 2031 8 : 2035 9 : 3070 10 : 2235 12 : 2050 13 : 3683 18 : 965
0 : 2045 4 : 2032 8 : 2035 9 : 3067 10 : 2233 12 : 2050 13 : 3683 18 : 964
0 : 2045 4 : 2032 8 : 2036 9 : 3068 10 : 2220 12 : 2050 13 : 3679 18 : 964
ADC test successful.
nsh>

@AntonioAguilera
Copy link

image

Is working now...

NuttShell (NSH) NuttX-10.2.0
nsh> param show BAT*
Symbols: x = used, + = saved, * = unsaved
x + BAT1_A_PER_V [2,27] : 17.0000
x BAT1_CAPACITY [3,28] : -1.0000
x + BAT1_I_CHANNEL [4,30] : 10
x BAT1_N_CELLS [5,31] : 4
x BAT1_R_INTERNAL [6,32] : -1.0000
x BAT1_SOURCE [7,34] : 0
x + BAT1_V_CHANNEL [8,35] : 13
x BAT1_V_CHARGED [9,36] : 4.0500
x + BAT1_V_DIV [10,37] : 5.5316
x BAT1_V_EMPTY [11,38] : 3.5000
x BAT1_V_LOAD_DROP [12,39] : 0.3000
x BAT2_A_PER_V [13,40] : -1.0000
x BAT2_CAPACITY [14,41] : -1.0000
x BAT2_I_CHANNEL [15,42] : -1
x BAT2_N_CELLS [16,43] : 0
x BAT2_R_INTERNAL [17,44] : -1.0000
x BAT2_SOURCE [18,45] : -1
x BAT2_V_CHANNEL [19,46] : -1
x BAT2_V_CHARGED [20,47] : 4.0500
x BAT2_V_DIV [21,48] : -1.0000
x BAT2_V_EMPTY [22,49] : 3.5000
x BAT2_V_LOAD_DROP [23,50] : 0.3000
x BATMON_DRIVER_EN [24,52] : 0
x BAT_CRIT_THR [25,54] : 0.0700
x BAT_EMERGEN_THR [26,55] : 0.0500
x BAT_LOW_THR [27,56] : 0.1500
x + BAT_N_CELLS [28,57] : 4
x BAT_V_CHARGED [29,58] : 4.0500
x BAT_V_EMPTY [30,59] : 3.5000
x BAT_V_LOAD_DROP [31,60] : 0.3000
x BAT_V_OFFS_CURR [32,61] : 0.0000

800/1951 parameters used.
nsh> param show ADC*
Symbols: x = used, + = saved, * = unsaved
x ADC_ADS1115_EN [0,0] : 0

800/1951 parameters used.
nsh>

@AntonioAguilera
Copy link

Ok so for the people might have the same trouble... i needed to pull down the nPOWER_IN_A

@jamming
Copy link
Contributor

jamming commented Feb 23, 2022

Ok so for the people might have the same trouble... i needed to pull down the nPOWER_IN_A

nPOWER_IN_A can't be found in parameters list.
Do you mean pulling it down by hardware mod?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants