NodeMcu Arduino Serial Communication Send Multiple Data, Up to 12 Data

preview_player
Показать описание
This is the Next video tutorial about NodeMcu Arduino Serial Communication. Also, this video fulfills my Subscriber request in the column comment. In this video, I create both NodeMcu and Arduino programs.
The rule is NodeMcu sends 12 different data to Arduino using a software serial program. The data was a combined data type, include int, float, and String data type. Then the Arduino receives the entire data and parses the data. In my opinion, to achieve this process, the most important thing to do is determine the data package. Commonly my data package structure is "Data1, Separator1, Data2, Separator2, ..., End Data Character".

Download the Code Here :
Рекомендации по теме
Комментарии
Автор

Hi,
First, I will share the code of this video, after that I will share the code if you want to send the data from arduino to NodeMcu


1- CODE Of the Video ( from NodeMcu to Arduino multiple data)

CODE ARDUINO :



#include<SoftwareSerial.h>

SoftwareSerial Arduino_SoftSerial(10, 11); // RX, TX

//Below is Global Variable Data

char c;
String DataIn;
int8_t indexofA, indexofB, indexofC, indexofD, indexofE, indexofF,
indexofG, indexofH, indexofI, indexofJ, indexofK, indexofL;

String data1, data2, data3, data4, data5, data6,
data7, data8, data9, data10, data11, data12;

void setup() {
// put your setup code here, to run once:

//Open Serial Communication (Arduino -PC)

Serial.begin(57600);

//Open Serial communication (NodeMcu -Arduino)



}

void loop() {
// put your main code here, to run repeatedly:

{

c= Arduino_SoftSerial.read();


if(c== '\n') {break;}
else {DataIn+=c;}
}


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


//Show All data to the Serial Monitor

Serial.println("data1 = " + data1);
Serial.println("data2 = " + data2);
Serial.println("data3 = " + data3);
Serial.println("data4 = " + data4);
Serial.println("data5 = " + data5);
Serial.println("data6 = " + data6);
Serial.println("data7 = " + data7);
Serial.println("data8 = " + data8);
Serial.println("data9 = " + data9);
Serial.println("data10 = " + data10);
Serial.println("data11 = " + data11);
Serial.println("data12 = " + data12);


//Reset the variable

c=0;
DataIn="";

}
}




void Parse_the_data()
{

indexofA = DataIn.indexOf("A");
indexofB = DataIn.indexOf("B");
indexofC = DataIn.indexOf("C");
indexofD = DataIn.indexOf("D");
indexofE = DataIn.indexOf("E");
indexofF = DataIn.indexOf("F");
indexofG = DataIn.indexOf("G");
indexofH = DataIn.indexOf("H");
indexofI = DataIn.indexOf("I");
indexofJ = DataIn.indexOf("J");
indexofK = DataIn.indexOf("K");
indexofL = DataIn.indexOf("L");

data1 = DataIn.substring (0, indexofA);
data2 = DataIn.substring (indexofA+1, indexofB);
data3 = DataIn.substring (indexofB+1, indexofC);
data4 = DataIn.substring (indexofC+1, indexofD);
data5 = DataIn.substring (indexofD+1, indexofE);
data6 = DataIn.substring (indexofE+1, indexofF);
data7 = DataIn.substring (indexofF+1, indexofG);
data8 = DataIn.substring (indexofG+1, indexofH);
data9 = DataIn.substring (indexofH+1, indexofI);
data10 = DataIn.substring (indexofI+1, indexofJ);
data11 = DataIn.substring (indexofJ+1, indexofK);
data12 = DataIn.substring (indexofK+1, indexofL);


}





CODE NODEMCU :



#include<SoftwareSerial.h>
SoftwareSerial NodeMcu_SoftSerial (D1, D2); // RX, TX

int data1, data2, data3, data4;
float data5, data6, data7, data8;
String data9, data10, data11, data12;

void setup() {
// put your setup code here, to run once:

//Open serial communication (NOdeMcu - PC)

Serial.begin(57600);

//Open Serial cimmunication (NodeMcu - Arduino)




}

void loop() {
// put your main code here, to run repeatedly:

data1 = 800;
data2 = 900;
data3 = 1000;
data4 = 10000;

data5 = 12.12345;
data6 = 123.1234;
data7 = 1234.123;
data8 = 12345.12;


data9 =
data10 = "Google";
data11 = "Subscriber";
data12 = "Catur";





NodeMcu_SoftSerial.print(data5, 5);
NodeMcu_SoftSerial.print(data6, 4);
NodeMcu_SoftSerial.print(data7, 3);
NodeMcu_SoftSerial.print(data8, 2);






delay(500);

}







2- (from arduino to NodeMcu Multiple data) :



CODE ARDUINO :

#include<SoftwareSerial.h>
SoftwareSerial Arduino_SoftSerial (10, 11); // RX, TX

int data1, data2, data3, data4;
float data5, data6, data7, data8;
String data9, data10, data11, data12;

void setup() {
// put your setup code here, to run once:

//Open serial communication (Arduino - PC)

Serial.begin(57600);

//Open Serial cimmunication (Arduino - Arduino)




}

void loop() {
// put your main code here, to run repeatedly:

data1 = 800;
data2 = 900;
data3 = 1000;
data4 = 10000;

data5 = 12.12345;
data6 = 123.1234;
data7 = 1234.123;
data8 = 12345.12;


data9 = "Youtube";
data10 = "Google";
data11 = "Subscriber";
data12 = "Catur";





Arduino_SoftSerial.print(data5, 5);
Arduino_SoftSerial.print(data6, 4);
Arduino_SoftSerial.print(data7, 3);
Arduino_SoftSerial.print(data8, 2);






delay(500);

}




CODE NODE Mcu :


#include<SoftwareSerial.h>

SoftwareSerial NodeMcu_SoftSerial(D1, D2); // RX, TX

//Below is Global Variable Data

char c;
String DataIn;
int8_t indexofA, indexofB, indexofC, indexofD, indexofE, indexofF,
indexofG, indexofH, indexofI, indexofJ, indexofK, indexofL;

String data1, data2, data3, data4, data5, data6,
data7, data8, data9, data10, data11, data12;

void setup() {
// put your setup code here, to run once:

//Open Serial Communication (NodeMcu -PC)

Serial.begin(57600);

//Open Serial communication (NodeMcu -NodeMcu)



}

void loop() {
// put your main code here, to run repeatedly:

{

c= NodeMcu_SoftSerial.read();


if(c== '\n') {break;}
else {DataIn+=c;}
}


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


//Show All data to the Serial Monitor

Serial.println("data1 = " + data1);
Serial.println("data2 = " + data2);
Serial.println("data3 = " + data3);
Serial.println("data4 = " + data4);
Serial.println("data5 = " + data5);
Serial.println("data6 = " + data6);
Serial.println("data7 = " + data7);
Serial.println("data8 = " + data8);
Serial.println("data9 = " + data9);
Serial.println("data10 = " + data10);
Serial.println("data11 = " + data11);
Serial.println("data12 = " + data12);


//Reset the variable

c=0;
DataIn="";

}
}




void Parse_the_data()
{

indexofA = DataIn.indexOf("A");
indexofB = DataIn.indexOf("B");
indexofC = DataIn.indexOf("C");
indexofD = DataIn.indexOf("D");
indexofE = DataIn.indexOf("E");
indexofF = DataIn.indexOf("F");
indexofG = DataIn.indexOf("G");
indexofH = DataIn.indexOf("H");
indexofI = DataIn.indexOf("I");
indexofJ = DataIn.indexOf("J");
indexofK = DataIn.indexOf("K");
indexofL = DataIn.indexOf("L");

data1 = DataIn.substring (0, indexofA);
data2 = DataIn.substring (indexofA+1, indexofB);
data3 = DataIn.substring (indexofB+1, indexofC);
data4 = DataIn.substring (indexofC+1, indexofD);
data5 = DataIn.substring (indexofD+1, indexofE);
data6 = DataIn.substring (indexofE+1, indexofF);
data7 = DataIn.substring (indexofF+1, indexofG);
data8 = DataIn.substring (indexofG+1, indexofH);
data9 = DataIn.substring (indexofH+1, indexofI);
data10 = DataIn.substring (indexofI+1, indexofJ);
data11 = DataIn.substring (indexofJ+1, indexofK);
data12 = DataIn.substring (indexofK+1, indexofL);


}

ozujbqc
Автор

Thank you very much, for this great help and saving time. I was searching the method to split the serial data for almost two weeks and here I got the perfect solution.

danaishrathore
Автор

WOW, Channel ini sangat membantu sekali dalam pengerjaan proyek saya.Terima kasih banyak CP

KR_FAIZ
Автор

Hello, great video tutorial, and your work really helped me. Thanks Bro.

youeng
Автор

Hey dear seems to be great totorial but i want to ask one question i have two sensors connected to uno and then i am sending its data to firebase using esp01 via serial communication but when it recieved at firebase they are combined one after to the other, as their any way to separate the reading for the both sensors in a separate row each contain only one sensor reading and then so on please need your help thanks in advance

IceCream
Автор

Thank you so much for sharing the knowledge... You really saved many people's brain... including me.. Thanks Sir !

hamdansulaiman
Автор

very useful tutorial, I was searching splitting data of serial read, from many days
thanks

LUCKY
Автор

I tried it to Arduino to Nodemcu but it just output question marks? What do you think is the problem there?

jmn
Автор

thank you sooo much you just completed my project <3

janithbandara
Автор

If I want to change Arduino to be a data sender and Nodemcu to be a data receiver, what would it be like?

taufikanwar
Автор

Hello sir! Your work really helped me in my studies and projects. If its possible, can you show how to have two way communication where an arduino will request data from another arduino before it send them. Thank you!

wardenclyffepark
Автор

On the Arduino side, how would you convert data* variables (string) to useful variables (int / float) in code? The only way I was able to do it was with a character array and parse using strtoul... I would prefer your method however because each data is specifically indexed. Excellent content btw **

jhzgl
Автор

Hello, great video that works very well between two esp8266, but when is it for communication between two ESP32? If you can enlighten me? The libraries are different, I think for the ESP32 the procedure is quite different. It would be great of you if you have already touched on this subject to tell us more. Thanks for your help.

DanielVila
Автор

will it work for if the integer values from transmitter are varying?

subahashsuman
Автор

Thanks man. You saved me. I was trying and searching for exactly this thing from last 10 days. Thanks again. keep uploading.

ateebhassan
Автор

Great video, do you have any videos using char array instead of String?

iantcroft
Автор

Hello. Great tutorial video.
Can you also make a tutorial on how to send ultrasonic sensor data from arduino uno to esp8266 and then send that data to firebase please ?

nitishgowrydoss
Автор

Exelente informacion, entendí todos los gestos que hiciste con el tipiado del código, los compilé sin errores, pero no logro que se comunique, probé la librería SoftwareSerial y no logro que transmita, el conexionado esta bien, que otra cosa puede estar mal?, muchas gracias al que me pueda orientar.

MarioPerez-vbhj
Автор

Excellent :). Very informative.
I have a question. If I want two-way serial communication between two Arduino's what do I need to add in the main loop to distinguish between transmitting and receiving. I don't need a whole sketch. I'll go into the details myself. Thanks

erboy
Автор

how can i sort this type of data and display in 3.5inch TFT LCD
$WaterLevel$2$m$
$WaterDischarge$0$m3/s$
$AverageSpeed$0$m/s$
$Tiltangle$213$Deg$
$Flowdirection$1$$
$SNRLevel$0$dBm$
$AverageVelocity$0$m/s$
$Battery$11.71262$VDC$

this data recieved by rs232 to ttl conveter in aurdino mega serial2 (16, 17)

ShadowX_Legion