A simple Python-based tool for monitoring and logging serial port data with command-line options for Raspberry Pi.
- Real-Time Serial Monitoring: Continuously reads and displays data from a specified serial port.
- Optional Logging: Logs the received data to
serial_log.txt
when the--log
option is enabled. - Configurable Parameters:
- Serial port and baud rate are adjustable via command-line arguments.
- Python: Version 3.7 or later
- Libraries:
pyserial
logging
(built-in)
Install the required library using pip:
pip install -r requirements.txt
Argument | Required | Description |
---|---|---|
-p , --port |
No | Serial port to connect to (default: /dev/serial0 ). |
-b , --baudrate |
No | Baud rate for the serial connection (default: 115200 ). |
-L , --log |
No | Enable logging to a file (serial_log.txt ). |
python3 serial_monitor -p /dev/serial0 -b 115200
python3 serial_monitor -p /dev/serial0 -b 115200 -L
-
Connect to the Serial Port:
- Opens a connection to the specified serial port at the given baud rate.
- Automatically retries the connection every 5 seconds if an error occurs.
-
Read and Display Data:
- Continuously reads data from the serial port line by line.
- Prints the received data to the console.
-
Optional Logging:
- If the
--log
option is enabled, all received data is logged toserial_log.txt
. - Logs include timestamps for each line of data.
- If the
-
Error Handling:
- Handles errors in serial communication gracefully by reconnecting after a delay.