Author Topic: Talking to the ADS1115  (Read 698 times)

0 Members and 1 Guest are viewing this topic.

Offline andymouseTopic starter

  • Contributor
  • Posts: 17
  • Country: gb
Talking to the ADS1115
« on: February 17, 2020, 10:16:42 am »
Code: [Select]
Hi,
I am trying to change the parameters of the ADS1115 to alter the gain and also the samples per second (SPS) by using the "Wire.h" library.
The section of code between the h"hash" marks is how I understand it from the datasheet but it has no effect, also
 I have tried other peoples code that uses the same method and it doesn't work for them either I can only assume they didn't check.
After trying proper 8 bits according to the register info I put in random Bytes (frustration) this did nothing. The sketch
 works fine if I uncomment the required gain but I also want to change the SPS, I would like to no why this has no effect,
am I using the Wire functions incorrectly or am I oversimplifying it ? what have I missed please?

Andy
[code#include <Wire.h>
#include <Adafruit_ADS1015.h>
#include <LiquidCrystal_PCF8574.h>
LiquidCrystal_PCF8574 lcd(0x27);
Adafruit_ADS1115 ads;

void setup(void)
{
  //                                                                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
  lcd.begin(16, 2);
  ads.begin();
  lcd.setBacklight(1);            // 0 = OFF  1 = ON

//######################## Trying to talk to ADS1115 ####################
Wire.begin();
Wire.beginTransmission(0b10010000);// ADS address
Wire.write(0b00000001);// pointer
Wire.write(0b11001011);// MSB
Wire.write(0b10000011);// LSB
Wire.endTransmission();// send Bytes
//####################### Unsuccessfully #################################

}

void loop(void)
{
  int16_t results = 0;
  float   multiplier = 0.015625;                                    // Set Multiplier according to the chosen gain
 
  results = ads.readADC_Differential_2_3();
  lcd.setCursor(0, 0);
  lcd.print("Counts : "); lcd.print(results);                  // Print to LCD the actual counts
  lcd.setCursor(0, 1);
  lcd.print("current: "); lcd.print(results * multiplier,3);     //Print to LCD the actual value determined by gain and multiplier
  delay(100);
}]
 

Online mikerj

  • Super Contributor
  • ***
  • Posts: 3238
  • Country: gb
Re: Talking to the ADS1115
« Reply #1 on: February 17, 2020, 01:09:47 pm »
If you look at the Adafruit library code the problem is obvious; the config register is written every time you call readADC_SingleEnded(), readADC_Differential_0_1() or readADC_Differential_2_3() and the conversion speed is always set to 1600sps. 

If you want to be able to modify this speed then you will need to add a speed property get/set function to the class, and then modify the above functions to use the value saved by your speed property instead of the hardcoded 1600sps value.
 

Offline andymouseTopic starter

  • Contributor
  • Posts: 17
  • Country: gb
Re: Talking to the ADS1115
« Reply #2 on: February 17, 2020, 02:53:50 pm »
Hi,
Thanks very much for your answer, however this is above my skill set, the datasheet makes it seem relatively simple, and to a "programer " it probably is, but I havent reached this level yet, I will try to understand the terms you have used and see if I can suss it.

Thanks again
Andy
 

Online mikerj

  • Super Contributor
  • ***
  • Posts: 3238
  • Country: gb
Re: Talking to the ADS1115
« Reply #3 on: February 17, 2020, 07:22:53 pm »
Where are you getting your library from?  The one on the Adafruit website is the one I was looking at which includes the hardcoded sample rate.  There is a different ADS1115 library on GitHub that includes a function setSPS() to set the sample rate.  The rest of the functions have the same names so you should be able to drop this straight into your project.
 
The following users thanked this post: andymouse


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf