Hi,
I used to use AT firmware on the ESP8266 to grab and post data using ThingSpeak. But because of their instability, I'm developping my own firmware, which will send back to the Arduino Strings if the Arduino requests it. In this case, the Arduino Uno is the Master and the ESP the slave.
The problem is that I don't know how to get SCL and SDA pins (I2C) on the ESP8266-01:
Using Rx and Tx pins doesn't seems to work.
There is a similar post here about using ESP as a master and Arduino as a slave: [Solved] ESP8266 to Nano I2C Problems. - Networking, Protocols, and Devices - Arduino Forum
But the guy actually used this line to set the SCL and SDA pins because the ESP is the master:
Wire.begin(0,2);//Change to Wire.begin() for non ESP.
And as my ESP is not the master, I must use this line:
Wire.begin(8); // join i2c bus with address #8
Here is the slave_sender and master_reader examples code in the Wire.h library:
Slave:
#include <Wire.h>
void setup()
{
Wire.begin(8); // join i2c bus with address #8
Wire.onRequest(requestEvent); // register event
}
void loop()
{
delay(100);
}
// function that executes whenever data is requested by master
// this function is registered as an event, see setup()
void requestEvent()
{
Wire.write("hello "); // respond with message of 6 bytes
// as expected by master
}
Master:
#include <Wire.h>
void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600); // start serial for output
}
void loop()
{
Wire.requestFrom(8, 6); // request 6 bytes from slave device #8
while (Wire.available()) // slave may send less than requested
{
char c = Wire.read(); // receive a byte as character
Serial.print(c); // print the character
}
delay(500);
}
I tried to use this line to set SCL and SDA to pin GPIO-0 and GPIO-2:
Wire.pins(0,2);
Wire.begin(8); // join i2c bus with address #8
But I didn't get any response from the ESP.
Do you guys have any suggestion? Thank you.