-->
Page 1 of 1

WeMos D1 Mini (ESP8266 Mod) - I2C Slave Mode not working.

PostPosted: Tue Dec 01, 2020 8:31 am
by rajhlinux
I have spent hours trying to figure out how I can get the "WeMos D1 Mini" to be in slave mode. For some reason it does not acknowledge any incoming data. From all the forums I read, everyone needs to make their own "special interrupt based I2C" code in order to make the esp8266 into slave mode since it is not supported officially.

So I have an Arduino Nano which is the master and it will be sending data to WeMos D1 Mini, but the example is not working what so ever.

Here is the code I'm using from "Arduino IDE 1.8.13" using the "ESP8266 core 2.7.4", it is the example code named "slave_receiver":

Code: Select all// 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
}


Any alternatives, working examples?

Thanks.