ADS 1115 sampling rate issues

Hello everyone, I need a small help for adjusting sampling rate that I’ve been trying for a month.

I’m using RPi 3B+ and adafruit ADS1115 16bit (max sample rate - 860/sec). I am getting just the standard 128samples/sec, but I need the maximum 860/sec or anywhere above 750samples/sec.
Output of my code - Press PB
count-1 blueON,
count-2 blueOFF, greenON
count-3 greenOFF, blueON for 5sec then blueOFF then greenON, read and writing A0 from ADS1115 to .csv file
count-4 greenOFF, stop reading A0, return to count-0.

This is the flow of the program, I’ve attached the code below.
I’ve gone through Aadafruit library https://github.com/adafruit/Adafruit_Python_ADS1x15 and no luck.
I am beginner to intermediate level in python. Kindly, help me do this. Thanks in advance.

import RPi.GPIO as GPIO
import datetime
import csv
import time
from time import sleep
# Import the ADS1x15 module.
import Adafruit_ADS1x15


adc = Adafruit_ADS1x15.ADS1115()
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(5,GPIO.IN,pull_up_down=GPIO.PUD_UP)
GPIO.setup(17,GPIO.OUT) #blue
GPIO.setup(27,GPIO.OUT) #green
#2/3=+/-6.144V #1=+/-4.096V #2=+/-2.048V
#4=+/-1.024V #8 = +/-0.512V #16=+/-0.256V

GAIN = 1
count = 0
results = ""
# Main loop.
while True:
       # values = [0]*2
   while GPIO.input(5) == 1:
       sleep(0.2)
   count = count + 1
   if count == 1:
       GPIO.output(17,GPIO.HIGH)
   while GPIO.input(5) == 0:
       sleep(1)
       GPIO.output(17,GPIO.LOW)
   print(count)

   if count == 2:
       GPIO.output(27,GPIO.HIGH)
       now=time.strftime('%d/%m/%Y,%H:%M:%S,')
       print(now)
       with open('ada1.csv', 'a') as file:
                file.write(now + ",")
   if count == 3:
       GPIO.output(27,GPIO.LOW)
       sleep(1)
       GPIO.output(17,GPIO.HIGH)
       sleep(3)
       GPIO.output(17,GPIO.LOW)
       GPIO.output(27,GPIO.HIGH)
       values = [0]*1
       for i in range(1):
           values[0] = adc.read_adc(0, gain=GAIN,data_rate=860)
       #    now=time.strftime('%d/%m/%Y,')
           print('{0:>6}'.format(*values))
           results = results + "," + str(values[i])

       with open('ada1.csv', 'a') as file:
            file.write(results + "\n")
       results = ""
       time.sleep(0.001)  
   if count == 4:
       count = 0
       GPIO.output(27,GPIO.LOW)

You don’t appear to be setting the data rate anywhere.

Try something like this:

adc = Adafruit_ADS1x15.ADS1115(data_rate=860)

Not sure if the rate needs to be in quotes. I believe the constructor will complain if it doesn’t like what you supply, and list the acceptable values.

1 Like