Computers can exchange bits of information serially (one after another, in sequence) or in parallel (several at the same time). In applications where it is necessary to have one computer talk to another, the most commonly used communication method is serial.
So it is no surprise that serial communication is the method used to send data between the Arduino board and a computer (or other device). Information is sent to and from the computer and the Arduino by setting a pin high or low. One side sets the pin and the other reads it.
The Arduino Duemilanove Board has one serial port that communicates on digital pins 0 (RX) and 1 (TX) as well as with the computer via USB. When you use the IDE to Upload your sketches to the Arduino, the bits are transmitted one at a time through the USB cable to the Arduino. The serial connection can also be used in our sketches to send data to the computer and to receive data from the computer via the serial monitor available on the IDE. This proves very useful for debugging your projects, as we will explore in the upcoming posts.
The Arduino serial library makes the following functions available for use in your sketches:
- begin(): opens serial port and sets the rate for serial data transmission (the RX and TX pins cannot be used for general input and output when the serial port is being used)
- end(): disables serial communication (this allows the RX and TX pins to be used for general input and output again)
- int available(): gets the number of bytes stored in the serial receive buffer (the buffer holds 128 bytes) that are available for reading from the serial port
- int read(): reads incoming serial data
- flush(): flushes the serial receive buffer of incoming serial data
- print(): prints data to the serial port as human-readable ASCII text
- println(): prints data to the serial port as human-readable ASCII text followed by a carriage return character and a newline character
- write(): writes binary data to the serial port