Re: i2c slave support
Posted: Fri Mar 03, 2017 6:52 am
I've been trying to get this to work by using the NodeMCU ESP8266 Development board using one ESP as the master and the other as the slave. I tried making the changes as in https://github.com/esp8266/Arduino/compare/master...bjoham:i2c_slave to no avail.
Code as follows :
Master:
Slave:
Help from anyone who has pulled this off would be great.
Code as follows :
Master:
Code: Select all
#include <Wire.h>
void setup() {
Wire.pins(5,4);
Wire.begin(8); // join i2c bus with address #8
Wire.onReceive(receiveEvent); // register event
Serial.begin(115200); // start serial for output
}
void loop() {
delay(100);
}
// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany) {
Serial.println("Received..");
/*
while (1 < Wire.available()) { // loop through all but the last
char c = Wire.read(); // receive byte as a character
Serial.print(c); // print the character
}
*/
int x = Wire.read(); // receive byte as an integer
Serial.println(x); // print the integer
}
Slave:
Code: Select all
#include <Wire.h>
void setup() {
Wire.pins(5,4);
Wire.begin(8); // join i2c bus with address #8
Wire.onReceive(receiveEvent); // register event
Serial.begin(115200); // start serial for output
}
void loop() {
delay(100);
}
void receiveEvent(int howMany) {
Serial.println("Received..");
/*
while (1 < Wire.available()) { // loop through all but the last
char c = Wire.read(); // receive byte as a character
Serial.print(c); // print the character
}
*/
int x = Wire.read(); // receive byte as an integer
Serial.println(x); // print the integer
}
Help from anyone who has pulled this off would be great.