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);
}