0

RPi3B+ & ADS 1115 input fluctuations & sampling rate issues
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

RPi3B+ & ADS 1115 input fluctuations & sampling rate issues

by mjana on Fri Aug 02, 2019 6:38 am

Hi guys,
I've been suddenly experiencing values fluctuations from A0 (ads1115).
I've tried from other pins too, same result. Rebooted, no change. Re-wired, no change.

The values are like

Code: Select all | TOGGLE FULL SIZE
26299
    -7
    -6
    -5
  6043
 26309
    -2
    -3
  6848
 26304
    -3
    -7
    -4
  3905
    -3
    -5
    -6
  4387
 26304
    -5
    -4
    -4
 26307
 12342
    -1
    -4
    -3
 26307
    -2
    -6
    -4
  3292
 26305
  6231
    -3
    -5
  1742
 26305
    -6
    -5
    -3
  6785
 26310
 16396
    -6
    -7
  7661


and the code is
Code: Select all | TOGGLE FULL SIZE
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)

#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:
   while GPIO.input(5) == 1:
       sleep(0.2)
   count = count + 1

   if count == 1:
   while GPIO.input(5) == 0:
       sleep(1)
   print(count)

   if count == 3:
       values = [0]
       while GPIO.input(5) == 1:
              values[0] = adc.read_adc(0, gain=GAIN, data_rate=860)
              print('{0:>6}'.format(*values))
              time.sleep(0.00000000001)  # Pause for half a secon
   if count == 4:
       count = 0


Also, I'm trying to get sampling rate of 1000samples/sec, but ads1115 maximum rate is 860. I've chosen data_rate=860. Still I get just 250samples/sec, I even tried varying time.sleep() , no change in samples.

Any help, highly appreciated.
Thanks in advance.

mjana
 
Posts: 12
Joined: Sun Jul 07, 2019 11:25 pm

Re: RPi3B+ & ADS 1115 input fluctuations & sampling rate iss

by mjana on Fri Aug 02, 2019 7:53 am

https://plux.info/cables/390-arduino-sensor-cable.html
https://plux.info/cables/226-3-lead-ele ... cable.html
These are input sensors. Input voltage to sensor is 3.3v from RPi

mjana
 
Posts: 12
Joined: Sun Jul 07, 2019 11:25 pm

Re: RPi3B+ & ADS 1115 input fluctuations & sampling rate iss

by adafruit_support_bill on Fri Aug 02, 2019 8:09 am

I get just 250samples/sec

Based on that sample rate, the fluctuations look like they have a frequency of roughly 50Hz. If you post some photos of your wiring and connections we can take a look.

adafruit_support_bill
 
Posts: 74679
Joined: Sat Feb 07, 2009 10:11 am

Re: RPi3B+ & ADS 1115 input fluctuations & sampling rate iss

by mjana on Fri Aug 02, 2019 12:33 pm

Thanks for the response. Here are my connections... sorry for the bad quality.
Attachments
IMG_12411.jpg
IMG_12411.jpg (954.68 KiB) Viewed 152 times

mjana
 
Posts: 12
Joined: Sun Jul 07, 2019 11:25 pm

Re: RPi3B+ & ADS 1115 input fluctuations & sampling rate iss

by mjana on Fri Aug 02, 2019 12:37 pm

adafruit_support_bill wrote:
I get just 250samples/sec

Based on that sample rate, the fluctuations look like they have a frequency of roughly 50Hz. If you post some photos of your wiring and connections we can take a look.


How to increase sampling rate to 1000 samples/sec or 860/sec.
And just letting you know that the base of RPi, ADS1115 module and breadboard aren't touching the PCB board. They are fixed using BluTack (thick reusable adhesives)

mjana
 
Posts: 12
Joined: Sun Jul 07, 2019 11:25 pm

Re: RPi3B+ & ADS 1115 input fluctuations & sampling rate iss

by adafruit_support_bill on Fri Aug 02, 2019 2:48 pm

We can't see what the blue wire is connected to. That is most likely where the noise is entering the system.

adafruit_support_bill
 
Posts: 74679
Joined: Sat Feb 07, 2009 10:11 am

Re: RPi3B+ & ADS 1115 input fluctuations & sampling rate iss

by mjana on Fri Aug 02, 2019 9:29 pm

Blue wire is connected to the signal wire of sensor(violet). It was all good till yesterday. Something wrong with sensor ?
And again how to increase sampling rate to 1000/sec. the samples I’ve been getting isn’t 50hz, but it’s 250hz.

mjana
 
Posts: 12
Joined: Sun Jul 07, 2019 11:25 pm

Re: RPi3B+ & ADS 1115 input fluctuations & sampling rate iss

by adafruit_support_bill on Sat Aug 03, 2019 5:53 am

Blue wire is connected to the signal wire of sensor(violet). It was all good till yesterday. Something wrong with sensor ?

We can't diagnose the noise without understanding the complete circuit. The 50Hz noise is typical of an open circuit or a grounding problem. Your photos do not show the complete circuit.

And again how to increase sampling rate to 1000/sec.

The sensor's maximum rate is 860/sec. But you have a noise problem with your current circuit and it is best to focus on one problem at a time.

the samples I’ve been getting isn’t 50hz, but it’s 250hz.

But the noise is periodic and appears to be about 50 Hz.

adafruit_support_bill
 
Posts: 74679
Joined: Sat Feb 07, 2009 10:11 am

Re: RPi3B+ & ADS 1115 input fluctuations & sampling rate iss

by mjana on Sun Aug 04, 2019 6:36 am

Your support and response rate is impressive.
Good news is that I rewired the whole thing again and the problem was with one of the wires. There is no noise now. Thanks alot.
Now, how do I increase sampling rate to 860/sec ?
If you can go through my code, and after testing I get sampling around 250hz (So, for 10sec it's 2579samples). Can you please help me to get 860hz, how do I do that ?
I am beginner to this electronics and python. Thanks for the help in advance.

mjana
 
Posts: 12
Joined: Sun Jul 07, 2019 11:25 pm

Re: RPi3B+ & ADS 1115 input fluctuations & sampling rate iss

by adafruit_support_bill on Sun Aug 04, 2019 7:10 am

Good to hear you have eliminated the noise problem.

There are a couple of things that affect sample rate. One is the default operating mode of the ADS1115 is 'single-shot'. That means the conversions only occur when requested. You can try setting the mode to continuous, instead of the default single shot. That eliminates some of the overhead.
Code: Select all | TOGGLE FULL SIZE
adc.mode = 0


The other possible issue is with Python execution overhead. Since it is an interpreted language, there is some sacrifice in speed. So your maximum read rate may be limited.

adafruit_support_bill
 
Posts: 74679
Joined: Sat Feb 07, 2009 10:11 am

Re: RPi3B+ & ADS 1115 input fluctuations & sampling rate iss

by mjana on Sun Aug 04, 2019 7:32 am

adafruit_support_bill wrote:Good to hear you have eliminated the noise problem.

There are a couple of things that affect sample rate. One is the default operating mode of the ADS1115 is 'single-shot'. That means the conversions only occur when requested. You can try setting the mode to continuous, instead of the default single shot. That eliminates some of the overhead.
Code: Select all | TOGGLE FULL SIZE
adc.mode = 0


The other possible issue is with Python execution overhead. Since it is an interpreted language, there is some sacrifice in speed. So your maximum read rate may be limited.


Unfortunately, I couldn't find a way to make it continuous from
Code: Select all | TOGGLE FULL SIZE
adc.mode = 0


Have you any tips/suggestions for algorithm or functions ?
If figured out something, I will definitely respond with code.
Thank you :)

mjana
 
Posts: 12
Joined: Sun Jul 07, 2019 11:25 pm

Re: RPi3B+ & ADS 1115 input fluctuations & sampling rate iss

by adafruit_support_bill on Sun Aug 04, 2019 8:02 am

Which library are you using? There was an issue related to continuous mode, but it was fixed recently here.

https://github.com/adafruit/Adafruit_Ci ... on_ADS1x15

https://github.com/adafruit/Adafruit_Ci ... /issues/26

adafruit_support_bill
 
Posts: 74679
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.