a 0 bit is represented by 0 volts, while 5 volts stands for a 1 bit. (Some proto-
cols use -12V and 12V, respectively.)
The following parameters control a serial communication:
0 1 00000 111 1
Start Bit
Parity
Stop Bit
Data
• A start bit indicates the beginning of a data word and is used to synchro-
nize the transmitter and receiver. It is always 0.
• A stop bit tells us when the last data bit has been sent and separates two
consecutive data words. Depending on the particular protocol agreement,
there can be more than one stop bit, but that happens rarely.
• Information is transferred as binary data bits; that is, if you’d like to
transmit the letter M, you have to turn it into a number first. Several
character set encodings are available, but when working with the Arduino,
the ASCII encoding fits best. In ASCII, an uppercase M is encoded as the
decimal number 77, which is 01001101 in binary. This is the bit sequence
that eventually gets transmitted.
• The parity bit indicates whether the number of 1s in the data has been
odd or even. This is a simple error-checking algorithm that is rarely used
and that stems from a time when network connections were less reliable
than they are today. Parity control can be “none” (no parity bit is sent),
“odd” (the parity bit is set if the amount of 1s in the data bits is odd;
otherwise, it is 0), or “even” (the parity bit is set if the amount of 1s in the
data bits is even; otherwise, it is 0). We chose odd parity for our data, and
because there are 4 bits set to 1 in 01001101, the parity bit is 0.
• The baud rate defines the transmission speed and is measured in trans-
mission steps per second. When working with the Arduino, typical baud
rates are 9600, 14400, 19200, or even 115200. Note that the baud rate
doesn’t define how much data is actually transferred per second, because
you have to take the control bits into account. If your connection settings
are 1 start bit, 1 stop bit, no parity, and 8 bits per byte, then you have to
transfer 1 + 1 + 8 = 10 bits to transfer a single byte. With a baud rate set
to 9600, you can then theoretically send 9600 / 10 = 960 bytes per sec-
ond—at least if every bit gets transferred in exactly one transmission step.
Appendix 3. Advanced Serial Programming • 254
report erratum • discuss
www.it-ebooks.info