Arduino Stack Exchange is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 esp-01 output on my UNO is output on my UNO

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);
}
share|improve this question
    
Pullup resistors? – Mikael Patel Feb 4 at 12:57
    
no... why should I ? and between what? – Vallabh Rao Feb 4 at 13:00
    
Try choosing an address that isn't reserved for special purposes. One that is between 8 and 119 inclusive. – Majenko Feb 4 at 14:46
    
I tried 15, that didn't make any difference... :( – Vallabh Rao Feb 4 at 15:43
    
Pullup resistors on the I2C bus (SDA, SCK) is required if not provided on the board. Check the I2C specification. – Mikael Patel Feb 4 at 16:43
up vote 0 down vote accepted

Perhaps the Serial.print()s in the slave's request event function are causing too much delay (clock stretching?). You should make the Wire.write() the second statement in that function right after the getTime call. Or you could use Wire.write("Hello") as the only statement in the function, so you can narrow down the problem.

share|improve this answer
    
thanks a lot.. it worked... – Vallabh Rao Feb 6 at 12:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.