I tried to send "hello" from ESP8266 to Arduino MKR Fox 1200 with i2C protocol.
I connected SCL (D1 ESP8266) to SCL (D12 Arduino Fox) and SDA (D2 ESP8266) to SDA (D11 Arduino FOX) and Ground to ground.
The codes compile but nothing happened, I tried to add a Serial.print in the "while(Wire.available())" and it seems that it doesn't even go in.
I used those codes
For Arduino MKR Fox 1200 (master_receiver) :
#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);
}
For ESP8266 (slave_sender) :
#include <Wire.h>
#define SDA_PIN 2
#define SCL_PIN 1
const int16_t I2C_SLAVE = 8;
void setup() {
Wire.begin(SDA_PIN, SCL_PIN, I2C_SLAVE); // join i2c bus with address #8
Wire.onRequest(requestEvent); // register event
}
void loop() {
}
// 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 5 bytes
// as expected by master
}
Merci pour ta réponse.
ah oui désolé, l'interface en anglais m'a induite erreur.
Pour la bibliothèque, j'ai trouvé le code slave de l'ESP8266 dans les exemples présents dans l'IDE dans la catégorie ESP8266... J'ai donc pensé que c'était bon.