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
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);
}