Hello there, i am having problem in sending message from arduino uno to NODEMCU (i.e. MASTER=uno and SLAVE=nodemcu) through I2C communication protocol . The problem is that despite making right connections and writing the following code the wire.available function in nodemcu is continuously returning 0 . Due to this the code is not working .
MASTER CODE FOR ARDUINO ---->>>
#include <Wire.h>
void setup() {
// Start the I2C Bus as Master
Serial.begin(9600);
Wire.begin();
}
int x=0;
void loop() {
#include <Wire.h>
void setup() {
Serial.begin(9600); /* begin serial for debug /
Wire.begin(D1, D2);/ join i2c bus with SDA=D1 and SCL=D2 of NodeMCU */
}
void loop() {
Serial.print(Wire.available());
while(Wire.available()){
int c = Wire.read();
Serial.print(c);
}
Serial.println();
delay(1000);
}
Do i need to write any argument in the wire.begin() function in the UNO code ? I have assumed the nodemcu adress to be "8" and thus have used "8" as argument in the wire.transmission function in the UNO code . I have tried writing "8" as argument in the wire.begin function as well but found no change . The main problem i have is that the wire.available() function in nodemcu code is returning 0 , and thats why nodemcu is not able to take any message from arduino uno . Please help as soon as possible.
groundFungus:
The master should not have an address in the begin(). The slave has to have a address. See the NodeMCU docs for the begin() syntax.
Do you need level shifters between the 5V Uno and the 3.3V NodeMCU? Do you have pullup resistors on the SDA and SCL pins?
No, i didnt use any level shifters and pullup resisters because i have read at many places on the internet that the nodemcu pins are 5v tolerant and there is no problem in directly connecting it .
The main problem i have is that the wire.available() function in nodemcu code is returning 0 , and thats why nodemcu is not able to take any message from arduino uno .
bkirkby:
Did this ever get solved? I am having the same issue...
Here is a solution using NodeMCU1.0-12E Module (I2C Master) and Arduino DUE (I2C Slave). The Master sends the data byte 0x23; the slave receives it and shows on its Serial Monitor. The Master makes a request to the Slave for 1-byte data; in response, the Slave sends 0x45 which is received by the Master and is displayed on Serial Monitor. (The Wire.h Library curretly supports NodeMCU only as Master.)
1. The connection diagram between NodeMCU and DUE using I2C Bus
3. Upload Master sketch into NodeMCU. Bring in the Serial Monitor-1 (SM1)
4. Upload Slave sketch into DUE.
5. Reset the DUE; observe that the built-in LED (L) blinks. Bring in the Serial Monitor-2 (SM2).
6. Reset the NodeMCU; observe that 23 has papered on SM2.
BTW: I am not sure if the NodeMCU's pins are 5V tolerant or not; however, I replaced the DUE with UNO in the above setup; uploaded the sketches in the NodeMCU and UNO. The I2C Bus is found working and exchanging data.
Rohla:
Did anyone ever found out the problem? That is precisely my problem...
I dont see anywhere where the int x is changing. it is set to 0 when declared but never altered. so when the master sends out x it is always sending out 0.
MASTER CODE FOR ARDUINO ---->>>
#include <Wire.h>
void setup() {
// Start the I2C Bus as Master
Serial.begin(9600);
Wire.begin();
}
int x=0; <<<<<----Right here x is set to 0
void loop() {
Wire.beginTransmission( 8 );
Wire.write(x); // sends x <<<<<------ x is sent so 0 is sent
Wire.endTransmission(); // stop transmitting
delay(500);
}
<<<<<------- X is never ++, +1, or anything
SLAVE CODE FOR NODEMCU ---->>>>>
#include <Wire.h>
void setup() {
Serial.begin(9600); /* begin serial for debug /
Wire.begin(D1, D2);/ join i2c bus with SDA=D1 and SCL=D2 of NodeMCU */
}
void loop() {
Serial.print(Wire.available());
while(Wire.available()){ <<<<<<-------- X is received as 0
int c = Wire.read(); <<<<<<-------- C is declared as 0
Serial.print(c); <<<<<<-------- 0 is printed on monitor
}
Serial.println();
delay(1000);
}
In the example you have referred, the Node is Master and UNO is Slave; I have asked for an example where the case is opposite -- the UNO is Master and Node is Slave.