The sketch works but I can’t change the gain setting on the A/D.
Relevant part of my sketch :
V=#include <Adafruit_ADS1015.h>
#include <Wire.h>
#include <LiquidCrystal.h>
Adafruit_ADS1015 ads1015;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup()
{
Serial.begin(9600);
lcd.begin(16, 2);
ads1015.begin();
ads1015.setGain(GAIN_TWOTHIRDS) ;
}
void loop()
{
delay(150);
int chgaReading = ads1015.readADC_SingleEnded(0);
float chgaVolts = chgaReading * 1.0 / 27.0 ;
lcd.setCursor(0, 0);
lcd.print ("+ A");
lcd.setCursor (1, 0);
lcd.print(chgaVolts);
Now from Adafruit
(http://learn.adafruit.com/adafruit-4-ch … rogramming)
Adjusting Gain
To boost small signals, the gain can be adjusted on the ADS1x15 chips in the following steps:
GAIN_TWOTHIRDS (for an input range of +/- 6.144V)
GAIN_ONE (for an input range of +/-4.096V)
GAIN_TWO (for an input range of +/-2.048V)
GAIN_FOUR (for an input range of +/-1.024V)
GAIN_EIGHT (for an input range of +/-0.512V)
GAIN_SIXTEEN (for an input range of +/-0.256V)
adsGain_t getGain(void)
Reads the current gain value (default = 2/3x)
adsGain_t gain = getGain();
void setGain(adsGain_t gain)
Sets the gain for the ADS1x15
Be careful to take note of the input voltage range when adjusting the gain or you can easilty destroy the ADC!
ads1015.setGain(GAIN_TWOTHIRDS); // 2/3x gain +/- 6.144V 1 bit = 3mV (default)
// ads1015.setGain(GAIN_ONE); // 1x gain +/- 4.096V 1 bit = 2mV
// ads1015.setGain(GAIN_TWO); // 2x gain +/- 2.048V 1 bit = 1mV
// ads1015.setGain(GAIN_FOUR); // 4x gain +/- 1.024V 1 bit = 0.5mV
// ads1015.setGain(GAIN_EIGHT); // 8x gain +/- 0.512V 1 bit = 0.25mV
// ads1015.setGain(GAIN_SIXTEEN); // 16x gain +/- 0.256V 1 bit = 0.125mV
Example
If we had an analog sensor with an output voltage ~1V (a TMP36, for example), we could set the gain on the ADC to GAIN_FOUR, which would give us a +/-1.024V range. This would push the 1V input signal over the entire 12-bit or 16-bit range of the ADC, compared to the very limited range 1V would cover without adjusting the gain settings
// Set the gain to 4x, for an input range of +/- 1.024V
// 1-bit = 0.5V on the ADS1015 with this gain setting
ads1015.setGain(GAIN_FOUR);
… but whether I enter TWOTHIRDS or ONE for ‘gain’ I get the same output.
I’m not sure if …
adsGain_t getGain(void)
or
adsGain_t gain = getGain()
is relevant : I tried but doesn’t work in my sketch.
(Thanks in advance.)