i am not able to communicate over i2c with my esp-01 as master and UNO as slave. i get special characters sent back to esp, but my esp is sending correctly... output on my esp-01 output on my UNO is
connections are esp-01 gpio-0 to uno A4 and gpio-2 to uno A5 is it because i am not using a level shifter or any mistake in my code..?
here is my esp master code
#include <Wire.h>
#define I2CAddressESPWifi 6
int x=32;
void setup()
{
Serial.begin(115200);
Wire.begin(0,2);//Change to Wire.begin() for non ESP.
}
void loop()
{
Wire.beginTransmission(I2CAddressESPWifi);
Wire.write(x);
Wire.endTransmission();
x++;
delay(1);//Required. Not sure why!
Wire.requestFrom(I2CAddressESPWifi,10);
Serial.print("Request Return:[");
while (Wire.available())
{
delay(100);
char c = Wire.read();
Serial.print(c);
}
Serial.println("]");
delay(500);
}
and here is my Uno slave code
#include <Wire.h>
#define I2CAddressESPWifi 6
void setup()
{
Serial.begin(115200);
Wire.begin(I2CAddressESPWifi);
Wire.onReceive(espWifiReceiveEvent);
Wire.onRequest(espWifiRequestEvent);
}
void loop()
{
delay(1);
}
void espWifiReceiveEvent(int count)
{
Serial.print("Received[");
while (Wire.available())
{
char c = Wire.read();
Serial.print(c);
}
Serial.println("]");
}
void espWifiRequestEvent()
{
String ts = getTime();
Serial.print("Sending:[");
Serial.print(ts.c_str());
Serial.println("]");
Wire.write(ts.c_str());
}
String getTime(){
int sec = millis() / 1000;
int min = sec / 60;
int hr = min / 60;
String ts = "U:";
if (hr<10) ts+="0";
ts += hr;
ts +=":";
if ((min%60)<10) ts+="0";
ts += min % 60;
ts +=":";
if ((sec%60)<10) ts+="0";
ts += sec % 60;
return(ts);
}