Talking to the ADS1115 - Page 1
Forum section: electronics / beginners

author: andymouse
author_rank: Contributor
timestamp: February 17, 2020, 10:16:42 am
content: Code: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, alsoI 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 sketchworks 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.0078125mVlcd.begin(16, 2);ads.begin();lcd.setBacklight(1); // 0 = OFF 1 = ON//######################## Trying to talk to ADS1115 ####################Wire.begin();Wire.beginTransmission(0b10010000);// ADS addressWire.write(0b00000001);// pointerWire.write(0b11001011);// MSBWire.write(0b10000011);// LSBWire.endTransmission();// send Bytes//####################### Unsuccessfully #################################}void loop(void){int16_t results = 0;float multiplier = 0.015625; // Set Multiplier according to the chosen gainresults = ads.readADC_Differential_2_3();lcd.setCursor(0, 0);lcd.print("Counts : "); lcd.print(results); // Print to LCD the actual countslcd.setCursor(0, 1);lcd.print("current: "); lcd.print(results * multiplier,3); //Print to LCD the actual value determined by gain and multiplierdelay(100);}]

author: mikerj
author_rank: Super Contributor
timestamp: February 17, 2020, 01:09:47 pm
content: 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.

author: andymouse
author_rank: Contributor
timestamp: February 17, 2020, 02:53:50 pm
content: 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 againAndy

author: mikerj
author_rank: Super Contributor
timestamp: February 17, 2020, 07:22:53 pm
content: 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 differentADS1115 libraryon 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.