-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Open
Description
With added support for i2c slave from here by @bjoham, after modifying all files.
Master (ESP8266)
#include <Wire.h>
int x = 3;
void setup() {
Wire.pins(4,5);
Wire.begin(); // join i2c bus (address optional for master)
Wire.beginTransmission(8); // transmit to device #8
Wire.write(x); // sends one byte
Wire.endTransmission(); // stop transmitting
}
void loop() {
}
Slave (ESP8266)
#include <Wire.h>
int x = 3;
void setup() {
pinMode(D0,OUTPUT);
Wire.pins(4,5);
Wire.begin(8); // join i2c bus with address #8
Wire.onReceive(receiveEvent); // register event
//Serial.begin(9600); // start serial for output
// Serial.println("Got something?");
digitalWrite(D0,LOW);
}
void loop() {
delay(100);
if (x == 3) {
digitalWrite(D0, HIGH);
}
//If value received is 3 blink LED for 400 ms
if (x == 0) {
digitalWrite(D0, LOW);
}
}
// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany) {
x = Wire.read(); // read one character from the I2C'
}
I have connected pins D1,D2,GND on both the boards(NodeMCU).
This doesn't seem to work. Any help will be appreciated.
Metadata
Metadata
Assignees
Labels
No labels