ADS1115 ADC checkout – #1

I have application for an analogue to digital converter (ADC) in a noisy environment, so a possible solution is to place an ADC module very close to the analogue sensors and use some form of digital connection back to a microcontroller. A possible protocol is I2C, and has the advantage that several ADC modules can be attached to the same bus, along with other peripherals Eg LCD.

ads1115-00The above ADS1115 modules have four input channels, 16 bit conversion, flexible input mux, and were available on eBay for less than A$4, so worth a try.

A quick search reveals Adafruit sell something similar and have published an Arduino library for the devices.

Next step is to test one of the examples, straight from the repo. So, the repo was cloned to my Arduino library folder and the single ended example copied to a source folder and compiled and loaded.

ads1115-01Above is the test framework, an Arduino Pro 16MHz 5V board with FTDI adapter for programming and IO, to the left a 5V/3V converter, and to the left the ADS1115 module on 3.3V (it can run on 5V, but I wanted to test it on 3.3V). Ain1P is grounded, the other inputs left floating.

screenshot-27_10_16-10_11_19Above is a capture of the I2C commands to set the config register to read Ain1P against ground.

screenshot-27_10_16-10_08_42

A few ms later, the read of the ADC register for Ain1P, and there it is, data is 0x00.

ads1115-03

Above is the breadboard with added I2C LCD, a 10k/3950 thermistor with 22k series resistor from 3V and code to sample, average 10 samples, calculate and display temperature on the LCD (and logged to the serial port).

//Thermometer example
//Owen Duffy 2013/02/24
//I2C LCD variation


#define VREF 2.048
#define VCC 3.13
#define R0 10000
#define T0 (25.0+273.15)
#define Beta 3950
#define Rb 22000
#define AVG 10
#define DISSFACT 0.0

/*
  The circuit:
 * 1k0 from +5V to A0, NTC201 thermistor to GND
 */

// include the library code:
//#define _BV(x) (1<<(x))
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
#include <Adafruit_ADS1015.h>

Adafruit_ADS1115 ads;  /* Use this for the 16-bit version */
int sensorPin=A0; // select the input pin for the thermistor
long AdcAccumulator; // variable to accumulate the value coming from the sensor
float vin;
float rt;
float temperature;
float self=0;
int i;

// initialize the library with the numbers of the interface pins
LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7,3,POSITIVE);  // Set the LCD I2C address
void setup(){
//  analogReference(INTERNAL);
  //set up the LCD number of columns and rows: 
  lcd.begin(16, 2);
  
  // start serial port at 9600 bps and wait for port to open:
  Serial.begin(9600);
 // while (!Serial) {;} // wait for serial port to connect. Needed for Leonardo only
  ads.setGain(GAIN_TWO);        // 2x gain   +/- 2.048V  1 bit = 1mV      0.0625mV
  ads.begin();
  }

void loop() {
  AdcAccumulator=0;
  for(i=AVG;i--;){
    // read the value from the thermistor:
    AdcAccumulator+=ads.readADC_SingleEnded(0);
    delay(100);
    }
  // calculate average vin
  vin=AdcAccumulator/32768.0*VREF/AVG;
  //calculate rt
  rt=vin/((VCC-vin)/Rb);
  //calculate self heating
  //self=vin*vin/rt/DISSFACT;
  //calculate temperature
  temperature=1/(log(rt/R0)/Beta+1/T0)-273.15-self;
  
  // Print a message to the LCD.
  lcd.clear();  
  lcd.print("Thermistor #1:");
  lcd.setCursor(0, 1);
  lcd.print("Temp: ");
  lcd.print(temperature,1);
  lcd.print("\xb0" "C"); //ROM A02
//  lcd.print("\xdf" "C"); //ROM A01
//  lcd.print("C");
  
  if(Serial.available()<=0){
    Serial.println(temperature); //send
    }
  }

Above is the prototype code.

screenshot-29_10_16-17_58_49

Above is a I2C bus trace of 10 measurements then the LCD output.