This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using ADS1115 in differential mode
#1
Hi, 
I have set up a configuration using ADS 1115 in differential mode.
This is suggested for some applications by the well known American
company Adafruit. They also supply a nice library for Pi (and Arduino
if you are not satisfied with 10 bits). 

My application is current measurement using Hall effect sensor (often referred 
to as current transformer, commonly used for AC) and measurement of 12V using a 
ladder which isolate both high amp +12V and GND (12V) system from the low voltage 
system on the Pi yacht server. See: 
https://sites.google.com/site/olewsaa/ya...ry-monitor
I plan to use several Hall effect sensors to keep track of current flowing and 
monitor the batteries. I do not want to bring in neither 12V nor GND from the 
high amp service 12V supply into the computer system / Pi. 
 
For background and overview of my project see:
https://sites.google.com/site/olewsaa/ya...-raspberry


So far I have interfaced this setup into openplotter  by writing an extra file:
differential_ads1115.py which is referenced from the setup file like this in 
the openplotter.conf :
[TOOLS]
py = [['Differential ads1115', 'put analog values to SignalK', 'differential_ads1115.py', '1'],['Analog ads1115', 'put analog values to SignalK', 'analog_ads1115.py', '0'], ['Analog Firmata', 'put analog values to SignalK', 'oppymata.py', '0'], ['SignalK Simulator', 'change values with sliders and send values to SignalK', 'SK-simulator.py', '0'], ['Auto Setup', 'configure basic system', 'autosetup_tty.py', '1']]

It shows up with an extra button.
In addition I have introduced two new entries in the 
tools/openplotter_analog.conf file :
[ADS1115_4]
active = 1
gain = 0
samples = 6
sk_name = electrical.batteries.current

[ADS1115_5]
active = 1
gain = 4
samples = 6
sk_name = electrical.batteries.voltage


So far none of the values are included and read into the differential_ads1115.py. 
This differential_ads1115.py file still have the things coded in the file 
and it's functions. Some relevant parts look like:


#
# Quick and dirty hack for differential measurements using ADS1115        
# Put the settings here before moving them  to config files.
GAIN_0 = 4 # 1 = +/-4.096V 2 = +/-2.048V 4 = +/-1.024V
GAIN_3 = 1 #
#
# Note you can change the differential value to the following:
#  - 0 = Channel 0 minus channel 1
#  - 1 = Channel 0 minus channel 3
#  - 2 = Channel 1 minus channel 3
#  - 3 = Channel 2 minus channel 3
#
#        


# Define functions to get the current i and voltage u.
# Eventually the settings parameters will be read from the
# config file.

def get_i():
    offset_0=200
    val=adc.read_adc_difference(0, gain=GAIN_0, data_rate=8)

#  Large Hall element, http://www.yhdc.com/en/product/379/ 50A version.
#  Pins from edge Vref Vout 0V Vdd
#  Linear regression, cal using multimeter.
#  y (current) = -0.52372 + 0.0024236 * x (counts)

    i = -0.52061 + 0.0024236 * val
    return i

def get_u():
    offset_3=1
    val=adc.read_adc_difference(3, gain=GAIN_3, data_rate=8)

    val=val-offset_3
    # 10k/54k=0.185185 ; rounded to 0.1841 after cal with voltmeter.
    u=(((float(val)/float(32768))*4.096)/0.1841) 
    return u

<snip>


else:
index+=1
if index>5: index=4

                        if index == 4:
                                a_value[index]=get_i()
                        else:
                                a_value[index]=get_u()                           
#                        print(index,a_value[4],a_value[5])

It all works fine and I and U display nicely on the instrumentpanel on 
the web page at port 3000.


There is a potential problem by setting the 
[ADS1115_4]
active = 1

and the [ADS1115_5 entry ad the normal ads1115 file will try to process it. 
I could us 2 as the code for active in the differential file and it would 
be taken as not 1 within the analog ads1115 file. Not a very clean way. 

This brings me to the question of the best way of setting this up and how the 
openplotter developers thinks this should be addressed ?

In due time the differential functions with it's parameters in the  
openplotter_analog.conf would be forwarded to the relevant processing scripts.

I would like to get some guidelines on how I should proceed in order
for the differential code should be written in order to get it included in the repository.


Regards,
Ole W. Saastad
https://sites.google.com/site/olewsaa/home
Reply


Messages In This Thread
Using ADS1115 in differential mode - by olewsaa - 2017-04-30, 08:41 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)