【发布时间】:2021-03-13 09:11:17
【问题描述】:
我花了几个小时试图弄清楚如何让“WeMos D1 Mini”进入从属模式。 由于某种原因,它不确认任何传入数据。从我阅读的所有论坛中,每个人都需要制作自己的“基于特殊中断的 I2C”代码,以使 esp8266 进入从模式,因为它不受官方支持。
所以我有一个 Arduino Nano 作为主机,它将向 WeMos D1 Mini 发送数据,但该示例无法正常工作。
这是我在“Arduino IDE 1.8.13”中使用“ESP8266 core 2.7.4”的代码,它是名为“slave_receiver”的示例代码:
// Wire Slave Receiver
// by devyte
// based on the example by Nicholas Zambetti <http://www.zambetti.com>
// Demonstrates use of the Wire library
// Receives data as an I2C/TWI slave device
// Refer to the "Wire Master Writer" example for use with this
// This example code is in the public domain.
#include <Wire.h>
#define SDA_PIN 4
#define SCL_PIN 5
const int16_t I2C_MASTER = 0x42;
const int16_t I2C_SLAVE = 0x08;
void setup() {
Serial.begin(115200); // start serial for output
Wire.begin(SDA_PIN, SCL_PIN, I2C_SLAVE); // new syntax: join i2c bus (address required for slave)
Wire.onReceive(receiveEvent); // register event
}
void loop() {
}
// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(size_t howMany) {
(void) howMany;
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 arduino-esp8266