0

Odd results from two ADS1015s
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Odd results from two ADS1015s

by lefs on Wed Jan 09, 2019 12:41 pm

I am using two ADS1015 with an Arduino Mega2560. Some channels are always same in both devices and don't really change. The rest of channels show almost random readings. If the code is ok, should I lower the I2C bus speed(and how)? There is no need for hurry. The voltages I measure are heavily filtered with 2*105k and 100nF. So probably not much interference.

The real code is longer, I have to edit it heavily if it is needed here.

The code I use is like this but longer and whole.
Code: Select all | TOGGLE FULL SIZE
#include <Wire.h>
#include <Adafruit_ADS1015.h>
Adafruit_ADS1015 ads;     /* Use this for the 12-bit version */
Adafruit_ADS1015 ads9(0x49);
double luku;//anumber
int16_t adc, adc0, adc1, adc2, adc3;

void setup() {
ads.setGain(GAIN_FOUR);
  ads.begin();
  ads9.setGain(GAIN_FOUR);
  ads9.begin();
}
void loop() {
  adc0 = ads.readADC_SingleEnded(0);
  adc = ads.readADC_SingleEnded(1);
  adc2 = ads.readADC_SingleEnded(2);
  adc3 = ads.readADC_SingleEnded(3);
  luku=5*(double)adc/2047;//
  luku=(210+33)*luku/33;//
  luku=luku*4;//
Serial.print("voltage = ");
  Serial.println( luku);

  adc0 = ads9.readADC_SingleEnded(0);
 //  luku=adc;
  adc1 = ads9.readADC_SingleEnded(1);
  luku=adc1;
  adc2 = ads9.readADC_SingleEnded(2);
  adc3 = ads9.readADC_SingleEnded(3);
  luku=5*(double)adc/2047;//
  luku=(210+33)*luku/33;//210k and 33k
  luku=luku*4;//ADC has a gain of 4. ads.setGain(GAIN_FOUR);
Serial.print("voltage9 = ");
  Serial.println( luku);
  delay(1000); //and various other delays

 }

lefs
 
Posts: 17
Joined: Mon Jul 30, 2018 10:00 am

Re: Odd results from two ADS1015s

by lefs on Wed Jan 09, 2019 12:49 pm

What I asking is:
How do I slow down the I2C bus with this library
Do I need to wait more after conversion starts.
Is it OK to write this once in the code in beginning:
ads.setGain(GAIN_FOUR);
ads.begin();
ads9.setGain(GAIN_FOUR);
ads9.begin();
First and then looping conversions later in code.
What about ads.stop();?

lefs
 
Posts: 17
Joined: Mon Jul 30, 2018 10:00 am

Re: Odd results from two ADS1015s

by adafruit_support_bill on Wed Jan 09, 2019 3:53 pm

It is not clear what you are doing in the code. Please post some photos of your circuit showing your soldering, connections and signal sources.

Also, it is not clear what your code is supposed to do. If you post just the raw adc readings, it will be easier to identify any problems.

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

Re: Odd results from two ADS1015s

by lefs on Wed Jan 23, 2019 7:51 am

Today I tried a genuine Adafruit ADS1015 board and it didn't work.
As for code I useAdafruit single ended example. My supply voltage is 5V. I have now about 3.1V connected to AIN0. There is a 22k and 3.3k voltage divider in that input. There is also a 100nF from input to ground. Result is 0-3, when it should be around 1000
Nick Gammon's I2C spy finds the chip at 48H. There is no photo at the moment but the board is connected correctly with about 10cm= 1/3 feet wires.
Code: Select all | TOGGLE FULL SIZE
#include <Wire.h>
#include <Adafruit_ADS1015.h>

// Adafruit_ADS1115 ads;  /* Use this for the 16-bit version */
Adafruit_ADS1015 ads;     /* Use thi for the 12-bit version */

void setup(void)
{
  Serial.begin(9600);
  Serial.println("Hello!");
 
  Serial.println("Getting single-ended readings from AIN0..3");
  Serial.println("ADC Range: +/- 6.144V (1 bit = 3mV/ADS1015, 0.1875mV/ADS1115)");
 
  // The ADC input range (or gain) can be changed via the following
  // functions, but be careful never to exceed VDD +0.3V max, or to
  // exceed the upper and lower limits if you adjust the input range!
  // Setting these values incorrectly may destroy your ADC!
  //                                                                ADS1015  ADS1115
  //                                                                -------  -------
  // ads.setGain(GAIN_TWOTHIRDS);  // 2/3x gain +/- 6.144V  1 bit = 3mV      0.1875mV (default)
  // ads.setGain(GAIN_ONE);        // 1x gain   +/- 4.096V  1 bit = 2mV      0.125mV
  // ads.setGain(GAIN_TWO);        // 2x gain   +/- 2.048V  1 bit = 1mV      0.0625mV
  // ads.setGain(GAIN_FOUR);       // 4x gain   +/- 1.024V  1 bit = 0.5mV    0.03125mV
  // ads.setGain(GAIN_EIGHT);      // 8x gain   +/- 0.512V  1 bit = 0.25mV   0.015625mV
  // ads.setGain(GAIN_SIXTEEN);    // 16x gain  +/- 0.256V  1 bit = 0.125mV  0.0078125mV
 
  ads.begin();
}

void loop(void)
{
  int16_t adc0, adc1, adc2, adc3;

  adc0 = ads.readADC_SingleEnded(0);
  adc1 = ads.readADC_SingleEnded(1);
  adc2 = ads.readADC_SingleEnded(2);
  adc3 = ads.readADC_SingleEnded(3);
  Serial.print("AIN0: "); Serial.println(adc0);
  Serial.print("AIN1: "); Serial.println(adc1);
  Serial.print("AIN2: "); Serial.println(adc2);
  Serial.print("AIN3: "); Serial.println(adc3);
  Serial.println(" ");
 
  delay(1000);
}

lefs
 
Posts: 17
Joined: Mon Jul 30, 2018 10:00 am

Re: Odd results from two ADS1015s

by adafruit_support_bill on Wed Jan 23, 2019 7:55 am

Please post some photos that clearly show your soldering and connections.
Also please post a sample of the serial output from the code you are using.

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

Re: Odd results from two ADS1015s

by lefs on Wed Jan 23, 2019 11:16 am

The board is soldered to a prototype, I can't take a photo of it. This problem occurred first with a chips machine soldered professionally elsewhere. And now with a module bought from you. I think this not a soldering or connection problem.

lefs
 
Posts: 17
Joined: Mon Jul 30, 2018 10:00 am

Re: Odd results from two ADS1015s

by adafruit_support_bill on Wed Jan 23, 2019 12:05 pm

If it happened with two different boards, then it is not likely a board problem either.

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

Re: Odd results from two ADS1015s

by lefs on Wed Jan 23, 2019 12:18 pm

I agree, I think its either SW problem or long wires. Wires are really some 50cm. I'll have try to connect the board directly to the Mega. And to study how to make my own SW.

lefs
 
Posts: 17
Joined: Mon Jul 30, 2018 10:00 am

Re: Odd results from two ADS1015s

by adafruit_support_bill on Wed Jan 23, 2019 12:24 pm

50 cm is possible with i2c. But longer wires are more susceptible to noise and excess capacitance. Good quality cabling can help. Slowing down the i2c speed also sometimes helps. You can set the i2c clock speed using "WireSetClock" https://www.arduino.cc/en/Reference/WireSetClock

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

Re: Odd results from two ADS1015s

by lefs on Wed Jan 23, 2019 12:32 pm

adafruit_support_bill wrote:50 cm is possible with i2c. But longer wires are more susceptible to noise and excess capacitance. https://www.arduino.cc/en/Reference/WireSetClock

50cm should be ok. I tried to slow down the bus earlier but that didn't seem to help.
Have to study more. I think I'll try to connect wires directly to the Mega.

lefs
 
Posts: 17
Joined: Mon Jul 30, 2018 10:00 am

Please be positive and constructive with your questions and comments.