I want to get sensor data from Arduino to NodeMcu and then send it to android. Also, I want to send some orders from the android to the Arduino board through the NodeCcu.
after searching the internet I found the following connection
#include<SoftwareSerial.h> //Included SoftwareSerial Library
//Started SoftwareSerial at RX and TX pin of ESP8266/NodeMCU
SoftwareSerial s(3,1);
void setup() {
//Serial S Begin at 9600 Baud
s.begin(9600);
}
void loop() {
//Write '123' to Serial
s.write(123);
delay(1000);
}
and this for arduino
int data; //Initialized variable to store recieved data
void setup() {
//Serial Begin at 9600 Baud
Serial.begin(9600);
}
void loop() {
data = Serial.read(); //Read the serial data and store it
delay(1000);
}
but the problem is that it only sends data from the nodemcu to arduino and I want both arduino and nodemcu to be able to sen and recieve data.
If you already have a nodeMCU-board the nodeMCU-Board can do almost everything the Arduino is doing.
One restriction is ADC. a nodeMCU has only one ADC-channel on board.
So if you give an overview about what you want to do in your project there is a good chance to optimise away the complete arduino.
If you want to stay with the combintion of the arduino and the nodeMCU
from your question I estimate that you are a real beginner about programming and electronics.
This no problem, this is completely OK. Though if you want to modify code and the modifying is more than just an IO-pin-number there is no way around really learnig to program.
If you imagine learning to ride a bike. It is not done from watching somebody else riding a bike for 5 minutes.
It needs some basic knowledge:
which way to push your feets against the pedals
which lever is the brake?
-which lever is for gear-shifting?
last but not least training your sense of balance
which can only be done by riding a bike with your own body
And you don't start practising riding a bike by BMX-ing back-flips in the half-pipe
You start on a flat level surface with a lot of space in every direction
In programming it is similar and different the difference is:
you have 80 wheels, 27 handlebars, 50 gearshifting-levers 30 brakes etc.
So you need some guidance through a tutorial how it all works.
working through a tutorial explains the basics - which has nothing to do with your actual project
but explains very important conceptual things. If you know these basics programming will be much easier.
You will have much less questions in the forum. So it is good invested time.
I recommed this tutorial as a starting point
Learning to program
Of course you can ask here in the forum. But then you have to wait for the answers. If you start to learn how coding works you become more and more independent of waiting for answers.
It is easy to understand and has a good mixture between explaining important concepts and example-codes to get you going. So give it a try and report your opinion about this tutorial.
This posting said nothing about to send & receive with the serial interface.
IMHO you need to know these basics to accelerate finishing your project.
messing around with the serial interface right know with such a low knowledge-level about programming is like mowing the green of a whole footbal-stadium with a nail-scissor. You can start right away but it will take very loooong.
Learning how to operate a mower tractor needs extra time - but once you have learned it
finishing mowing a whole football-stadium will be finished in three hours. (compared to three months with the nail-scissor)
It is much easier to debug programs if you send data as text with Serial.print() rather than sending it as binary data with Serial.write()
I am not familiar with the NodeMCU - if it is a 3.3v device then you will need a voltage divider to reduce the Arduino's 5v Tx signal to 3.3v. The Arduino's Rx should be happy with a 3.3v Tx signal from the NodeMCU.
Have a look at the examples in Serial Input Basics - simple reliable non-blocking ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.
The technique in the 3rd example will be the most reliable. It is what I use for Arduino to Arduino and Arduino to PC communication.
You can send data in a compatible format with code like this (or the equivalent in any other programming language)