Friday, August 15, 2014

4 Channel 16 Bit ADC Arduino / Raspberry Pi

The Arduino UNO has five 10 bit Analog to Digital Converter pins (0-1023), but I needed higher resolution. I'm working with a I2C connected 16 bit 4 channel ADC from Adafruit called the ADS1115. 16 bits of resolution allows me to measure signed integers with values ranging from negative 32768 through positive 32767 (-5v to +5v). Although I'm running this single ended (measuring 4 separate inputs in respect to ground), it can also run in a 2 channel differential mode. This would measure the voltage difference between AIN0 and AIN1, and between AIN2 and AIN3. I'm multiplying the value being reported by the ADC by .000188 (188uV / bit) to get the voltage being supplied to the input.

The Raspberry Pi has no ADC, and can only read digital inputs, so this would be a nice addition, as the Pi does have a I2C interface. I'll post an article on the code for doing this soon. Here is the code for the Arduino. Complete tutorial, connections, and library available at

#include <Wire.h>
#include <Adafruit_ADS1015.h>

Adafruit_ADS1115 ads1115;

void setup(void)

  Serial.println("Getting single-ended readings from AIN0..3");
  Serial.println("ADC Range: +/- 6.144V (1 bit =  188uV)");

void loop(void)
  int16_t adc0, adc1, adc2, adc3;
  float volt0, volt1, volt2, volt3;

  adc0 = ads1115.readADC_SingleEnded(0);
  adc1 = ads1115.readADC_SingleEnded(1);
  adc2 = ads1115.readADC_SingleEnded(2);
  adc3 = ads1115.readADC_SingleEnded(3);
  volt0 = adc0*0.000188;
  volt1 = adc1*0.000188;
  volt2 = adc2*0.000188;
  volt3 = adc3*0.000188;
  Serial.print("AIN0: ");
  Serial.print(" ");
  Serial.print(volt0, 4);
  Serial.println(" vdc");
  Serial.print("AIN1: ");
  Serial.print(" ");
  Serial.print(volt1, 4);
  Serial.println(" vdc");
  Serial.print("AIN2: ");
  Serial.print(" ");
  Serial.print(volt2, 4);
  Serial.println(" vdc");
  Serial.print("AIN3: ");
  Serial.print(" ");
  Serial.print(volt3, 4);
  Serial.println(" vdc");
  Serial.println(" ");