Hello guys!
I have problem with I2C (esp8266 - 01 master and Arduino UNO slave).
Arduino send data to esp and its displayed on Serial, but when i tried to send data from esp to Arduino it wont work, from my perspective it looks like loop in ESP's code isn't working... Esp prints once "Hello Arduino" and nothing after that just code from Arduino.
Here is my ESP8266 01 Master code:
Code: Select all#include <Wire.h>
#define I2CAddressESPWifi 6
void setup()
{
Serial.begin(9600);
Wire.begin(0,2);
}
void loop()
{
Wire.beginTransmission(I2CAddressESPWifi);
Wire.write("Hello Arduino");
Wire.endTransmission();
delay(1);//Required. Not sure why!
Wire.requestFrom(I2CAddressESPWifi,10);
Serial.print("Received from Arduina:[");
while (Wire.available())
{
delay(1);
char c = Wire.read();
//int error = Wire.endTransmission(); I tried with or without this two lines but still not working
//Serial.print("error: " + error); I tried with or without this two lines but still not working
Serial.print(c);
}
Serial.println("]");
delay(500);
}
Here is my Arudino UNO Slave code:
Code: Select all#include <Wire.h>
#define I2CAddressESPWifi 6
void setup()
{
Serial.begin(9600);
Wire.begin(I2CAddressESPWifi);
Wire.onReceive(espWifiReceiveEvent);
Wire.onRequest(espWifiRequestEvent);
}
void loop()
{
delay(1);
}
void espWifiReceiveEvent()
{
Serial.print("Received from ESP [");
while (Wire.available())
{
char c = Wire.read();
Serial.print(c);
}
Serial.println("]");
}
void espWifiRequestEvent()
{
Wire.write("0123456789");
Serial.print("Sending to ESP:[");
Serial.print("0123456789");
Serial.println("]");
}
This is my Serial Monitor, but I have one note... I use only one USB cable so i have to switch wires after uploading code to ESP, keeping that on mind the first line is printed while wire aren't connected properly.
Serial Monitor print:
Code: Select allReceived from A⸮⸮⸮⸮ٕ⸮⸮from Arduina:[]
Received from ESP [Hello Arduino]
Sending to ESP:[0123456789]
Received from ESP [Hello Arduino]
Sending to ESP:[0123456789]
Received from ESP [Hello Arduino]
Sending to ESP:[0123456789]
Received from ESP [Hello Arduino]
Sending to ESP:[0123456789]
Received from ESP [Hello Arduino]
Sending to ESP:[0123456789]
Received from ESP [Hello Arduino]
Sending to ESP:[0123456789]
Received from ESP [Hello Arduino]
Sending to ESP:[0123456789]
Received from ESP [Hello Arduino]
Sending to ESP:[0123456789]
Received from ESP [Hello Arduino]
Sending to ESP:[0123456789]
Received from ESP [Hello Arduino]
Sending to ESP:[0123456789]