loading modules for ADS1115
Moderators: adafruit_support_bill, adafruit

loading modules for ADS1115

by mglenn12 on Thu Dec 12, 2013 12:34 pm

I confess I've gone from 'Hello World' to the ADS1115 with thermocouples in a blink and I'm floundering. When I run the program provided I receive the error that there is no module Adafruit_ADA1x15. But I have copied it to my root directory. I know this is the wrong directory because I should see it when I type 'lsmod' and it is not there. How do I move it to the modules directory? Rookie question, forgive me.

I was able to install and run the rtc-ds1307 module and that is working fine.

I eventually will use the ADS115 for the thermistors I bought.




Mike
mglenn12
 
Posts: 35
Joined: Thu Dec 12, 2013 11:56 am

Re: loading modules for ADS1115

by adafruit_support_mike on Thu Dec 12, 2013 3:15 pm

As you've stated the problem, I don't have quite enough information to choose the right answer.

I assume you're running Linux, but there's no such thing as an Adafruit_ADS1x15 module that `lsmod` would be able to see. We have an Adafruit_ADS1x15 library for the Arduino, and one written in Python for the Raspberry Pi.

What machine/OS are you using, and what kind of device are you trying to program?
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.
User avatar
adafruit_support_mike
 
Posts: 10082
Joined: Thu Feb 11, 2010 2:51 pm

Re: loading modules for ADS1115

by mglenn12 on Thu Dec 12, 2013 5:29 pm

I am running Linux and will attach 4 -10K thermistors to the ADS1115. thanks
mglenn12
 
Posts: 35
Joined: Thu Dec 12, 2013 11:56 am

Re: loading modules for ADS1115

by adafruit_support_mike on Fri Dec 13, 2013 5:22 am

Are you using a Raspberry Pi?
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.
User avatar
adafruit_support_mike
 
Posts: 10082
Joined: Thu Feb 11, 2010 2:51 pm

Re: loading modules for ADS1115

by mglenn12 on Fri Dec 13, 2013 9:17 am

My apologies for not being complete. Linux Debian v 2.0 with Python installed with the NOOB card in the Raspberry Pi.

For a more complete overview. I'm a scientist with the USDA and plan to use many of these Raspberry Pi units as inexpensive data loggers for climate change research. A typical data logger is at least $1K and I'm sure I can make each of these for less than $100 including conversion to battery power. I don't have access to an IT guy and it seems like an interesting intellectual challenge since teenage kids are doing so much of it. The first units will measure temperature with the 10K thermistors you provide (4 of them on the ADS1115). Other units will log millivolt output from other light and humidity sensors. Since I measure mv from thermistors, this should only be a programming change. The more difficult problem will be in measuring wind speed and rainfall with pulses/switches. But I'll fight that battle as my skill increases. 30+ years ago I did some ForTran programming so it is not entirely new but still just as frustrating as the old 80 column card decks.

The hardware is working fine since I can measure mv outputs at the terminals.

I do appreciate any help in getting the ADS115 programmed.

Mike
mglenn12
 
Posts: 35
Joined: Thu Dec 12, 2013 11:56 am

Re: loading modules for ADS1115

by adafruit_support_mike on Sat Dec 14, 2013 12:09 am

Thank you.. that gives me a much better idea of what you're trying to do, and what pieces you're using to do it.

Let me try to describe the issue to see if I understand it correctly:

You have a Python script on the RasPi that's trying to import the Adafruit_ADS1x15 library, but can't find it. As things currently stand, your home directory either contains a subdirectory named 'Adafruit_ADS1x15' or one named 'Adafruit-Raspberry-Pi-Python-Code', within which is the ADS1x15 folder.

Your script lives somewhere else, and you're trying to tell Python how to find the ADS1x15 library from there.

If that's correct, where is your script located?
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.
User avatar
adafruit_support_mike
 
Posts: 10082
Joined: Thu Feb 11, 2010 2:51 pm

Re: loading modules for ADS1115

by mglenn12 on Mon Dec 16, 2013 10:36 am

in my root directory
root@raspberrypi:/home/pi#

ls displays the folder Adafruit_ADS1x15

inside that folder are the 5 files from the GIThub:
Adafruit_ADS1x15.py ads1x15_ex_comparator.py ads1x15_ex_singleended.py ads1x15_ex_differential Adafruit_I2C.py

i2cdetect -y 1 demonstrates that I have the RTC card at 68 and the ADC card at 48

At the prompt I would enter root@raspberrypi:/home/pi# sudo python Adafruit_ADS1x15.py

This returns: python: can't open file 'Adafruit_ADS1x15.py': [Errno 2] No such file or directory

On what command line should I execute the program Adafruit_ADS1x15.py?

thank you for your help.
mglenn12
 
Posts: 35
Joined: Thu Dec 12, 2013 11:56 am

Re: loading modules for ADS1115

by adafruit_support_mike on Mon Dec 16, 2013 1:39 pm

It isn't something you'd run from the command line, but you need to let the Python interpreter know how to find the module you want to include.

To do that, add this to the top of your script:

Code: Select all | TOGGLE FULL SIZE
import sys
sys.path.append("/home/pi/Adafruit_ADS1x15")
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.
User avatar
adafruit_support_mike
 
Posts: 10082
Joined: Thu Feb 11, 2010 2:51 pm

Re: loading modules for ADS1115

by mglenn12 on Mon Dec 16, 2013 2:26 pm

add these 2 lines to Adafruit_ADS1x15.py?

If it's not normally run from the command line? where is it/how is it normally run?

thanks
mglenn12
 
Posts: 35
Joined: Thu Dec 12, 2013 11:56 am

Re: loading modules for ADS1115

by adafruit_support_mike on Tue Dec 17, 2013 11:58 pm

The file Adafruit_ADS1x15.py doesn't do anything by itself. It's just a library of pre-tested code that takes all the "this is how the datasheet says you have to communicate with the chip" stuff and wraps it in functions that have more immediate value in your own programs.

There are three example scripts in the same directory as Adafruit_ADS1x15.py. Those show you how to use the library, and what some of the specific functions do.

To run those from the Unix command line, navigate to the folder that contains the files:

Code: Select all | TOGGLE FULL SIZE
cd ~/Adafruit-Raspberry-Pi-Python-Code/Adafruit_ADS1x15/

where the tilde means "start in my home directory".

Then to execute the example files, use the following:

Code: Select all | TOGGLE FULL SIZE
sudo python ads1x15_ex_comparator.py
sudo python ads1x15_ex_differential.py
-or-
sudo python ads1x15_ex_singleended.py

The command `sudo` means "execute the following command with the privileges of the root user". That's necessary because the RasPi imposes restrictions on who can use the GPIO pins (which you'll use to talk to the ADC). `python` is the name of the program that reads the script and converts it to commands the CPU can execute. Then comes the name of the file you want the python interpreter to use.

To use the ADC in your own projects, you'll need to write your own python scripts using code provided by the Adafruit_ADS1x15 library. The code I posted earlier needs to go into those scripts so the python interpreter knows how to find the library you want to call. To learn how to write those scripts, read the code in the examples listed above and copy the parts that you need.
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.
User avatar
adafruit_support_mike
 
Posts: 10082
Joined: Thu Feb 11, 2010 2:51 pm

Re: loading modules for ADS1115

by mglenn12 on Wed Dec 18, 2013 11:09 am

thank you for the thorough reply. I know I am missing something fundamental but I have tried every possible combination of directories and files to make this work, without any success. It is my ignorance, not yours. But all I need is to read and write the 4 addresses on the ADS115. I know the i2c board is working at 0x48. The command 'i2cget -y 0x48 0x01 w' returns 8385 for example.

In scanning the various blogs, a simple program such as I've attached would do the job but even it doesn't work. It gives the error:

x = bus.read_byte_data(address, 1)
IOError: [Errno 5] Input/output error

Code: Select all | TOGGLE FULL SIZE
import smbus
import time
bus = smbus.SMBus(0)
address = 0x48

def x():
   x=bus.read_byte_data(address, 1)
   return x
while True:
   x = x()
   print x
   time.sleep(1)


so it is not reading the 0x48 address and I don't understand why?

Any help is appreciated while I learn Python programming. Mike
mglenn12
 
Posts: 35
Joined: Thu Dec 12, 2013 11:56 am

Re: loading modules for ADS1115

by mglenn12 on Wed Dec 18, 2013 2:52 pm

I solved my problem but I'm ashamed to explain the basis of my ignorance. thank you so much for all your help; your support was spot-on.
mglenn12
 
Posts: 35
Joined: Thu Dec 12, 2013 11:56 am

Re: loading modules for ADS1115

by adafruit_support_mike on Wed Dec 18, 2013 3:45 pm

You probably didn't make any mistake that I haven't. ;-)

Linux takes some getting used to. As long as it works for you now, it's all good. Happy hacking!
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.
User avatar
adafruit_support_mike
 
Posts: 10082
Joined: Thu Feb 11, 2010 2:51 pm

Re: loading modules for ADS1115

by mglenn12 on Thu Feb 27, 2014 4:51 pm

Now that I have everything working fine with one ADS115, I need to add a second and ultimately, 4 total. This is possible according to the spec's. Below is the read portion of my program for 2 ADS1115 boards. I do not make any distinction between them and simply continue the progression; consequently, the Pi only reads one board. Can you suggest modifications that will define each board? I have looked at Table 5 in the data sheet and have no idea what that means.

The 'while' statement that reads the ADS1115 in my program is below:


while step == 1:
sleep(60)

# Read channel 0 in single-ended mode using the settings above
volts0 = adc.readADCSingleEnded(0, gain, sps) /1000
R0 = 10*(5/volts0 -1)
T0 = (volts0-3.7375)/(-0.0504)

# To read channel 1 in single-ended mode, :
volts1 = adc.readADCSingleEnded(1, gain, sps) /1000
R1 = 10*(5/volts1-1)
T1 = (volts1-3.7375)/(-0.0504)

# Read channel 2 in single-ended mode using the settings above
volts2 = adc.readADCSingleEnded(2, gain, sps) /1000
R2 = 10*(5/volts2-1)
T2 = (volts2-3.7375)/(-0.0504)

# To read channel 3 in single-ended mode,
volts3 = adc.readADCSingleEnded(3, gain, sps) /1000
R3 = 10*(5/volts3-1)
T3 = (volts3-3.7375)/(-0.0504)

# Read channel 4 in single-ended mode using the settings above
volts4 = adc.readADCSingleEnded(4, gain, sps) /1000
R4 = 10*(5/volts0 -1)
T4 = (volts0-3.7375)/(-0.0504)

# To read channel 5 in single-ended mode, :
volts5 = adc.readADCSingleEnded(5, gain, sps) /1000
R5 = 10*(5/volts1-1)
T5 = (volts1-3.7375)/(-0.0504)

# Read channel 6 in single-ended mode using the settings above
volts6 = adc.readADCSingleEnded(6, gain, sps) /1000
R6 = 10*(5/volts2-1)
T6 = (volts2-3.7375)/(-0.0504)

# To read channel 7 in single-ended mode,
volts7 = adc.readADCSingleEnded(7, gain, sps) /1000
R7 = 10*(5/volts3-1)
T7 = (volts3-3.7375)/(-0.0504)

TI=datetime.datetime.now()

print TI.year, TI.month, TI.day, TI.hour, TI.minute,rep, trt, loc, T0, T1, T2, T3, T4, T5, T6, T7
mglenn12
 
Posts: 35
Joined: Thu Dec 12, 2013 11:56 am

Re: loading modules for ADS1115

by mglenn12 on Thu Feb 27, 2014 5:22 pm

I forgot to add that I have jumpered the 2 boards and read them as 048 and 049.
mglenn12
 
Posts: 35
Joined: Thu Dec 12, 2013 11:56 am