The Adafruit PiUART is a UART (Universal Asynchronous Receiver/Transmitter) interface board specifically designed for use with the Raspberry Pi series of single-board computers. This component simplifies the process of connecting UART-compatible devices, such as serial consoles, to the Raspberry Pi's GPIO (General Purpose Input/Output) pins. It is an essential tool for developers and hobbyists who need to establish serial communication between their Raspberry Pi and other hardware components.
Pin Number | Name | Description |
---|---|---|
1 | VCC | 3.3V Power Supply Input |
2 | TX | Transmit Data (PiUART to Raspberry Pi) |
3 | RX | Receive Data (Raspberry Pi to PiUART) |
4 | GND | Ground Connection |
Q: Can I use the PiUART with a 5V logic device? A: No, the PiUART is designed for 3.3V logic levels. Use a logic level converter for 5V devices.
Q: How do I change the baud rate on the PiUART? A: The baud rate is set within your Raspberry Pi's software configuration. Refer to the Raspberry Pi's serial interface configuration settings to adjust the baud rate.
Q: Is the PiUART compatible with all Raspberry Pi models? A: The PiUART is compatible with any Raspberry Pi model that has a GPIO header with UART pins available.
Below is an example Python script for sending a simple message through the PiUART to a connected serial device. This script assumes you have already configured the serial port on your Raspberry Pi.
import serial
import time
ser = serial.Serial( port='/dev/serial0', # Replace with the correct serial port if necessary baudrate=9600, # Set the baud rate to match the connected device timeout=1 )
def send_message(message): ser.write(message.encode())
try: while True: send_message("Hello from Raspberry Pi!") time.sleep(2) # Wait for 2 seconds before sending the next message except KeyboardInterrupt: ser.close() # Close the serial connection when the script is stopped
Remember to configure the serial port on your Raspberry Pi and install the `pyserial` package before running the script. Use the command `pip install pyserial` to install the package if it's not already installed.