5.0 Communication Protocols
Arduino boards support several standard protocols for communicating with computers, sensors, and other microcontrollers.
5.1 Serial Communication (UART)
This is the most common method for communication between an Arduino board and a host computer. It is an asynchronous protocol (no shared clock).
- Hardware: Uses digital pins 0 (RX) and 1 (TX) on the UNO, as well as the USB connection.
- Key Functions:
- Serial.begin(baud_rate): Initializes serial communication.
- Serial.println(data): Sends data to the serial port, followed by a newline character.
- Serial.read(): Reads incoming serial data.
- Serial.available(): Returns the number of bytes available for reading.
5.2 Inter-Integrated Circuit (I2C)
I2C is a synchronous, multi-master, multi-slave serial bus used for attaching low-speed peripherals to microcontrollers over short distances.
- Hardware: Uses two wires: SDA (data line) and SCL (clock line). On the UNO, these are pins A4 and A5.
- Library: The Wire library is used to facilitate I2C communication. One device acts as the master, initiating communication with one of up to 112 slave devices.
5.3 Serial Peripheral Interface (SPI)
SPI is a synchronous serial data protocol used for short-distance communication, primarily in embedded systems. It is faster than I2C and supports full-duplex communication.
- Hardware: Uses four wires: MOSI (Master Out Slave In), MISO (Master In Slave Out), SCK (Serial Clock), and SS (Slave Select). On the UNO, these are pins 11, 12, 13, and 10, respectively.
- Library: The SPI library is used to manage communication.
5.4 Wireless and Network Communication
- RF Modules: Simple wireless communication can be achieved using 315/433 MHz RF transmitter and receiver modules, often managed with libraries like VirtualWire.
- Wi-Fi Modules: More advanced modules, such as the Texas Instruments CC3000, can be connected via SPI to provide full WiFi functionality. This allows the Arduino to connect to a network, act as a web server, and be controlled remotely.