Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Iot 3

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Internet of things[102046709] 12102080501068

PRACTICAL-3
AIM: Study of serial communication and device control using serial
communication with Arduino.

Serial communications provide an easy and flexible way for your Arduino board to interact
with your computer and other devices.
Serial communication and debugging are essential to working with Arduino boards. Simply
put, serial communication is a method that the board uses to communicate with other
devices – such as another computer, a peripheral, etc. When we discuss Arduino serial
communication, it’s also necessary to distinguish between its physical components (the
Arduino’s serial ports, for example) and its software components (using the serial monitor in
the Arduino IDE).

• Arduino Serial Port

Every Arduino board has at least one serial port, and many have additional built in serial
ports (Serial1, Serial2, etc.). Other boards, such as the Leonardo, also have serial
communication in the form of a USB) port. In USB-enabled boards, we refer to the USB as
Serial. The other standard serial ports begin with “Serial1” and number progressively from
there.

The port on your board called Serial (Serial1 if you have USB) communicates via pins 0 and 1
(RX and TX, respectively). Keep in mind that if you use these pins for serial data transmission,
they will be unavailable for digital I/O. To use the extra serial pins (pins 18 and 19 on the
Arduino Due, for instance), to communicate with your PC, make sure you have a
USB-to-serial adapter, as the extra pins are not connected to the board’s built-in adapter

• Arduino Serial Example Code

If you still need more serial ports than the built-in ones provided by your board, you have
another option. The Arduino Software Serial library will allow you to use other digital pins,
supplemented by software that replaces the RX and TX functions, to expand your board’s
serial connectivity.

To better understand the idea, we can look at Tom Igoe’s public domain example
code here:

#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
voidsetup() {
// Open serial communications and wait for port to open:
Serial.begin(57600);

1
Internet of things[102046709] 12102080501068
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?");
}
voidloop() { // run over and over
if (mySerial.available()) {
Serial.write(mySerial.read());
}
if (Serial.available()) {
mySerial.write(Serial.read());
}
}
This code creates a virtual serial port using pins 10 and 11 as the RX and TX ports,
respectively

You might also like