Mturk Jobs

Mturk Jobs
Mturk Jobs

Tank

Friday, March 16, 2018

How to make serial communications with Arduino - Simple Steps

In this post we'll see how to make serial communications between Arduino board and the standard PC or any other device connected to Arduino.





Serial communications is a common way to communicate between devices.

In the early day, serial communication played an important rule in data transfer and other ways of communications between devices.

As systems advanced and chips has become more powerful, protocols got faster.

Traditional serial communication is maybe somehow not available in its old form.

But it has another form and got a new life in the form of serial communication over USB.

USB Universal Serial Bus is the modern and more convinent type of communication between devices.

But arduino uses USB to make serial communication and it also has the traditional serial communication port you can use with any device.

This means that when you connect Arduino board to a modern device like any modern PC or even to your tablet, you connect it to Arduino using USB.

But if you connect Arduino to any other device like a sensor or actuator that uses serial communication protocol you can use the standard serial communication library in Arduino.

The best thing in all of this is that the user doesn't have to bother himself about all of that.

The library takes care of all the stuff.

All you have to do is to call the serial library and it does its magic.


And here is the code for Arduino softwareSerial library you can use to either make a new(virtual/software) serial port. Or if you want to connect Arduino to an device that doesn't have a USB device. Like a sensor or any other simple device.

For example, I used this softwareSerial Library with a speech recognition module.

I needed the standard Arduino serial port over USB to be connected to the PC that ran my Arduino IDE.

And I also needed to connect the speech recognition module to Arduino board.

My brother has suggested that I use another serial port on Arduino and here I knew about the softwareSerial Library.



/*
  Software serial multple serial test

 Receives from the hardware serial, sends to software serial.
 Receives from software serial, sends to hardware serial.

 The circuit:
 * RX is digital pin 10 (connect to TX of other device)
 * TX is digital pin 11 (connect to RX of other device)

 Note:
 Not all pins on the Mega and Mega 2560 support change interrupts,
 so only the following can be used for RX:
 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69

 Not all pins on the Leonardo and Micro support change interrupts,
 so only the following can be used for RX:
 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI).

 created back in the mists of time
 modified 25 May 2012
 by Tom Igoe
 based on Mikal Hart's example

 This example code is in the public domain.

 */

#include

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

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(57600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }


  Serial.println("Goodnight moon!");

  // set the data rate for the SoftwareSerial port
  mySerial.begin(4800);
  mySerial.println("Hello, world?");
}

void loop() { // run over and over
  if (mySerial.available()) {
    Serial.write(mySerial.read());
  }
  if (Serial.available()) {
    mySerial.write(Serial.read());
  }
}











Paid Online Surveys
Check our books on Amazon we created on our way to find happiness.
A Trip To Siwa Oasis: Tourist guide to an Egyptian Oasis by [ElSakhawy, Sara M.]

A Trip To Siwa Oasis

The Ultimate travel bag list by [ Elskhawy, Sara M.]

No comments:

Tank