Hello All
I am still trying to get my battery voltage readings sorted and now i am very close as one reading is very accurate . But having trouble getting the second reading . I am using An ESP32 with 2 X ADS1115
Can you please take a look at my code and see if you advise why i am only getting one reading
//#include <Adafruit_ADS1X15.h>
#include<ADS1115_WE.h>
#include<Wire.h>
#define I2C_ADDRESS_1 0x48
#define I2C_ADDRESS_2 0x49
ADS1115_WE adc_1 = ADS1115_WE(I2C_ADDRESS_1);
ADS1115_WE adc_2 = ADS1115_WE(I2C_ADDRESS_2);
void setup() {
Wire.begin();
Serial.begin(115200);
if(!adc_1.init()){
Serial.print("ADS1115 No 1 not connected!");
}
adc_1.setVoltageRange_mV(ADS1115_RANGE_6144);
adc_1.setMeasureMode(ADS1115_CONTINUOUS);
adc_1.setCompareChannels(ADS1115_COMP_0_GND);
if(!adc_2.init()){
Serial.print("ADS1115 No 2 not connected!");
}
adc_2.setVoltageRange_mV(ADS1115_RANGE_6144);
adc_2.setMeasureMode(ADS1115_CONTINUOUS);
adc_2.setCompareChannels(ADS1115_COMP_0_GND);
}
void loop() {
float voltage = 0.0;
voltage = adc_1.getResult_V();
Serial.println("Voltage [V], ADS1115 No 1: ");
Serial.println(voltage);
voltage = adc_2.getResult_V();
Serial.println("Voltage [V], ADS1115 No 2: ");
Serial.println(voltage);
Serial.println("****************************");
delay(1000);
}
Thanks
johnnyregs:
having trouble
What trouble? What do you mean, "get one reading"? If the reading that you get is not what you expect, how does it differ?
how much i2c ports has ESP32 ? on which pins?
We are only getting a reading of 2.5 volts on ADC one and 0.00 on Adc2
We are using pin 21 and 22 and 17 and 18 .
Why are you doing that? Why aren't both devices on the same I2C bus?
I did try putting both on 21 and 22 but still only received reading on ADC one
When you used an I2C scanner what address did you get for the connected I2C devices?
I did not try the I2C scanner as i was not aware of it
The Arduino ESP32 core does not automatically know about the 2nd I2C buss of the ESP32. The programmer would need to setup the 2nd I2C buss for the Arduino I2C core to use. It's possible but just put both devices on the same I2C bus and use the I2C scanner to see if BOTH devices show up.
When i do put both ADS1115 on pins 21 and 22 my 2.5volt reading goes away .
Did the I2C scanner ID both devices? What were the devices ID's as detected by the I2C scanner?
Try them one-at-a-time with the I2C Scanner.
at the moment i have an error using the i2c scanner code
You have to set the two ADS1115 to have different I2C addresses using the ADDR pin, and address them one at a time. See the data sheet.
If the I2C scanner will not detect the devices the program, you are trying to run will NOT detect the I2C devices.
is there a i2c scanner code for the esp32 ?
I've not needed to run a specific I2C scanner for the ESP32's but what happened when you tried using the internet to do you own research on words like "esp32 i2c scanner"?
The Arduino programming language Reference, organized into Functions, Variable and Constant, and Structure keywords.
ok thanks i have installed that library just trying again