Reading 7 external voltages

Hi

I'm extremely new to this and like most I try to learn by playing with other peoples code.

I want to read 7 voltages from an external battery bank which has 7 cells.

I found a great video from Andy Cartwright on YouTube whick allowed me to read 4 voltages using an ESP32 Dev Board and an Adafruit 1115 ADC module. Fig 1

Andy Cartwright video

I know you can use 2 Adafruit 1115 ADC modules by using different jumper connections on the ADDR pin but I do not know how to adjust the code to read from the 2nd ADC Fig2

Fig 1

Fig2

Serial output
Cell 1: 537.00
Cell 2: 546.00
Cell 3: 522.00
Cell 4: 522.00
Cell 5: 0.00
Cell 6: 0.00
Cell 7: 0.00

Code for 4 inputs

#include <Wire.h>
#include <Adafruit_ADS1X15.h>

Adafruit_ADS1115 ads; /* Use this for the 16-bit version */

void setup(void)
{
Serial.begin(115200);
Serial.println("Hello!");

Serial.println("Getting single-ended readings from AIN0..3");
Serial.println("ADC Range: +/- 6.144V (1 bit = 3mV/ADS1015, 0.1875mV/ADS1115)");

// The ADC input range (or gain) can be changed via the following
// functions, but be careful never to exceed VDD +0.3V max, or to
// exceed the upper and lower limits if you adjust the input range!
// Setting these values incorrectly may destroy your ADC

ads.setGain(GAIN_TWOTHIRDS); // 2/3x gain +/- 6.144V 1 bit = 0.1875mV (default)

ads.begin();
}

void loop (void)
{
int16_t adc0, adc1, adc2, adc3;

adc0 = ads.readADC_SingleEnded(0);
adc1 = ads.readADC_SingleEnded(1);
adc2 = ads.readADC_SingleEnded(2);
adc3 = ads.readADC_SingleEnded(3);

float fadc0, fadc1, fadc2, fadc3;

fadc0 = adc0 * 0.1875;
fadc1 = adc1 * 0.1875;
fadc2 = adc2 * 0.1875;
fadc3 = adc3 * 0.1875;

Serial.print("Cell 1: "); Serial.println(String(fadc0));
Serial.print("Cell 2: "); Serial.println(String(fadc1));
Serial.print("Cell 3: "); Serial.println(String(fadc2));
Serial.print("Cell 4: "); Serial.println(String(fadc3));
Serial.println(" ");

delay(1000);
}

Modified code for 7 inputs

#include <Wire.h>
#include <Adafruit_ADS1X15.h>

Adafruit_ADS1115 ads; /* Use this for the 16-bit version */

void setup(void)
{
Serial.begin(115200);
Serial.println("Hello!");

Serial.println("Getting single-ended readings from AIN0..3");
Serial.println("ADC Range: +/- 6.144V (1 bit = 3mV/ADS1015, 0.1875mV/ADS1115)");

// The ADC input range (or gain) can be changed via the following
// functions, but be careful never to exceed VDD +0.3V max, or to
// exceed the upper and lower limits if you adjust the input range!
// Setting these values incorrectly may destroy your ADC

ads.setGain(GAIN_TWOTHIRDS); // 2/3x gain +/- 6.144V 1 bit = 0.1875mV (default)

ads.begin();
}

void loop (void)
{
int16_t adc0, adc1, adc2, adc3, adc4, adc5, adc6;

adc0 = ads.readADC_SingleEnded(0);
adc1 = ads.readADC_SingleEnded(1);
adc2 = ads.readADC_SingleEnded(2);
adc3 = ads.readADC_SingleEnded(3);
adc4 = ads.readADC_SingleEnded(4);
adc5 = ads.readADC_SingleEnded(5);
adc6 = ads.readADC_SingleEnded(6);

float fadc0, fadc1, fadc2, fadc3, fadc4, fadc5, fadc6;

fadc0 = adc0 * 0.1875;
fadc1 = adc1 * 0.1875;
fadc2 = adc2 * 0.1875;
fadc3 = adc3 * 0.1875;
fadc4 = adc4 * 0.1875;
fadc5 = adc5 * 0.1875;
fadc6 = adc6 * 0.1875;

Serial.print("Cell 1: "); Serial.println(String(fadc0));
Serial.print("Cell 2: "); Serial.println(String(fadc1));
Serial.print("Cell 3: "); Serial.println(String(fadc2));
Serial.print("Cell 4: "); Serial.println(String(fadc3));
Serial.print("Cell 5: "); Serial.println(String(fadc4));
Serial.print("Cell 6: "); Serial.println(String(fadc5));
Serial.print("Cell 7: "); Serial.println(String(fadc6));
Serial.println(" ");

delay(1000);
}

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

You will need to declare two instances of an ADS1115 and use begin to specify that one of them is at a different I2C address. Adafruit's tutorial has the details and example code.

1 Like

Thanks, I will try and find it

The voltages on the ADS1115 inputs MUST be between 0V and the ADS1115 supply voltage at all times.

You need differential reading, either per cell or in software by the voltage difference between 2 cells.

And you need voltage dividers to bring the full battery voltage down into the acceptable range, as @jremington pointed out already.

Right. got it thanks

Thanks

You can simply like whichever contribution was helpful.

int16_t adc0, adc1, adc2, adc3, adc4, adc5, adc6;

adc0 = ads.readADC_SingleEnded(0);
adc1 = ads.readADC_SingleEnded(1);
adc2 = ads.readADC_SingleEnded(2);
adc3 = ads.readADC_SingleEnded(3);
adc4 = ads.readADC_SingleEnded(4);
adc5 = ads.readADC_SingleEnded(5);
adc6 = ads.readADC_SingleEnded(6);

float fadc0, fadc1, fadc2, fadc3, fadc4, fadc5, fadc6;

fadc0 = adc0 * 0.1875;

You really, really need to learn to use arrays. Otherwise your entire sketch is going to be 7 times longer than it should be!

For example the above can be shortened to

int16_t adc[7];

for (byte c=0; c<7; c++) adc[c] = ads.readADC_SingleEnded(c);

float fadc[7];

for (byte c=0; c<7; c++) fadc[c] = adc[c] * 0.1875;

Hi, @bobbych
Can you post a schematic showing how you will connect the ADCs to the batteries and to the ESP32.
Please include the batteries and all their connection.

PLEASE use a pen(cil) and paper to draw your diagram, labelling all components and pin names.

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.