esp8266 / esp8266/Arduino

ESP8266 to ESP8266 i2c

Open
#3,046 10 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
16.7k
Forks
13.1k
PR merge metrics
No merged PRs in 30d

Description

With added support for i2c slave from [here](https://github.com/esp8266/Arduino/compare/master...bjoham:i2c_slave) by @bjoham, after modifying all files.

Master (ESP8266)
```
#include

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

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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.