nodemcu i2c to pro-mini

I’ve been trying all evening in total vain to get a pro-mini to communicate with a nodemcu via i2c. this comes after completely failed attempts to get a nodemcu to operate with an NRF24l01. so I thought, maybe I can just hook to radio up to the pro-mini, then have the mini communicate the relevant info to the nodemcu.

but nothing I’ve tried works. I can get two pro-minis to talk to each other right away, like its supposed to be. but the nodemcu won’t acknowledge anything being sent. I tried using a i2c scanner, and it wouldn’t detect anything there either. I’ve been using the example code that comes with the library.

Master Sender (the pro-mini)

#include <Wire.h>

void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
}

byte x = 0;

void loop()
{
Wire.beginTransmission(4); // transmit to device #4
Wire.write("x is "); // sends five bytes
Wire.write(x); // sends one byte
Wire.endTransmission(); // stop transmitting

x++;
delay(500);
}

Slave Receiver (nodeMCU)

#include <Wire.h>

void setup()
{
Wire.begin(2,14); // physical pins D4 and D5
Wire.onReceive(receiveEvent); // register event
Serial.begin(9600); // 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)
{
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 help would be greatly appreciated.

silly_cone: I've been trying all evening in total vain to get a pro-mini to communicate with a nodemcu via i2c. this comes after completely failed attempts to get a nodemcu to operate with an NRF24l01. so I thought, maybe I can just hook to radio up to the pro-mini, then have the mini communicate the relevant info to the nodemcu.

but nothing I've tried works. I can get two pro-minis to talk to each other right away, like its supposed to be. but the nodemcu won't acknowledge anything being sent. I tried using a i2c scanner, and it wouldn't detect anything there either. I've been using the example code that comes with the library.

Master Sender (the pro-mini)

Slave Receiver (nodeMCU) Any help would be greatly appreciated.

Don't know the NodeMCU, but where in your Slave code have you assigned its I2C address? In the master code you are sending to I2C device 4?

Have you changed the NodeMCU to Arduino environment, or is it still LUA?

Chuck.

I had a feeling that's a big part of the problem, that the slave has not been addressed. but where would you do that? The NodeMCU doesn't have established i2c pins like arduino, so you have to define them in the wire.begin() command. but that's also where you address the slave. so how do you do both?

silly_cone:
I had a feeling that’s a big part of the problem, that the slave has not been addressed. but where would you do that? The NodeMCU doesn’t have established i2c pins like arduino, so you have to define them in the wire.begin() command. but that’s also where you address the slave. so how do you do both?

The current Arduino port for EPS8266 DOES not support Slave mode. The Master mode is bit banged. No hardware support.

You are SOL, the Arduino Port of the ESP8266 does not support Slave Mode.

Chuck.

well that's not what I wanted to hear, haha.

How do you initialize it as a master?

Would you just enter the pins in the wire.begin() command? Then use addresses (like 4 in my example above) like usual to talk with the arduino slave?

Not exactly what I wanted, but I could make that work.

silly_cone: well that's not what I wanted to hear, haha.

How do you initialize it as a master?

Would you just enter the pins in the wire.begin() command? Then use addresses (like 4 in my example above) like usual to talk with the arduino slave?

Not exactly what I wanted, but I could make that work.

if you are using the default D4,D5 pins; You can just use Wire.begin();, or specify them.

I looked through the I2C implementation from ESP8266/Arduino on GitHub, it is a partial implementation. It does not support clock stretching very well, it codes a loop count to limit the time for an Stretched clock( it defaults to 230us). With hardware Slaves, it might work ok, but with an Arduino as a slave, the OnRequestEvent() call stretches the clock until your eventhandler returns. So, that gives you 3,680 CPU Clock cycles max to answer the RequestEvent(). Minus any instructions inside of WIRE.h.

Understand that you might want to call Wire.setClockStretchLimit(uint32_t); to increase this value if you get failures on the ESP8266.

Chuck.