Hello
Arduino to Nodemcu Connection
today i will show you how to Serial Communication between NodeMCU and Arduino
First you have to know about
What is Serial Communication
Serial communication is a communication process wherein data transfer occurs by transmitting data one bit at a time in sequential order over a computer bus or a communication channel. It is the most widely used approach to transfer information between data processing equipment and peripherals. Binary One represents a logic HIGH or 5 Volts, and zero represents a logic LOW or 0 Volts, used for communicating between the Arduino board and a computer or other devices. All Arduino boards have at least one serial port which is also known as a UART or USART. It communicates on digital pins 0 (RX) and 1 (TX) as well as with the computer via USB. Serial communication on pins TX/RX uses TTL logic levels (5V or 3.3V depending on the board).To establish serial communication between two devices, the devices should be connected as shown below.Serial Communication |
Arduino to Nodemcu Connection
ARDUINO PART:
In Arduino, we shall consider pin 5 as Rx and pin 6 as Tx. To use the GPIO pins for serial communication SoftwareSerial library can be used. Here we have created a serial port named s with pin 5 as RX and pin 6 as TX.// Arduino code
#include <SoftwareSerial.h>
SoftwareSerial s (5,6);
void setup () {
s.begin (9600);
}
void loop () {
int data = 50;
if (s.available ()> 0)
{
s.write (data);
}
}
NODEMCU PART:
In NodeMCU we shall make pin 5 as Tx and pin 6 as Rx. So data sent by Arduino will be received by the NodeMCU and vice versa. So we can establish a successful Serial Communication between NodeMCU and Arduino.
#include <SoftwareSerial.h>
SoftwareSerial s (D6, D5);
int data;
void setup () {
s.begin (9600);
Serial.begin (9600);
}
void loop () {
s.write ("s");
if (s.available ()> 0)
{
data = s.read ();
Serial.println (data);
}
}
No comments