Raspberry Pi 4 cannot connect to ADS1115

I have a raspberry pi 4 and am trying to connect an ads1115 to the pi. I have checked the wiring and everything seems ok. Every time I try to add the unit I cannot select the device as shownCayenne|375x500
I can use sudo i2cdetect -y 1 and it shows channel 48 is reading. Any help would be appreciated.

you need to use ads plugin GitHub - myDevicesIoT/cayenne-plugin-ads1xxx: An ADS1XXX extension plugin for Cayenne

Thanks,
I have done this and still no change. The restart was done as well.

Thanks

  1. Install Adafruit python ads115 library using pip:, pip install Adafruit-ADS1x15
  2. Run the script below in your pi’s terminal and then check your dashboard whether some widgets showing numerical values appear or not.

Don’t forget to change cayenne authentication info in the sketch below.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import cayenne.client
import Adafruit_ADS1x15
import time
import smbus
import paho.mqtt.client as mqtt

# Cayenne Authentication info. This should be obtained from the Cayenne Dashboard.
MQTT_USERNAME  = "3b7a8a90-caec-11e9-ba7c-716e7f5ba423"
MQTT_PASSWORD  = "78aeda8509dcece0c19b3c99e53a867fbb0457fd"
MQTT_CLIENT_ID = "c7079ab0-f0d7-11e9-84bb-8f71124cfdfb"

client = cayenne.client.CayenneMQTTClient()
client.begin(MQTT_USERNAME, MQTT_PASSWORD, MQTT_CLIENT_ID)

# Call adc115
adc = Adafruit_ADS1x15.ADS1115()
GAIN = 1

print('Reading ADS1x15 values, press Ctrl-C to quit...')
print('| {0:>6} | {1:>6} | {2:>6} | {3:>6} |'.format(*range(4)))
print('-' * 37)

# Main loop.
while True:
    # Read all the ADC channel values in a list.
    values = [0]*4
    for i in range(4):
        # Read the specified ADC channel using the previously set gain value.
        values[i] = adc.read_adc(i, gain=GAIN)
    # Print the ADC values.
    print('| {0:>6} | {1:>6} | {2:>6} | {3:>6} |'.format(*values))
	client.loop()
	client.virtualWrite(1, values[0])
	client.virtualWrite(2, values[0])
	client.virtualWrite(3, values[0])
	client.virtualWrite(4, values[0])
    # Pause for half a second.
    time.sleep(2)

Hi Sahar,

I have had some success and can see all 4 channels


I am a complete amateur at this so I am not sure how I know if the ADS115 is communicating with the rpi
Thanks in advance

Just apply 3 volts to any analogue pin of ads ( let say pin A0) and see whether the values on the dashboard changes or not. If changes that means your ads is working.

Hi Sahar
The values in the previous post were generated from your python script I can still not add an extension from the cayenne faceplate.
I have used the following

import time
import board
import busio
import adafruit_ads1x15.ads1015 as ADS
from adafruit_ads1x15.analog_in import AnalogIn

# Create the I2C bus
i2c = busio.I2C(board.SCL, board.SDA)

# Create the ADC object using the I2C bus
ads = ADS.ADS1015(i2c)

# Create single-ended input on channel 0
chan = AnalogIn(ads, ADS.P0)

# Create differential input between channel 0 and 1
#chan = AnalogIn(ads, ADS.P0, ADS.P1)

print("{:>5}\t{:>5}".format('raw', 'v'))

while True:
    print("{:>5}\t{:>5.3f}".format(chan.value, chan.voltage))
    time.sleep(0.5)

Which seems to give me the raw values from the ADS on channel 0 but cannot see it on cayenne.
What am I missing

Thanks

are you using ADS1115 or ADS1015?
if the code shared by you is working then, just add the cayenne code from sahar post into yours.

Hi I am using a ads1115 but only require one channel and have changed the code to suit.
Can you please help me add the following codes together so I can get channel 0 to write to ceyanne for me.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import cayenne.client
import Adafruit_ADS1x15
import time
import smbus
import paho.mqtt.client as mqtt

# Cayenne Authentication info. This should be obtained from the Cayenne Dashboard.
MQTT_USERNAME  = "blah"
MQTT_PASSWORD  = "blah"
MQTT_CLIENT_ID = "blah"

client = cayenne.client.CayenneMQTTClient()
client.begin(MQTT_USERNAME, MQTT_PASSWORD, MQTT_CLIENT_ID)

# Call adc115
adc = Adafruit_ADS1x15.ADS1115()
GAIN = 1

print('Reading ADS1x15 values, press Ctrl-C to quit...')
print('| {0:>6} | {1:>6} | {2:>6} | {3:>6} |'.format(*range(4)))
print('-' * 37)

# Main loop.
while True:
    # Read all the ADC channel values in a list.
    values = [0]*1
    for i in range(1):
        # Read the specified ADC channel using the previously set gain value.
        values[i] = adc.read_adc(i, gain=GAIN)
    # Print the ADC values.
    print('| {0:>6} |'.format(*values))
    client.loop()
    client.virtualWrite(1, values[0])

    # Pause for half a second.
    time.sleep(2)

and

import time
import board
import busio
import adafruit_ads1x15.ads1115 as ADS
from adafruit_ads1x15.analog_in import AnalogIn
Create the I2C bus
i2c = busio.I2C(board.SCL, board.SDA)
Create the ADC object using the I2C bus
ads = ADS.ADS1115(i2c)
Create single-ended input on channel 0
chan = AnalogIn(ads, ADS.P0)
Create differential input between channel 0 and 1
#chan = AnalogIn(ads, ADS.P0, ADS.P1)
print("{:>5}\t{:>5}".format(‘raw’, ‘v’))
while True:
print("{:>5}\t{:>5.3f}".format(chan.value, chan.voltage))
time.sleep(0.5)

Thanks

MC

in your first code, it is sending dat from channel 0 to cayenne.

Yes but would like to be able to vary the input . At the moment it just sends through what seems random numbers. I have applied 3 volts to the input on channel 0 and nothing changes

can you share the output of this when you change the sensor value:

# Simple demo of reading each analog input from the ADS1x15 and printing it to
# the screen.
# Author: Tony DiCola
# License: Public Domain
import time

# Import the ADS1x15 module.
import Adafruit_ADS1x15


# Create an ADS1115 ADC (16-bit) instance.
adc = Adafruit_ADS1x15.ADS1115()

# Or create an ADS1015 ADC (12-bit) instance.
#adc = Adafruit_ADS1x15.ADS1015()

# Note you can change the I2C address from its default (0x48), and/or the I2C
# bus by passing in these optional parameters:
#adc = Adafruit_ADS1x15.ADS1015(address=0x49, busnum=1)

# Choose a gain of 1 for reading voltages from 0 to 4.09V.
# Or pick a different gain to change the range of voltages that are read:
#  - 2/3 = +/-6.144V
#  -   1 = +/-4.096V
#  -   2 = +/-2.048V
#  -   4 = +/-1.024V
#  -   8 = +/-0.512V
#  -  16 = +/-0.256V
# See table 3 in the ADS1015/ADS1115 datasheet for more info on gain.
GAIN = 1

print('Reading ADS1x15 values, press Ctrl-C to quit...')
# Print nice channel column headers.
print('| {0:>6} | {1:>6} | {2:>6} | {3:>6} |'.format(*range(4)))
print('-' * 37)
# Main loop.
while True:
    # Read all the ADC channel values in a list.
    values = [0]*4
    for i in range(4):
        # Read the specified ADC channel using the previously set gain value.
        values[i] = adc.read_adc(i, gain=GAIN)
        # Note you can also pass in an optional data_rate parameter that controls
        # the ADC conversion time (in samples/second). Each chip has a different
        # set of allowed data rate values, see datasheet Table 9 config register
        # DR bit values.
        #values[i] = adc.read_adc(i, gain=GAIN, data_rate=128)
        # Each value will be a 12 or 16 bit signed integer value depending on the
        # ADC (ADS1015 = 12-bit, ADS1115 = 16-bit).
    # Print the ADC values.
    print('| {0:>6} | {1:>6} | {2:>6} | {3:>6} |'.format(*values))
    # Pause for half a second.
    time.sleep(0.5)
1 Like

Cheers

That has me on the right track now

i have not added cayenne code in it. it was just to make sure whether you are getting the correct reading from ads1115.

Thanks
I have done that and it seems to work however I now need to work out how to change the raw value from 0-2.5 volts to 0-100%

i think this should work:

def map(x, in_min, in_max, out_min, out_max):
    return int((x-in_min) * (out_max-out_min) / (in_max-in_min) + out_min)

where x is the sensor value and provides the min and max range.

no puedo instalar la libreria Adafruit-ADS1x15

Help me please

you can also use ads plugin for cayenne pi agent GitHub - myDevicesIoT/cayenne-plugin-ads1xxx: An ADS1XXX extension plugin for Cayenne