Can't get I2C To Work

Hi. I'm new to this forum and just bought a Nano ESP32 but I can't get it to work with a DFRobot DS1307 Module: nor a MAX7311 I/O Expander

I want to scan the address of my I2C devices and it's not happening.
Here is my super basic code that I was able to run successfully with an UNO R4 but no luck with Nano ESP32.

#include <Wire.h>
byte error = 0;

void setup(){
    Wire.begin();
    Serial.begin(115200);
}

void loop(){
    for(byte x = 0x00; x= 0x77; x++){
    Wire.beginTransmission(x);
    error = Wire.endTransmission();
    if(error == 0){
    Serial.print("address: ");
    Serial.println(x);
    }else(Serial.println(error));
    }
}

It keeps giving me error 2, which I believe is the "ESP_FAIL" message.

I have a 4.7k pullup resistors for both SDA and SCL pins to 3.3V pin on both DS1307 and MAX7311. VCC = 3.3V for MAX7311 and 5V for DS1307.

I have checked the connections multiple times and about to lose my hair overthinking about this. What am I missing? Please help. Thank you.

Try removing one set of pull up resistors. Also verify those modules do not already have them installed. Put these two lines of code in your program and see what you get.

    Serial.print(SCL);
    Serial.print(SDA);

Then check to see if that is the pins you used. This works on the Arduino's I use.

Hi @wanmax
the fact that you do not get any feedback to your problem seems to be the way how you post it.
Looks like few people see what your problem is, at least I don´t. Can you explain what you want to do with the I2C line ?
can you please post your code properly in this forum. In the IDE you can mark all you want to publish and choose "copy to forum" instead of just "copy"

1 Like

actually, if you just want to check if the connections via I2C to your devices are working you can run the simple example WireScan from the library. If this does not find any connected devices then you have a HW-problem.

Please read this important information on how to use this forum.
Posting images of code is not acceptable.

2 Likes

Hi. Sorry I'm new here but that's not an excuse. I delete the photo and replaced it with the code. Thank you for the reminder.

1 Like

Yes. That's on me. Thank you for the "copy" tip. I did not know that.

I want a proper response from an I2C device. In this case, as simple as getting its address by scanning.

Have you tried it without the DS1307 hardware and code, and vice versa?

Update: I tried running I2Cdetect by Mike Causer and I'm still not able to detect the address of my DS1307 using the Nano ESP but no problem with UNO R4. I can confidently say that it's not a connection problem. I'm using the same connections, components, wires, USB cable and still, only the UNO works - it prints out the correct address "0x50", in my case. I also tried different NANO ESP boards and they giving the same response - all "--".

please upload pictures so we can see your actual wiring.
Each component - each wire must be visible.

The Uno is a 5V device and the Nano ESP32 is a 3.3V device, so you must have them connected differently.

Are you powering the modules with 3.3V or 5V?
They must be powered by 3.3V when using the Nano ESP.
If the modules require 5V, then you MUST use voltage translators when connected to the ESP
Make sure there are only one set of pull-up on the I2C bus.

With that in mind, read the DS1307 datasheet.

1 Like