Transmitting data from nodeMCU to Arduino UNO using I2C

I'm trying to send data from nodeMCU to arduino uno using I2C and need help in writing code.

here is the condition I need to implement.

Is the Arduino a 3.3 or 5v version ?
Is the NodeMCU running the Arduino framework?

1 Like

Previous post may be useful:
I2C communication between nodeMCU and arduino uno - Using Arduino / Programming Questions - Arduino Forum

more:
nodeMCU + Arduino + "I2C" at DuckDuckGo

If these devices are close to a meter apart seriously consider some sort of communications that is designed for this type of application, I2C is not.

Hello all, thanks for your reply, I managed to write one code for testing purpose, here it is:

#include <Wire.h>
#include <Adafruit_ADS1X15.h>
Adafruit_ADS1015 ads;     /* Use thi for the 12-bit version */

#define SDA_PIN 4
#define SCL_PIN 5

const int16_t I2C_MASTER = 0x42;
const int16_t I2C_SLAVE = 0x08;

double  calibrationv; //used to store calibrated value
int sensorcheck=0;//to check health on sensor. If value is 0 sensor works, if value is 1 sensor out of range or not connected
int Sensor_lowrange=58;//When sensor is healthy and new it reads 58 on low
int Sensor_highrange=106;//When sensor is healthy and new it reads 106 on high
int current_function=0;

String IP_Addr = "192.168.1.4";
double O2Purity = 0.0;
double temprature = 0.0;
double flowRate = 5.0;

int calibrate(){
  int16_t adc0=0;
  int result;
  for(int i=0; i<=19; i++)
       {
         adc0=adc0+ads.readADC_SingleEnded(0);
       }
  
  result=adc0/20;
  return result;
}

void transmitData()
{
  String variable1_str = String(O2Purity);
  String variable2_str = String(temprature);
  String variable3_str = String(flowRate);
  Wire.beginTransmission(9);
  Wire.write(IP_Addr.c_str(), IP_Addr.length() + 1);
  Wire.write(variable1_str.c_str(), variable1_str.length() + 1);
  Wire.write(variable2_str.c_str(), variable2_str.length() + 1);
  Wire.write(variable3_str.c_str(), variable3_str.length() + 1);
  Wire.endTransmission();
}

void updateO2Value()
{
    int16_t adc0=0;
    double currentmv; //the current mv put out by the oxygen sensor;
    double calibratev;
       //taking 20 samples. The sensor might spike for a millisecond. After we average the samples into one value
    for(int i=0; i<=19; i++)
      {
        adc0=adc0+ads.readADC_SingleEnded(0);
      }
    currentmv = adc0/20;
    calibratev=calibrationv;
    O2Purity=(currentmv/calibratev)*20.9;
    delay(300);
}

void updateTempValue()
{
  //int16_t adc1=0;
  //adc1 = ads.readADC_SingleEnded(1); // read the analog input from channel 0
  //temprature = (adc0 * 0.1875); // convert the ADC value to temperature using the LM35 formula
  temprature = random(100) / 100.0;
  Serial.print("Temperature: ");
  Serial.print(temprature);
  Serial.println(" C");

  delay(300);
}

void setup() {
  Serial.begin(115200);           // initialize serial communication
  Wire.begin(SDA_PIN, SCL_PIN, I2C_MASTER);                // join I2C bus as a slave with address #8
  //starts ADS readings
  ads.setGain(GAIN_SIXTEEN);    // 16x gain  +/- 0.256V  1 bit = 0.125mV  0.0078125mV
  
  ads.begin();
  calibrationv=calibrate();
}

void loop() 
{
  updateO2Value();
  updateTempValue();
  transmitData();

}

problem here is when I flashed it to nodeMCU WDT Soft Reset is happening:


--------------- CUT HERE FOR EXCEPTION DECODER ---------------

Soft WDT reset

>>>stack>>>

ctx: cont
sp: 3ffffcf0 end: 3fffffd0 offset: 01a0
3ffffe90:  feefeffe feefeffe feefeffe 00000001  
3ffffea0:  3ffee778 00000001 3ffee778 40202ebd  
3ffffeb0:  60000314 00000002 00000040 40202f7b  
3ffffec0:  00000002 3ffee608 3ffee778 40203069  
3ffffed0:  00000048 3ffee778 00000001 3ffee57d  
3ffffee0:  60000314 00000001 3ffee778 00000002  
3ffffef0:  3ffef5e4 3ffee54e 00000002 40201544  
3fffff00:  00000001 00000048 00000000 40201578  
3fffff10:  3ffee778 3ffee57c 00000002 402018f4  
3fffff20:  00000000 00000001 3ffee574 3ffef5e4  
3fffff30:  00000002 00000002 00000000 40201970  
3fffff40:  3ffee54e 00000001 00000001 00000000  
3fffff50:  00000000 00000003 3ffef5e4 3ffee730  
3fffff60:  3fffdad0 3ffee54e 3ffee540 40201700  
3fffff70:  3fffdad0 00000014 3ffee540 40201728  
3fffff80:  3fffdad0 00000014 3ffee540 402017a4  
3fffff90:  3ffee554 00000004 00000000 40201039  
3fffffa0:  3fffdad0 3ffee554 3ffee540 40201277  
3fffffb0:  feefeffe 00000000 3ffee704 40202498  
3fffffc0:  feefeffe feefeffe 3fffdab0 40100f91  
<<<stack<<<

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

 ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 3424, room 16 
tail 0
chksum 0x2e
load 0x3fff20b8, len 40, room 8 
tail 0
chksum 0x2b
csum 0x2b
v00043910
~ld

could anyone please help me here?
Thanks

Hi, my main intention is to use a 3.5" TFT display shield over arduino uno, so I'm left with these options to use: SCL, SDA pins, Rx-Tx pins, and A5 pin.

here nodeMCU is connected to ADS1115 via SCL, SDA line for gathering sensor data on address 0x48. Now, what I need to do is send the sensor data to arduino uno either using SDA, SCL lines or Rx, Tx pins available.

What would you suggest as started working on these devices a couple of months back and I'm trying to finish my college project.

I do not recommend I2C for inter processor communications. I will assume they will be more then a meter apart. Look at CAN, RS232, RS485, LIN and many others that are designed to communicate over a distance.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.