Dear guys, I am currently writing codes on two-way communication between Arduino Uno and Node MCU. I was able to send multiple dataS from Arduino Uno to NodeMCU. However, I have some trouble fetching multiple data from NodeMcu back to Arduino Uno. I have tried out some code myself but it not working as I expected. The connection between the Arduino Uno and NodeMCU is as below. Can you show me how to pass ( A= 128 and B=456) from NodeMCU to the Arduino Uno? I really need some helps in fetching data from NodeMCU to Arduino Uno. Really appreciate it if you can help me out here.
Arduino Uno 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);
}