How to fetch data from node mcu to arduino uno

Hi, guys currently I am writing a code for two-way communication in between the Arduino Uno board with the node MCU(Amica). I was able to send multiple sensor data from Arduino to NodeMCU. However, I am having trouble fetching multiple data from NodeMcu back to Arduino Uno. The interconnection between the two boards is shown below. Can anybody shows me how to fetch multiple data(for example A=111 and B=222) to the Arduino Uno from Nodemcu?? I really need helps. Appreciate a lot.

Arduino Code

const int GSR=A0;
int sensorValue=0;
int gsr_average=0;
int muscle=0;
char c; 
String dataIn;                      

void setup(){
Serial.begin(9600);              //hardware serial communicate with PC  
}

void loop(){
  long sum=0;
  for(int i=0;i<10;i++)           //Average the 10 measurements to remove the glitch
      {
      sensorValue=analogRead(GSR);
      sum += sensorValue;
      delay(5);
      }
   gsr_average = sum/10;
   muscle = 10;
   Serial.print(gsr_average);         Serial.print("A");
   Serial.print(muscle);              Serial.print("B");
   Serial.print("\n");
   
   delay(1000);
  
   //reset variable
   c=0;
   dataIn="";     
       }

NodeMcu Code

#include <SoftwareSerial.h>
SoftwareSerial DataSerial(D6, D7);        //D6=12, D7=13

char c;
String dataIn;
int8_t indexOfA, indexOfB, indexOfC;
String GSR;                              
String Muscle; 
int ReturnData1 = 888;
int ReturnData2 = 999;

void setup() {
Serial.begin(9600);                      // Open serial communications and wait for port to open:
DataSerial.begin(9600);                  //software serial communicate with NodeMCU
}

void loop() { 
            
    while(DataSerial.available()>0)       //read data serial
    {
      c =DataSerial.read();
    
    //test data
    if(c=='\n'){break;}
    else       {dataIn+=c;}
    }

    if(c=='\n')
      {
        Parse_the_Data();

        //Show all the data in serial monitor
        Serial.println("GSR = " + GSR);
        Serial.println("Muscle = " + Muscle);
        Serial.println("=============================================");
        
        //reset variable
        c=0;
        dataIn="";
        
        }
}

void Parse_the_Data()
{
  indexOfA = dataIn.indexOf("A");
  indexOfB = dataIn.indexOf("B");
 
  GSR = dataIn.substring (0, indexOfA);
  Muscle = dataIn.substring(indexOfA+1, indexOfB);
  
}

If the NodeMCU uses 3.3V logic (which it most likely does) you should start by getting a logic level shifter since the Arduino uses 5V logic and this may damage the NodeMCU.

1 Like

Hi @copernicus_yew

Please redo your initial post and enclose your code in </> tags.
ArduinoForum

If you don't know how to do this then why not read the initial thread when registering in the forum.
Then read: How to get the best out of this forum.

How to get the best out of this forum - Using Arduino / Installation & Troubleshooting - Arduino Forum

RV mineirin

1 Like

Hi, ruilviana. Thanks for the information. Will amend my post.

Hi, Danois. Thanks for the information. I will a voltage divider to connect the arduino Uno with the NodeMCU.

Some pins on the NodeMCU may be 5V tolerant, look at this guide and also try to search for "5v tolerant pins" for your specific board.

EDIT: This may be better.

1 Like