Skip to Content
Getting Started with Arduino
book

Getting Started with Arduino

by Massimo Banzi
February 2009
Beginner
128 pages
2h 45m
English
O'Reilly Media, Inc.
Content preview from Getting Started with Arduino

SERIAL COMMUNICATION

As you saw in Chapter 5, you can communicate with devices over the USB port using a serial communication protocol. Here are the serial functions.

Serial.begin(speed)

Prepares Arduino to begin sending and receiving serial data. You'll generally use 9600 bits per second (bps) with the Arduino IDE serial monitor, but other speeds are available, usually no more than 115,200 bps.

Example:

Serial.begin(9600);

Serial.print(data) Serial.print(data, encoding)

Sends some data to the serial port. The encoding is optional; if not supplied, the data is treated as much like plain text as possible.

Examples:

Serial.print(75);       // Prints "75"
Serial.print(75, DEC);  // The same as above.
Serial.print(75, HEX);  // "4B" (75 in hexadecimal)
Serial.print(75, OCT);  // "113" (75 in octal)
Serial.print(75, BIN);  // "1001011" (75 in binary)
Serial.print(75, BYTE); // "K" (the raw byte happens to
                        // be 75 in the ASCII set)

Serial.println(data) Serial.println(data, encoding)

Same as Serial.print(), except that it adds a carriage return and linefeed (\r\n) as if you had typed the data and then pressed Return or Enter.

Examples:

Serial.println(75);       // Prints "75\r\n"
Serial.println(75, DEC);  // The same as above.
Serial.println(75, HEX);  // "4B\r\n"
Serial.println(75, OCT);  // "113\r\n"
Serial.println(75, BIN);  // "1001011\r\n"
Serial.println(75, BYTE); // "K\r\n"

int Serial.available()

Returns how many unread bytes are available on the Serial port for reading via the read() function. After you have ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Getting Started with Arduino, 3rd Edition

Getting Started with Arduino, 3rd Edition

Massimo Banzi, Michael Shiloh
Mastering Arduino

Mastering Arduino

Jon Hoffman, Ejike (George Steve) Ifeanyichukwu, Pratik Desai
Arduino Cookbook

Arduino Cookbook

Michael Margolis

Publisher Resources

ISBN: 9780596155704Errata Page