【问题标题】:ESP8266 to ESP8266 i2C CommunicationESP8266 到 ESP8266 i2C 通信
【发布时间】:2017-07-16 06:25:21
【问题描述】:

我正在尝试让我的 ESP8266 连接并通过 i2c 总线发送消息。我正在使用 NodeMcu 开发板。 D1、D2 和 GND 引脚相互连接。

我主人的代码是:

#include <Wire.h>

void setup() {
  Wire.begin(D1,D2); // join i2c bus (address optional for master)
  Serial.begin(115200); 
}

byte x = 0;

void loop() {

 Wire.beginTransmission(8);
  Wire.write(x);              // sends one byte
  Wire.endTransmission();    // stop transmitting
    Serial.println("Transmitted");
  x++;
  delay(500);
}  

我的从属 ESP 上的代码是:

#include <Wire.h>

void setup() {
  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
}

运行此程序不会在接收器芯片上产生任何输出。

【问题讨论】:

标签: arduino esp8266 i2c


【解决方案1】:

正如 cmets 中所述,它看起来不支持 I2C,但您可以使用 PJON

您只需要连接一根线即可启用两个设备之间的通信

【讨论】:

    【解决方案2】:

    我不确定,但我希望 Arduino 的 Wire 库将硬件 I2C 控制器用于 ATMega。 Espressif 固件中的 I2C 驱动程序似乎正在通过 GPIO 执行 I2C,这表明 ESP 上没有硬件控制器(无论如何它们相同的几率是多少)。所以你需要使用 Wire.h 以外的东西,因此我建议 - 尝试为你的 Arduino IDE 下载一些通过 GPIO 伪造 I2C 的东西。就像this .. 也许,我还没有尝试过。我不知道一个完整的解决方案,但也许至少这会有所帮助.. 祝你好运!

    【讨论】:

      【解决方案3】:

      ESP8266(I2C Master) 到 ESP8266(I2C Slave) works 从 2.5.0 版本开始。看看我的cmetson the ESP8266 GitHub

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-07-06
        • 2016-06-11
        • 2020-03-04
        • 1970-01-01
        • 1970-01-01
        • 2017-07-19
        • 1970-01-01
        相关资源
        最近更新 更多