It looks simple, dealing with I2c communication of Arduino and a Sensor. What if we use two controllers:
My Arduino does some calculations and produces different messages which can be directed to the serial port by Serial.print (...). A NodeMcu is supposed to read those occasional messages, immediately after they are produced by Arduino. Therefore, NodeMcu shouldn't request for data independently.
There are posts where they consider Arduino as Slave and request/read Arduino's data. However, I want Arduino to be a Master and to be read by NodeMcu.
How can I use I2c to transmit the data to NodeMcu to be printed out by NodeMcu? Do I need extra interrupt or wire.h can do this?
I'm confused Do you want the NodeMCU to be a I2C Master or Slave or should it read data from a Serial RX/TX bus ?
Can a NodeMCU be a I2C Slave ? I don't think so.
When both the Arduino and the NodeMCU are Master, then it can go wrong.
By the way, the Arduino can be Slave and Master at the same time without problem.
I think it is easer when the NodeMCU receives Serial data from the Arduino.
The NodeMCU has three ways to read Serial messages:
Use the normal serial port, they can be set on other pins during setup. The TX2 can then be used to send messages to the serial monitor with help of a extra resistor.
SoftwareSerial seems to work on a NodeMCU.
OTA. Use OverTheAir update of the sketch, and you can use the serial port for other things. There is telnet addition to be able to send debug messages to the computer.
Or you can buy a ESP32. I think it has three serial ports, but I have not tried to use all three yet. At least you don't have to go through all that trouble to use a serial port with the NodeMCU.
The Wire-compatible library for the ESP8266 was a software implementation that did not support I2C Slave mode.
The development environment for the ESP8266 is now at 2.7.1 and the I2C Slave mode was added with version 2.5.
From what I read, there are still many issues