ADC ADS1115

Forum Administrative - NOT PROJECT OR "HELP"

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
cosmoff
 
Posts: 7
Joined: Sun May 10, 2015 8:17 am

ADC ADS1115

Post by cosmoff »

hello,
i prevent you, I m french so my ENglish is so so

i have bought a ADC ADS1115 and to read the analog voltage I used python langage with a raspberry,
my problem and that i receive numbers but it doesn't correspond of my voltage. It must be a probleme with byte order, so this is my code:

Code: Select all

import time
import smbus

Bus_I2C = smbus.SMBus(1) 
Address_I2C_US = 0x48 # 

Bus_I2C.write_word_data(Address_I2C_US,0x01,0x8384) 
Bus_I2C.write_byte(Address_I2C_US,0x00) 
while True:
        time.sleep(1)
        try:
                tension=Bus_I2C.read_word_data(Address_I2C_US,0) 
                voltage =  (tension & 0xFF) << 8 | (tension >> 8)
                print(voltage)
        except IOError:
                print("connexion Error ")

Do you have an idea to resolve my problem?
thank you ;)

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: ADC ADS1115

Post by adafruit_support_bill »

You are reading the raw result which is in binary. To convert that to volts, you need to know the gain setting.

We have a Python library and some example code for this:
https://github.com/adafruit/Adafruit-Ra ... it_ADS1x15

User avatar
cosmoff
 
Posts: 7
Joined: Sun May 10, 2015 8:17 am

Re: ADC ADS1115

Post by cosmoff »

I put the gain to +-2.048V (default) 0x84
what can i do now to read my analog voltage without to use your library

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: ADC ADS1115

Post by adafruit_support_bill »

You need to start the conversion and wait for it to finish. Then you need top multiply the raw reading by the full-scale range and divide by 32768.

Please refer to the library code. It is a good example of how to do all this - even if you do not want to use the library.

User avatar
cosmoff
 
Posts: 7
Joined: Sun May 10, 2015 8:17 am

Re: ADC ADS1115

Post by cosmoff »

I looked the library code (ligne 486-498), and I have changed my code which is:

Code: Select all

import time
import smbus

pga = 1024
Bus_I2C = smbus.SMBus(1)

Address_I2C_US = 0x48

Bus_I2C.write_word_data(Address_I2C_US,0x01,0x8384) 
Bus_I2C.write_byte(Address_I2C_US,0x00)

while True:
        time.sleep(1)
        tension=Bus_I2C.read_word_data(Address_I2C_US,0x00)
        voltage = ((tension&0x01) << 8) | (tension&0x02)
        if voltage > 0x7FFF:
                        voltage=((voltage - 0xFFFF))*pga/32768.0
        else:
                        voltage= (((voltage&0x01) << 8) | (voltage&0x02) )*pga/32768.0
        
        print("voltage equal : "+str(voltage))

but it doesn't work....

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: ADC ADS1115

Post by adafruit_support_bill »

I looked the library code (ligne 486-498),
There is a lot more to the library. To take a reading, you need to start the conversion, wait for it to finish, then read the result.

User avatar
cosmoff
 
Posts: 7
Joined: Sun May 10, 2015 8:17 am

Re: ADC ADS1115

Post by cosmoff »

I have read every about the library code, I have put a delay of 1 second... everything is Ok but the analog voltage read is False...
Someone knows how can I resolve the problem ??

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: ADC ADS1115

Post by adafruit_support_bill »

The library code works. What is your objection to using it?

User avatar
cosmoff
 
Posts: 7
Joined: Sun May 10, 2015 8:17 am

Re: ADC ADS1115

Post by cosmoff »

I download the Adafruit's Raspberry-Pi Python Code Library in writting on my terminal git clone https://github.com/adafruit/Adafruit-Ra ... n-Code.git

but when I put in my code : from Adafruit_I2C import Adafruit_I2C

my terminal answer me : No module named Adafruit_I2C

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: ADC ADS1115

Post by adafruit_support_bill »

As you can see, Adafruit_i2c.py is definitely included in the repository. Are you sure you downloaded the entire code library?
https://github.com/adafruit/Adafruit-Ra ... ython-Code

User avatar
cosmoff
 
Posts: 7
Joined: Sun May 10, 2015 8:17 am

Re: ADC ADS1115

Post by cosmoff »

to download the entire code library I just need to put in my terminal :

git clone https://github.com/adafruit/Adafruit-Ra ... n-Code.git


no?

User avatar
tdicola
 
Posts: 1074
Joined: Thu Oct 17, 2013 9:11 pm

Re: ADC ADS1115

Post by tdicola »

If you're getting an error 'No module named Adafruit_I2C' double check that there's an Adafruit_I2C.py file in the same directory as your python script. In the library there's a symlink to the Adafruit_I2C.py file so perhaps that's causing an issue on your platform. Try just grabbing the Adafruit_I2C.py file from here and dropping it in the same directory as your python code: https://github.com/adafruit/Adafruit-Ra ... uit_I2C.py

Give that a shot and let me know if you still see errors, thanks!

User avatar
cosmoff
 
Posts: 7
Joined: Sun May 10, 2015 8:17 am

Re: ADC ADS1115

Post by cosmoff »

I have added it in my code and I think it 's working but I have an other problem :

Code: Select all

Default I2C bus is accessible
Traceback (most recent call last):
  File "AdaUS.py", line 178, in <module>
    class ADS1x15:
  File "AdaUS.py", line 289, in ADS1x15
    def __init__(self, address=0x48, ic=_IC_ADS1115, debug=False):
NameError: name '_IC_ADS1115' is not defined
have you got an idea to fix it ?

User avatar
tdicola
 
Posts: 1074
Joined: Thu Oct 17, 2013 9:11 pm

Re: ADC ADS1115

Post by tdicola »

Sorry missed replying to this earlier, but it looks like your file might have been changed or corrupted. If you look at the code on github here the name should be '__IC_ADS1015' with two underscores instead of one underscore: https://github.com/adafruit/Adafruit-Ra ... 15.py#L132 If you're copying the library code into your own code double check it's copying over two underscores and not just one.

Locked
Please be positive and constructive with your questions and comments.

Return to “Administrative (closed)”