- Wed Feb 01, 2017 2:33 pm
#61890
I tried simple I2C communication between Arduino and ESP8266
Arduino ESP8266
Pin 4 GPIO_0
Pin 5 GPIO_2
In addition, CH_PD, VCC of ESP8266 connected to VCC (3.3v) and GND of ESP is connected to GND.
It seems that communication is not happening.
Wire.avaialbale() is returning 0 at both master esp and slave Arduino side ?
Any suggestion what mistakes I have done ??
//Slave side code
#include <Wire.h>
// Send variables
int Hint,Tint;
char msg[8];
byte one;
void setup() {
Serial.begin(115200);
Wire.begin(8); // join i2c bus with address #8
delay(100);
}
void loop() {
Wire.beginTransmission(8);
// THIS IS REQUIRED because in Wire.cpp, Wire.begin() does not write if "transmitting" flag is not SET to 1. "transmitting" flag is SET to 1 from begin.Transmission() function.
delay(10);
Wire.write("jyoti");
delay(1000);
Serial.println("starting");
Wire.requestFrom(8, 6);
while (Wire.available())
{
// slave may send less than requested
one = Wire.read();
Serial.println(one);
}
}
//ESP8266 as I2C master
#include <Wire.h>
float pfVcC,SensF,Hum,Temp;
byte four,three,two,one,four1,three1,two1,one1,four2,three2,two2,one2,four12,three12,two12,one12;
void setup() {
Serial.begin(115200); // start serial output
delay(1000); // Arduino Startup delay
Wire.begin(0,2); // start i2c bus
Serial.println("Started I2C Arduino Slave....Requesting Data...\r\n\r\n");
delay(1000);
}
void loop() {
delay(130); // Set this for the response time of Your Arduino Loop......
Wire.beginTransmission(8);
Wire.requestFrom(8, 5); // request 6 bytes from slave device #8
delay(1000);
while (Wire.available())
{
Wire.write("sharma");
// slave may send less than requested
one = Wire.read();
two = Wire.read();;
three = Wire.read();
four = Wire.read();
Hum = Wire.read();
Temp = Wire.read();
}
char c = Wire.read(); // receive a byte as character
}