I bought Pimoroni breakout board based on ADS1015 Texas Instruments 12 bit ADC, it has capability of measuring 24V voltage. Problem is that I want to use Arduino board for the measurement and Pimoroni only shares Python code for their product. I thought that if it is based on ADS1015, I can use any Arduino library for ADS1015 and it should be working… and it is, sort of. I used a couple of libraries, and there is practically the same case. As I understand for voltage 0 V the output should be around 0 bytes. For different libraries the output is different and certainly is not 0. I attach Arduino program for Sparkfun library (I tried also Adafruit, and Rob Tilaart library).
The output for 0V, both wire connected to GND on Arduino: 1183.
The output for 3.3V, one wire connected to 3.3V on Arduino, second to GND: 1340.
The output for 5V, one wire connected to 5V on Arduino, second to GND: 1420.
Therefore for 0V to 3.3V -> 3.3V/(1340-1183)=3.3V/157=0.021 V/bit
For 3.3 to 5V ->(5-3.3)/(1420-1340)=1.7 V/80=0.0212 V/bit
So the formula: (channel_A3-1183)*0.021 works. Why is it not symmetrical, I mean it should be 0 for 0V, 2048 for 24V and -2048 for -24V, why is not the case, is it the issue with reading the I2C signal?
uint16_t channel_A3 is an unsigned integer and cannot represent negative numbers.
I'd have expected a 12bit ADC to output a range 0 to 4095. If it is capable of handling negative voltages, then 0 volts would be mid scale at 2047.
Post code as text, not pictures.
Hello All,
thank You for your answers, first of all single-ended measurement just seems to have not symmetrical output, therefore I have changed code to differential between A0 and A1 channels:
#include <SparkFun_ADS1015_Arduino_Library.h> //Click here to get the library: http://librarymanager/All#SparkFun_ADS1015
#include <Wire.h>
ADS1015 adcSensor;
void setup() {
// put your setup code here, to run once:
Wire.begin();
Serial.begin(19200);
if (adcSensor.begin() == true)
{
Serial.println("Device found. I2C connections are good.");
}
else
{
Serial.println("Device not found. Check wiring.");
while (1); // stall out forever
}
adcSensor.setGain(ADS1015_CONFIG_PGA_4);
}
void loop() {
// put your main code here, to run repeatedly:
int16_t channel_A0 =adcSensor.getDifferential();
Serial.print("A0_raw: ");
Serial.println(channel_A0);
Serial.print("A0:");
Serial.println(channel_A0*0.02125);
delay(500); // avoid bogging up serial monitor
}
Now, it is symmetrical. Different output from different ADS1015 libraries is caused by different default gains.
I have chosen +/- 1.024v which gives the best resolution around 0.011V/bit, but for 24 V it goes slightly above the maximum value, the reason is before feeding to ADS1015, voltage is divided from 24V to 1.14V so slightly higher than 1.024 V.