ESp32c3 cannot detect i2c Address in deferent pin input

hello

i have proble to detect 2 i2c address in same time at deferent pin input

any one have solution ?

can you be more specific… what device what address what pins?

Hi there,
Post the code , using the code tags above </> paste it in there, others can read it easier and compile it as well.
are you naming the Pins in the i2c begin (X,Y) ?
HTH
GL :slight_smile: PJ
:v:

You need to use an I2C multiplexer. Grove - 8 Channel I2C Multiplexer/I2C Hub (TCA9548A) | Seeed Studio Wiki

2 Likes

Hi there,
Good Eye, (2) LOL I missed that
GL :slight_smile: PJ
:v:

So he is saying that he has two devices with same I2C address, Hence the I2C Multiplexor :+1:
He may want to look at the Espressif updated doc. HERE:
https://docs.espressif.com/projects/esp-idf/en/latest/esp32c3/api-reference/peripherals/i2c.html

1 Like

here is the code

#include “DFRobot_GP8302.h”

#include “ADS1X15.h”

ADS1115 ADS(0x48);

DFRobot_GP8302 module;

uint16_t dac;

float mA ;

float dispmA ;

float set;

float dac_4;

float dac_20;

float float_dac;

void setup(){

Serial.begin(115200);

Wire.begin();

while(!Serial){

}

Serial.print("I2C to 0-25 mA analog current moudle initialization … ");

uint8_t status = module.begin(); // use the pin used by the I2C Wire object of the MCU hardware by default

if(status != 0){

Serial.print("failed. Error code: ");

Serial.println(status);

Serial.println("Error Code: ");

Serial.println("\t1: _scl or _sda pin is invaild.");

Serial.println("\t2: Device not found, please check if the device is connected.");

while(1) yield();

}

Serial.println(“done!”);

module.calibration4_20mA(/dac_4 =/640, /dac_20 =/3235);

//uint16_t dac = module.output(4); //control the converter module to output a current of 10mA and return the corresponding DAC value

uint16_t dac = module.output(/*current_mA =**/4);

Serial.print(“DAC value: 0x”); Serial.println(dac, HEX);

module.store(); Serial.println(“Save current configuration.”); //the above current config will be saved and will not be lost after power off

}

float output_mA(dac);

void loop(){

mAread();

adc();

delay(500);

}

void mAread()

{

dac_4 =645;

dac_20 =3250;

module.calibration4_20mA(dac_4,dac_20);

mA = 20;

uint16_t dac = module.output(/*current_mA =**/mA);

float_dac = (float) dac;

dispmA = (((float_dac-dac_4)/(dac_20-dac_4))*16)+4;

Serial.println(“Save current configuration.”);

Serial.print(“DAC value: 0x”); Serial.println(dac);

Serial.print("mA value: "); Serial.println(dispmA);

delay(500);

}

void adc(){

ADS.begin();

ADS.setGain(0);

int16_t val_0 = ADS.readADC(0);

int16_t val_1 = ADS.readADC(1);

int16_t val_2 = ADS.readADC(2);

int16_t val_3 = ADS.readADC(3);

float f = ADS.toVoltage(1); // voltage factor

Serial.print("\tAnalog0: "); Serial.print(val_0); Serial.print(’\t’); Serial.println(val_0 * f, 3);

Serial.print("\tAnalog1: "); Serial.print(val_1); Serial.print(’\t’); Serial.println(val_1 * f, 3);

Serial.print("\tAnalog2: "); Serial.print(val_2); Serial.print(’\t’); Serial.println(val_2 * f, 3);

Serial.print("\tAnalog3: "); Serial.print(val_3); Serial.print(’\t’); Serial.println(val_3 * f, 3);

Serial.println();

delay(2000);

}

heres the output serial
DAC value: 0x3250
mA value: 20.00
Analog0: -101 -0.019
Analog1: -101 -0.019
Analog2: -101 -0.019
Analog3: -101 -0.019

the ADC cant read the voltage that i set @ analog1

Hi there,
Too many errors in the CUT & PASTE, You need to use the code tags above </> Paste it in there
Compile it to verify no Errors and then copy and paste it to the Tags.
for example the “” quote tags in there is not Ansi compatible. (“done!”); not the same as ("done!")
look closely.
HTH
GL :slight_smile: PJ
:v:

2 Likes

< #include “DFRobot_GP8302.h”
#include “ADS1X15.h”
ADS1115 ADS(0x48);
DFRobot_GP8302 module;
uint16_t dac;
float mA ;
float dispmA ;
float set;
float dac_4;
float dac_20;
float float_dac;
void setup(){
Serial.begin(115200);
Wire.begin();
while(!Serial){
}
Serial.print("I2C to 0-25 mA analog current moudle initialization … ");
uint8_t status = module.begin(); // use the pin used by the I2C Wire object of the MCU hardware by default
if(status != 0){
Serial.print("failed. Error code: ");

Serial.println(status);
Serial.println(“Error Code: “);
Serial.println(”\t1: _scl or _sda pin is invaild.”);
Serial.println("\t2: Device not found, please check if the device is connected.");

while(1) yield();
}
Serial.println(“done!”);
module.calibration4_20mA(/dac_4 =/640, /dac_20 =/3235);
//uint16_t dac = module.output(4); //control the converter module to output a current of 10mA and return the corresponding DAC value
uint16_t dac = module.output(/*current_mA =**/4);
Serial.print(“DAC value: 0x”); Serial.println(dac, HEX);
module.store(); Serial.println(“Save current configuration.”); //the above current config will be saved and will not be lost after power off

}

float output_mA(dac);
void loop(){
mAread();
adc();
delay(500);
}

void mAread()
{

dac_4 =645;
dac_20 =3250;
module.calibration4_20mA(dac_4,dac_20);
mA = 20;
uint16_t dac = module.output(/*current_mA =**/mA);
float_dac = (float) dac;
dispmA = (((float_dac-dac_4)/(dac_20-dac_4))*16)+4;
Serial.println(“Save current configuration.”);
Serial.print(“DAC value: 0x”); Serial.println(dac);
Serial.print("mA value: "); Serial.println(dispmA);
delay(500);

}

void adc(){
ADS.begin();
ADS.setGain(0);
int16_t val_0 = ADS.readADC(0);
int16_t val_1 = ADS.readADC(1);
int16_t val_2 = ADS.readADC(2);
int16_t val_3 = ADS.readADC(3);
float f = ADS.toVoltage(1); // voltage factor

Serial.print("\tAnalog0: “); Serial.print(val_0); Serial.print(’\t’); Serial.println(val_0 * f, 3);
Serial.print(”\tAnalog1: “); Serial.print(val_1); Serial.print(’\t’); Serial.println(val_1 * f, 3);
Serial.print(”\tAnalog2: “); Serial.print(val_2); Serial.print(’\t’); Serial.println(val_2 * f, 3);
Serial.print(”\tAnalog3: "); Serial.print(val_3); Serial.print(’\t’); Serial.println(val_3 * f, 3);
Serial.println();

delay(2000);

}
/>