Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Maik Schmidt - Arduino A Quick-Start Guide, 2nd Edition (The Pragmatic Programmers) - 2015.pdf
Скачиваний:
146
Добавлен:
22.03.2016
Размер:
30.47 Mб
Скачать

What If It Doesn’t Work? 35

You can control many devices using serial communication, but the regular Arduino has only one serial port. If you need more, take a look at the Arduino Due, which has four serial ports.2

A Universal Asynchronous Receiver/Transmitter (UART)3 device supports serial communication on the Arduino. This device handles serial communication while the CPU takes care of other tasks. This greatly improves the system’s overall performance. The UART uses digital pins 0 (RX) and 1 (TX), which means you cannot use them for other purposes when communicating on the serial port. If you need them, you can disable serial communication using Serial.end().

With the SoftwareSerial4 library, you can use any digital pin for serial communication. It has some limitations, but it is sufficient for most applications.

In this chapter, you saw how to communicate with the Arduino using the serial port, which opens the door to a whole new world of physical computing projects. (See Learning More About Serial Communication, on page 253, for more details about serial communication.) In the next chapters, you’ll learn how to gather interesting facts about the real world using sensors, and you’ll learn how to change the real world by moving objects. Serial communication is the basis for letting you control all of these actions using the Arduino and your PC.

What If It Doesn’t Work?

If anything goes wrong with the examples in this chapter, you should take a look at What If It Doesn’t Work?, on page 21, first. If you still run into problems, it may be because of some issues with serial communication. You might have set the wrong baud rate; in the following figure, you can see what happens in such a case.

2.http://arduino.cc/en/Main/arduinoBoardDue

3.http://en.wikipedia.org/wiki/UART

4.http://www.arduino.cc/en/Reference/SoftwareSerial

report erratum • discuss

Chapter 2. Creating Bigger Projects with the Arduino 36

Make sure that the baud rate you’ve set in your call to Serial.begin matches the

baud rate in the serial monitor.

Exercises

Add new commands to the sample program. The command 3 could make the LED blink for a while.

Try to make the commands more readable; that is, instead of 1, use the command “on”, and instead of 2, use “off”.

If you have problems solving these exercises, read Chapter 4, Building a Morse

Code Generator Library, on page 61.

report erratum • discuss

Part II

Eleven Arduino Projects

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]