The document introduces serial communication, explaining that it transmits data one bit at a time over a single wire, unlike parallel communication which uses multiple wires. It discusses the simplicity of serial ports, particularly in Arduino devices, and outlines how to start a serial connection and send or receive data using specific functions. The document also includes example code for sending and receiving data with an Arduino.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0 ratings0% found this document useful (0 votes)
4 views12 pages
Serial Communication - Arduino
The document introduces serial communication, explaining that it transmits data one bit at a time over a single wire, unlike parallel communication which uses multiple wires. It discusses the simplicity of serial ports, particularly in Arduino devices, and outlines how to start a serial connection and send or receive data using specific functions. The document also includes example code for sending and receiving data with an Arduino.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
Serial CommunicationIntroducing Serial Communication
The word serial comes from the way data is transmitted;
serial devices send bits one at a time on a single wire. This is
something that you have seen before; it is like a telephone
call. Both users pick up the telephone and a single wire
connects them together.
While serial devices send bits on a single wire, parallel
devices send multiple bits on multiple wires. Although
parallel communications can be faster than serial, they were
often more expensive, requiring more wires. There are also
speed limitations due to physical limitations of conductive
wiring. The next figure shows the difference between serial
and parallel communications.Introducing Serial Communication
Oo
ee
Lr)
Serial versus parallelIntroducing Serial Communication
Serial ports are extremely simple. This simplicity is one reason
why they are used so often. Data is sent on one wire, the
transmit wire (TX), and received on another, the receive wire
(RX). On the other side of the cable, it is connected to another
computer with a TX pin and an RX pin. Inside the cable itself, the
TX and RX wires are inverted. The TX pin on one side is
connected to the RX pin on the other side. This is illustrated in
Figure.
OX 1™
RX ee —————————— Rx
Transmit and receive wiresIntroducing Serial Communication
Arduinos use serial ports for communicating with computers
and other devices. The USB port of an Arduino is used for
serial communication with a computer, with the added
advantage that USB can also be used to power the device.
USB also has the advantage of auto-configuring most of the
parameters.
Some Arduinos have other hardware serial ports, enabling
communication with other devices. The USB communication
is sent to Arduino pins 0 and 1, meaning that those pins are
reserved if your device must communicate with a computer.Starting a Serial Connection
To Start a Serial Connection you must first do some basic
configuration. To do this, you use the begin function of the
Serial object. Typically, 9,600 is an appropriate speed for
communicating. You are free to use any speed you want as long
as both devices are operating at the same speed.
Serial configuration is normally done in setup() because devices
tend to not change the speed at which they communicate over
time.Serial Communication-writing
Sending Text
To send data to the serial device , use the function print(). The
data to be printed can be in any format.
You need the following components:
+ Arduino Uno
+ USB cableSerial Communication-writing
Gum
void setup( )
{
pinMode(13, OUTPUT);
[Link](9600); // sets data rate to 9600 bps
}
void loop()
{
digitalWrite(13, HIGH);
[Link]("LED is On");
delay(1000);
digitalWrite(13, LOW);
[Link]("LED is Off");
delay(1000);
i | 4Serial Communication-Reading
=
Arduinos can also receive data, Receiving data can be used for
many projects; computers can send data, for example, to control
the brightness of an LED. To read data from the serial device , use
the function [Link]( );
int ledPin=13;
int value;
void setup()
{
[Link](9600); |
pinMode(ledPin,OUTPUT);
}Serial Communication-Reading
void loop ()
{value = [Link]();
if (value == '1')
{
digitalWrite(ledPin,HIGH);
}
else if (value == '0')
{
digitalWrite(ledPin, LOW);
}
}Reference
James A. Langbridge,” Arduino sketches tools and
techniques for programming wizardry”,2015.