β FULLY TESTED AND WORKING - A Python client that receives serial data from an ARM assembly program and forwards prompts to TinyLLM for AI processing on Raspberry Pi.
This client is part of a dual-Pi communication system where:
- Sender Pi: Runs ARM assembly program that sends messages via serial
- Receiver Pi: Runs this Python client to receive and process with AI
βββββββββββββββββββ USB Serial βββββββββββββββββββ TinyLLM βββββββββββββββββββ
β SENDER PI β Cable β RECEIVER PI β Processing β TinyLLM β
β β βββββββββββββββΆ β β βββββββββββββββΆ β β
β ARM Assembly β /dev/ttyUSB0 β Python Client β ββββββββββββββ AI Response β
β Program β 9600 baud β (This Code) β Response Back β Generation β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
# Copy project to your Pi
scp -r ArmGPT-server/ pi@your-pi-ip:~/
# SSH to Pi and install
ssh pi@your-pi-ip
cd ~/ArmGPT-server
./install_tinyllm_rpi.sh# Test Ollama integration
python3 test_ollama.py
# Test serial connection (with ARM sender connected)
python3 main.py --config config/rpi_config.yaml --serial-test
# Test full pipeline with simulated messages
python3 main.py --config config/rpi_config.yaml --test-mode# Start receiving ARM assembly prompts and processing with AI
python3 main.py --config config/rpi_config.yamlThis implementation has been successfully tested on Raspberry Pi 4 with:
- β Ollama + TinyLlama running on ARM64 CPU-only mode
- β Serial communication at 9600 baud via USB cable
- β ARM assembly messages received and processed
- β AI responses generated in 3-8 seconds
- β Complete pipeline functioning end-to-end
[03:54:59.307] INFO SERIAL: Simulating message 1/3: "Hello from ARM assembly on Raspberry Pi"
[03:54:59.307] INFO PROCESS: Cleaned message: "Hello from ARM assembly on Raspberry Pi"
[03:54:59.307] INFO LLM: Forwarding to TinyLLM (attempt 1/5)...
[03:55:03.398] INFO LLM: Response received (4.091s): "Certainly! Here's an example of how you can use the Arm assembly command in Raspberry Pi..."
[03:55:03.398] INFO LLM: Processing complete
[03:55:03.399] INFO SERIAL: Response sent back: "AI: Certainly! Here's an example of how you can use..."
The client processes these message types from the ARM assembly sender:
TEST MESSAGE FROM ACORN SYSTEM
[User input up to 255 characters]
TEST MESSAGE FROM ACORN SYSTEM
TEST MESSAGE FROM ACORN SYSTEM
[...repeats with timing delays]
serial:
port: "/dev/ttyUSB0" # Serial device path
baudrate: 9600 # Must match ARM sender
timeout: 1 # Read timeout in seconds
reconnect_attempts: 5 # Auto-reconnection attempts
reconnect_delay: 2 # Delay between reconnect attemptstinyllm:
interface_type: "api" # Using Ollama API
api_endpoint: "http://localhost:11434/api/generate"
model: "tinyllama" # Ollama model name
timeout: 60 # Increased for Raspberry Pi
max_retries: 3 # Retry attempts for failed requests
retry_delay: 3 # Delay between retries
max_tokens: 100 # Limit response length for performance
temperature: 0.7response:
enabled: true # Enable/disable sending responses back
max_length: 500 # Maximum response length to send
prefix: "AI: " # Prefix for responses
suffix: "\n---\n" # Suffix to mark end of responselogging:
level: "INFO" # Console log level
file_level: "DEBUG" # File log level
file: "logs/serial_client.log"
console: true # Enable colored console output- β 9600 baud USB serial communication
- β Automatic device detection and reconnection
- β Robust error handling and recovery
- β Hardware buffer management
- β Bidirectional communication - sends AI responses back
- β Message cleaning and validation
- β Type classification (test vs custom messages)
- β Content filtering and safety checks
- β Statistics tracking
- β Ollama API integration with TinyLlama model
- β Raspberry Pi optimized settings
- β Automatic retry logic with exponential backoff
- β Response time monitoring and failure recovery
- β Colored console output with component prefixes
- β Comprehensive file logging
- β Real-time performance statistics
- β Transaction logging
python3 tests/test_serial_client.py
# Test Ollama integration specifically
python3 test_ollama.pyTest without hardware or LLM:
python3 main.py --config config/rpi_config.yaml --test-modeTest serial reception only:
python3 main.py --config config/rpi_config.yaml --serial-testTest full pipeline with mock LLM:
python3 main.py --config config/client_config.yaml
# (Uses mock interface by default in client_config.yaml)[12:34:56.789] INFO SERIAL: Waiting for data...
[12:34:57.123] INFO SERIAL: Received: "TEST MESSAGE FROM ACORN SYSTEM"
[12:34:57.124] INFO PROCESS: Cleaned message: "TEST MESSAGE FROM ACORN SYSTEM"
[12:34:57.125] INFO LLM: Forwarding to TinyLLM...
[12:34:58.456] INFO LLM: Response received (1.331s): "[AI response here]"
[12:34:58.457] INFO LOG: Transaction logged to file
[12:34:58.458] INFO SERIAL: Ready for next message...
python3 main.py [OPTIONS]
Options:
-c, --config PATH Configuration file path (default: config/client_config.yaml)
-t, --test-mode Run with simulated messages
-s, --serial-test Test serial reception only
-p, --port DEVICE Override serial port (e.g., /dev/ttyUSB0)
-b, --baudrate RATE Override baudrate (e.g., 9600)
-l, --log-level LEVEL Override log level (DEBUG, INFO, WARNING, ERROR)
-v, --verbose Enable verbose output (DEBUG level)
-h, --help Show help messageProblem: Permission denied on /dev/ttyUSB0
# Add user to dialout group
sudo usermod -a -G dialout $USER
# Logout and login againProblem: Device not found
# Check available devices
ls -la /dev/ttyUSB*
ls -la /dev/ttyACM*
# Test with different device
python3 main.py --config config/rpi_config.yaml --port /dev/ttyUSB1Problem: Ollama not running
# Check Ollama service
sudo systemctl status ollama
sudo systemctl start ollama
# Test Ollama manually
ollama run tinyllama "test message"Problem: TinyLlama model not found
# Pull the model
ollama pull tinyllama
# Test API endpoint
curl http://localhost:11434/api/generate \
-d '{"model":"tinyllama","prompt":"test","stream":false}'Problem: High response times
- Increase timeout values in config
- Check TinyLLM model size and hardware
- Monitor system resources
Problem: Message loss
- Check serial cable quality
- Verify baud rate matches sender
- Enable DEBUG logging for detailed analysis
ArmGPT-server/
βββ src/
β βββ __init__.py
β βββ serial_client.py # Serial communication
β βββ message_processor.py # Message cleaning/validation
β βββ llm_interface.py # Ollama/TinyLLM integration
β βββ logger.py # Colored logging system
βββ config/
β βββ client_config.yaml # Default configuration
β βββ rpi_config.yaml # Raspberry Pi optimized
βββ logs/ # Log files (auto-created)
βββ tests/
β βββ test_serial_client.py
βββ main.py # Main application entry
βββ test_ollama.py # Ollama integration testing
βββ install_tinyllm_rpi.sh # Raspberry Pi setup script
βββ requirements.txt # Python dependencies
βββ README.md # This file
βββ README_RASPBERRY_PI.md # Pi-specific setup guide
βββ CHANGELOG.md # Project changelog
βββ python_prompt.md # Original project prompt
This client is designed to work with the existing ARM assembly program that:
- Sends messages via
/dev/ttyUSB0at 9600 baud - Uses ASCII encoding with
\nterminators - Implements hardware buffer flushing for reliability
- Provides menu-driven interface with test/custom/continuous modes
The client maintains full compatibility with existing bash testing tools like test-listener.sh.
The client tracks comprehensive statistics:
- Total messages received
- Valid vs invalid messages
- Message type distribution
- Processing success rate
- Request/response counts
- Average response times
- Failure rates and retry patterns
- Timeout occurrences
- Serial connection uptime
- Reconnection events
- Error rates by component
- Memory usage patterns
- Input validation prevents malformed messages
- No code execution from serial input
- Configurable message length limits
- Safe error handling prevents crashes
- Optional transaction logging for audit trails
This project is part of the ArmGPT-server system for educational and research purposes.
- Install on Raspberry Pi: Run
./install_tinyllm_rpi.shto set up Ollama - Test Integration: Run
python3 test_ollama.pyto verify Ollama works - Test Hardware: Verify serial connection with
python3 main.py --config config/rpi_config.yaml --serial-test - Go Live: Connect to ARM sender and run
python3 main.py --config config/rpi_config.yaml
π For detailed Raspberry Pi setup, see README_RASPBERRY_PI.md
π For complete change history, see CHANGELOG.md
For questions or issues, check the troubleshooting section or review the logs in the logs/ directory.
- β Fully implemented and tested on Raspberry Pi 4
- β ARM assembly integration confirmed working
- β TinyLlama AI responses generating successfully
- β Serial communication stable at 9600 baud
- β Automated deployment with installation script
- β Comprehensive documentation and troubleshooting guides