ADS1115 Not functioning properly

Moderators: adafruit_support_bill, adafruit

Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/
User avatar
ZavierJacob
 
Posts: 18
Joined: Wed Apr 13, 2022 5:05 pm

Re: ADS1115 Not functioning properly

Post by ZavierJacob »

It doesn't seem like the ads1115 is receiving the sensor values at all but channel 0 works perfectly

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

Re: ADS1115 Not functioning properly

Post by adafruit_support_bill »

Sensor 1 - 2.45
sensor 2 - 2.46

with potentiometer change
That is only one measurement.
What is the voltage at the minimum range of the pot?
And what is the voltage at the maximum range of the pot?

How do the actual voltages measured with the multimeter compare to the voltages reported by the code?

User avatar
ZavierJacob
 
Posts: 18
Joined: Wed Apr 13, 2022 5:05 pm

Re: ADS1115 Not functioning properly

Post by ZavierJacob »

When I vary the potentiometer the voltage at the sensor stays the same 2.46V but the voltage in the code ranges from 0 to 15 V for sensor 1. Sensor 2 is unaffected and displays 9 on the code regardless of the potentiometer change.

User avatar
ZavierJacob
 
Posts: 18
Joined: Wed Apr 13, 2022 5:05 pm

Re: ADS1115 Not functioning properly

Post by ZavierJacob »

The maximum value on the potentiometer reads a voltage of 15V on the code for Sensor 1.

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

Re: ADS1115 Not functioning properly

Post by adafruit_support_bill »

OK. So it sounds like you have some sort of crosstalk between channels 0 and 1. I'm going to check with some of our python experts that are more familiar with the library you are using.

User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: ADS1115 Not functioning properly

Post by adafruit_support_carter »

You are using the ADS in a single ended setup on channels 1-3 with channel 4 not in use. Please see the example here:
https://github.com/adafruit/Adafruit_Ci ... pletest.py
and try rewriting your code to use the channel's value and voltage properties as shown, instead of calling adc.read() directly.

User avatar
ZavierJacob
 
Posts: 18
Joined: Wed Apr 13, 2022 5:05 pm

Re: ADS1115 Not functioning properly

Post by ZavierJacob »

This is the new code

Code: Select all


# This code runs a motor clockwise and the speed is adjustable by potentiometer
import adafruit_ads1x15.ads1115 as ADS
from adafruit_ads1x15.ads1115 import Mode
from adafruit_ads1x15.analog_in import AnalogIn
import time
import smbus
import board
import busio
import RPi.GPIO as GPIO


i2c = busio.I2C(board.SCL, board.SDA)

adc = ADS.ADS1115(i2c)
#adc.mode = Mode.SINGLE

GAIN=1

chan0 = AnalogIn(adc, ADS.P0) #define channel on ads1115
chan1 = AnalogIn(adc, ADS.P1) #define channel for voltage sensor on battery1
chan2 = AnalogIn(adc, ADS.P2) #define channel for voltage sensor on battery2
chan3 = AnalogIn(adc, ADS.P3) #define channel for voltage sensor on generator

value=chan0

def setup():
	global adc
	if(AnalogIn(adc, ADS.P0)):
		adc = ADS.ADS1115(board.I2C())
	else:
		print("No correct I2C address found, \n"
		"Please use command 'i2cdetect -y 1' to check the I2C address. \n"
		"Program Exit. \n");
		exit(-1)
	global p
	GPIO.setmode(GPIO.BCM) #declare the GPIO settings
	global value
	
	
	
	#set up GPIO pins
	GPIO.setup(17 , GPIO.OUT) # connected to pwm
	GPIO.setup(22 , GPIO.OUT) # connect to In2
	GPIO.setup(27 , GPIO.OUT) # connected to In1

	p = GPIO.PWM(17 , 1000) # creat PWM and set Frequence to 1KHz
	p.start(0)


def motor(ADC):
	
	value = ADC 
	if (ADC > -16384):  # turn clockwise
		GPIO.output(27, GPIO.HIGH)
		GPIO.output(22, GPIO.LOW)
		print("Run")
		p.ChangeDutyCycle(95)
	elif (value < -16348):
		GPIO.output(27, GPIO.HIGH)
		GPIO.output(22, GPIO.LOW)
		print("Run Slow")
		p.ChangeDutyCycle(75)
	

def parameters():
	while True:
		value = chan0  # read ADC from channel 0
		print('ADC Value :%s' % str(value))
		motor(value)
		#bat1 = adc.read(1, GAIN) #read voltage sensor from channel 2
		#bat2 = adc.read(2, GAIN) #read voltage sensor from channel 3
		#gen1 = adc.read(3, GAIN) #read voltage sensor from generator
		print('Battery 1 Voltage : %d' % ((abs(bat1)/1362)*12))
		print('Battery 2 Voltage : %d' % ((abs(bat2)/1614)*12))
		print('Generator Voltage : %d' % (((abs(gen1)/8192)*19)+3))
		print(chan0)
		print(chan1)
		print(chan2)
		print(chan3)
		#print(bat2)
		time.sleep(1)


def destroy():
	p.stop()  # stops PWM
	GPIO.cleanup()


if __name__ == '__main__':  # program entrance
	print('Program is starting...')
	setup()
	try:
		parameters()
	except KeyboardInterrupt:  # press  ctrlc to end program
		destroy()

This is the error:

Code: Select all


Program is starting...
ADC Value :<adafruit_ads1x15.analog_in.AnalogIn object at 0xb65357d0>
Traceback (most recent call last):
  File "RC51.py", line 93, in <module>
    parameters()
  File "RC51.py", line 69, in parameters
    motor(value)
  File "RC51.py", line 53, in motor
    if (ADC > -16384):  # turn clockwise
TypeError: '>' not supported between instances of 'AnalogIn' and 'int'


User avatar
ZavierJacob
 
Posts: 18
Joined: Wed Apr 13, 2022 5:05 pm

Re: ADS1115 Not functioning properly

Post by ZavierJacob »

I fixed it. Thank you so much for all your help!!

User avatar
adafruit2
 
Posts: 22148
Joined: Fri Mar 11, 2005 7:36 pm

Re: ADS1115 Not functioning properly

Post by adafruit2 »

first up - your wiring is also super long and kinda messy. you should tighten everything up, make sure you have short wiring to minimize noise coupling.
also make sure your voltages don't have big resistive impedences that could make them susceptible to noise.
and REMOVE the motor, you cannot power it on the same power rails as the ADC

second, remove all the parts of the code except for reading the ADC. have two ADC reads per channel in a row to make sure you flush out any bad reads.

User avatar
ZavierJacob
 
Posts: 18
Joined: Wed Apr 13, 2022 5:05 pm

Re: ADS1115 Not functioning properly

Post by ZavierJacob »

Thank you, I will take all of your suggestions into consideration (especially the part about tightening up the wires). The motor is on a separate rail and powered by a different source though. After your code example, I changed the code and the sensors read fine. Now I just need to sort out why the potentiometer causes the program to quit.

Locked
Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/

Return to “Adafruit Raspberry Pi® accessories”