I2C communication btw esp8266 and arduino nano

Only an Arduino/microcontroller expert will know for certain when it is a good design to use 2+ microcontrollers in the same project. The expert will have carefully evaluated ways to avoid using 2+ microcontrollers and come to the conclusion that none of those solutions is better and simpler than using 2+ microcontrollers.

As a beginner, you should assume that it is always bad to use 2+ microcontrollers. If you cannot find a way to achieve your project with only 1 microcontroller, then you should ask for help from experts. They may recommend using 2+ microcontrollers, but probably they will know a better way that needs only 1.

When beginners try to use 2+ microcontrollers, the results are mostly the same. They cannot make it work and come to the forum asking for help to make communications work between the microcontrollers. The advice is almost always the same: use only 1 microcontroller, then there are no communication problems.

Sorry if this sounds like a lecture!

2 Likes

1. Practically, ESP8266 is 5V tolerant; so, it can be directly connected with 5V-devive Arduino NANO.

2. Connect ESP8266 (I2C Master) and Arduino NANO (I2C Slave). ESP8266 does not work as I2C Slave. The connections are:
ESP8266's D1 (SCL) ---------> NANO's A5 (SCL)
ESP8266's D2 (SDA) --------> NANO's A4 (SDA)
ESP8266's GND --------------> NANO's GND

3. Uplaod the following sketch in ESP8266 (I2C Master)

#include <Wire.h>

void setup()
{
  Serial.begin(115200);  // start serial for output
  Wire.begin(D2, D1); //SDA=D2, SCL=D1
}

void loop()
{
  Wire.requestFrom(8, 1);    // request 1-byte from slave device #8
  byte x = Wire.read();
  Serial.print("Reading 1-byte from SLave-1: ");
  Serial.println(x, HEX);
  //-----------------------
  delay(1000);
}

4. Uplaod the following sketch in NANO (I2C Slave)

#include <Wire.h>
 
void setup()
{
  Serial.begin(115200);
  Wire.begin(8);
  Wire.onRequest(sendEvent);
}

void loop()
{
 
}

void sendEvent()
{
  Wire.write(0x23);
}

5. Press REST Buttons of both ESP8266 and NANO.
6. Open Serial Monitor of i2C master at Bd = 115200.
7. Check that the following message appers on SM at 1-sec interva.

Reading 1-byte from SLave-1: 23
Reading 1-byte from SLave-1: 23
Reading 1-byte from SLave-1: 23

1 Like

Do you have the following gadgets to exchange data between ESP32-CAM Module and Arduino NANO using I2C Bus? If yes, then I can help you with connections and sketches.
1. Arduino NANO.
image

2. Level Shifter (ESP#@-CAM is strictly a 3.3V device; it's pins are not 5V tolerant).
image

3. USB/TTL adapter (Type: ESP32-CAM-MB) to uplaod sketch into ESp32-CAM Module.
image

4. ESP32-CAM Module.
image

2 Likes

Yes Sir they are taken 5V and 3.3V there is no power issue between them

Yes Sir I have all these gadgets except level shifter
Can you plz help to do I2C communication between them
I have Arduino nano, ESP32-CAM-MB and also ESP32-CAM module

Thanks Alot Dear for helping
It works but it have some issues it shows hex value mean FF
image

Dear Also the issue is when I want to write a String data and increase the number of bytes like 5 or 9 it shows me 255 like this
image

also when i print only x without Hex like
Serial.println(x);
it then shows me 255
can you plz tell me why it not displays the exact message as it is a number or as a string

No, it deos not work for you!

Upload the following sketches and check that the Serial Monitor of ESP8266 shows the following message; If not, check the connections and the continuity of the jumper wires:
I2C Device found at address: 0x8

Sketch for ESP8266:

#include<Wire.h>
byte busStatus;

void setup()
{
  Serial.begin(9600);
  Wire.begin(D2, D1);  //D2 = SDA, D1 = SCL
  for (int i2cAddress = 0x00; i2cAddress < 0x80; i2cAddress++)
  {
    Wire.beginTransmission(i2cAddress);
    busStatus = Wire.endTransmission();
    if (busStatus == 0x00)
    {
      Serial.print("I2C Device found at address: 0x");
      Serial.println(i2cAddress, HEX);
    }

    else
    {
      Serial.print("I2C Device not found at address: 0x");
      Serial.println(i2cAddress, HEX);
    }
  }
}

void loop()
{

}

Sketch for NANO:

#include <Wire.h>
 
void setup()
{
  Serial.begin(115200);
  Wire.begin(8);
  Wire.onRequest(sendEvent);
}

void loop()
{
 
}

void sendEvent()
{
  Wire.write(0x23);
}
1 Like

Perform Tutorial of post #28 first and then think on ESP32-CAM and NANO. In the meantime, you may collect the level shifter.

1 Like

Can this be without done by level shifter or the level shifter is must
Bcz It is not available right now

It shows me different addresses that IPC device not found and then the addresses end at one point
image

here it ends
image

cd y pl u fw !!

Do you understand what all these abreviations mean?
Surely not!

Start writing like an adult and use normal non-crippled words !

2 Likes

What are you talking about
let me know where I use them.
Also sorry if anything cause to heart you

1. Check the connection.
2. Check the continuity of evry jumper wires using DVM is sound mode.
3. Reprt the findings.

1 Like

The connections I made
GND to GND
D1 (ESP GPIO5) to A5 (Arduino)
D2 (ESP GPIO4) to A4 (Arduino)

After checking Voltages from DVM, the results I got below:
|3.65|A5|
|4.85|A4|
|3.66|D1|
|4.89|D2|

But the error remain same after resetting it shows me
I2C Device not found at address: 0x1
and end at
I2C Device not found at address: 0x7F

Not the voltage check; I said for continuity check of the jumper wires after removing them from the circuit. if the wire is ok, you will hear tiny tone.

1 Like

Oh Sorry
yes Sir I checked all the three wires they are okay
I hear continous sound of the wires when i checked them

Do not use Breadboard.

Repeat the tasks of post 28. If your NANO is not detected at address 8, then change the NANO and try againg. If the problem is still there, change ESP8266.

1 Like

Okay Sir I'll check when I, have 2nd arduino nano
Thank you very much for your efforts and responses Thanks Alot
I really happy to see that the seniors here like you to help us beginners
Really Helpful and again thank you very much for your precious time
I'll tell you very soon.

1 Like

Before you buy the second NANO, you may check that the present NANO is alright. Just uplaod a blink program from the IDE Examples and chcek that the onboard LED (L) is blinking at 1-sec interval.

1 Like