The USB interface used by the Arduino to communicate with the computer is the USB interface used to download the program, and when Arduino communicates with other devices, it needs to use the "Serial" series of functions, so we have to know about it, here are a few common " Serial"function.
1, Serial.begin ()-Sets the rate at which the serial data is transmitted per second (baud rate). When communicating with a computer, use the following values: 300, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, or 115200. You can also use other values at any time, for example, to communicate with a NO. 0 or 1th interface to require a special baud rate.
2, Serial.print ()-outputs data from the serial port.
3, Serial.println ()-output data from the serial port, followed by a carriage return (ASCII 13, or ' \ R ') and a newline character (ASCII 10, or ' \ n '). The value obtained by this function is the same as Serial.print ().
4, Serial.read ()-Read the data that is continuously entered.
Watch the tx/rx indicator on the Arduino board
TX(t:transmitter send) indicates that instruction information is sent to the computer for Arduino,RX(r:receive receive) indicates that the Arduino receives The instruction information from the computer, which flashes when the program is downloaded or when it communicates with the computer.
Let me illustrate with an example, and we'll write a simple applet that lets the computer display the string "Hello world". And let an LED match, the small lights flashing a display of a "Hello world" cycle.
The procedure is as follows
Pay attention to the flashing of TX and RX LEDs and pin13 port LEDs!
Then write a small program that uses the computer to send instructions to Arduino, and when we send "a", the LEDs will blink. This is because I assign a value to the Val,arduino received from the computer signal, run to the Serial.read () instruction will read the value assigned to Val, by the IF statement to judge, if it is true will execute if{} instruction, so the LED lit a will be extinguished, You should understand that.
Enter a and look at the LEDs of the Pin13 interface!
arduino-Serial Communication