Using the serial monitor

The Arduino board itself can communicate easily using basic protocols for serial communication.

Basically, serial communication is the process of sending data elements over a channel, often named a bus. Usually, data elements are bytes, but it all depends on the implementation of the serial communication.

In serial communication, data is sent sequentially, one after the previous one. This is the opposite of parallel communication, where data are sent over more than one channel, all at the same time.

Baud rate

Because the two entities that want to communicate using serial communications have to be okay about the answer to the question "Hey, what is a word?", we have to use the same speed of transmission on both sides. Indeed, if I send 001010101010, is it a whole word or are there many words? We have to define, for instance, that a word is four-digits long. Then, we can understand that the previous example contains three words: 0010, 1010, and 1010. This involves a clock.

That clock definition is made by initializing serial communication at a particular speed in baud, also called baud rate.

1 baud means 1 symbol transmitted per second. A symbol can be more than one bit.

This is why we don't have to create confusion between bps, bit per second, and baud!

Serial communication with Arduino

Each Arduino board has at least one serial port. It can be used by using digital pins 0 and 1, or directly using the USB connection when you want to use serial communication with your computer.

You can check http://arduino.cc/en/Reference/serial.

On the Arduino board, you can read RX and TX on both digital pins 0 and 1 respectively. TX means transmit and RX means receive; indeed, the most basic serial communication requires two wires.

There are many other kinds of serial communication buses we'll describe a bit later in Chapter 10, Some Advanced Techniques, in the Using I2C and SPI for LCD, LED, and other funny games section.

Note

If you use serial communication on your Arduino board, you cannot use the digital pins 0 and 1.

Serial communication with Arduino

Check TX and RX on digital pins 1 and 0

Arduino IDE provides a nice serial monitor that displays all symbols sent by the board to the computer via the USB interface. It provides a lot of baud rates from 300 baud to 115,200 baud. We are going to check how to use it in the following sections.

Serial monitoring

Serial monitoring is the way of creating very basic and easy communication with our board! It means we can program it to speak to us, via the serial monitor.

If you have to debug something and the board's behavior differs from what you are expecting from it, and you want to "verify whether the problem stems from the firmware or not, you can create some routines that will write messages to you. These messages are called traces. Traces can be totally necessary for debugging source code.

Traces will be described in detail in the next chapter.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.150.109