HOW TO USE ANY ARDUINO DIGITAL PINS TO EMULATE SERIAL (SOFTWARE SERIAL)
This post helps you to understand and use software serial implantation in any Arduino. BY using digital pins other than 0,1 .
Why do we
need extra serial pins? When we have serial at 0, 1 pins on Uno. Well sometimes
you need many as possible as you can, because the default Tx,Rx(0,1) are always
reserved for pc communications sometimes if we force to use it as debug it
might throw an error also!
That’s why
we need additional serials as possible.
Here is an
excuse..! for using software serial to put hc05 Bluetooth to at command mode:
notice if i use the default serial to communicate it might throw an error while uploading.
#include <SoftwareSerial.h> // this library is default installed in //Arduino ide
// defining Tx and Rx pins (we can use only digital pins and analog //pins)
#define RX_PIN 7
#define TX_PIN 8
SoftwareSerial swSer (RX_PIN, TX_PIN); //here the swSer is the //name of serial function we use whatever name you want
int state;
void setup() {
Serial.begin(9600);
Serial.println("enter cmds:");
swSer.begin(38400);
}
void loop() {
if (swSer.available())
Serial.write(swSer.read());
if (Serial.available())
swSer.write(Serial.read());
}
Comments
Post a Comment