A web-based label printing server for Brother P-touch printers using ESP32-S3-DevKitC-1 with ESP-IDF framework and USB Host support.
Based on the ptouch-print library - A comprehensive Brother P-touch protocol implementation with extensive debugging and fixes.
This project is in early development and has NOT been tested with any real Brother P-touch printers. Before using this code:
- β Do NOT use in production environments
- β Do NOT expect it to work with real printers without testing
- β No guarantee of compatibility with any Brother P-touch model
- β No validation of print quality or reliability
- β USB Host functionality is theoretical and untested
π§ͺ This is a development project that needs hardware testing and validation before any practical use.
This project is licensed under the GNU General Public License v3.0 (GPL-3.0) as it is a derivative work of the ptouch-print library.
- License: GPL-3.0
- Original Work: ptouch-print library by Familie Radermacher
- Derivative Work: ESP32-S3 port with web interface and USB Host implementation
This means you are free to use, modify, and distribute this software under the terms of the GPL-3.0 license. See the LICENSE file for the full license text.
This project is specifically designed for the ESP32-S3-DevKitC-1 Development Board with the following specifications:
- Microcontroller: ESP32-S3 (Xtensa dual-core, 240MHz)
- Flash Memory: 8MB (standard variant)
- RAM: 320KB
- Connectivity: WiFi 802.11 b/g/n (2.4GHz), Bluetooth 5.0 + BLE 5.0
- USB: Native USB Host support with ESP32-S3
- Architecture: Xtensa
- GPIO Pins: 22 digital I/O pins, 16 external interrupt pins, 6 analog input pins
Board specifications referenced from ESPBoards.dev
- ESP-IDF Framework: Ported to ESP-IDF v5.4.1 with configuration
- USB Host Stack: USB Host API implementation (untested with real printers)
- WiFi Connectivity: 802.11 b/g/n connection with auto-reconnect
- Web Server: HTTP server with embedded interface
- REST API: API endpoints for printer control (backend only)
- Brother P-touch Protocol: Protocol implementation ported from ptouch-print library
- Memory Optimization: Builds successfully with reasonable resource usage
- Debug System: USB packet logging and protocol analysis framework
- β No Real Printer Testing: Zero validation with actual Brother P-touch printers
- β USB Communication: USB Host implementation unverified with real hardware
- β Print Quality: No testing of actual print output or quality
- β Protocol Compatibility: Brother P-touch protocol untested on ESP32-S3
- β Error Handling: Real-world error scenarios not validated
- β Performance: No measurement of actual print speeds or reliability
- Build Status: β SUCCESS (compiles without errors)
- Compilation Time: ~44 seconds
- Flash Usage: 29.0% (911,804 / 3,145,728 bytes)
- RAM Usage: 10.6% (34,896 / 327,680 bytes)
- Available Space: 2.2MB flash remaining for future features
Important Notice: The Brother P-touch protocol implementation is derived from the extensively tested ptouch-print library. However, this ESP32-S3 port has not been validated with actual hardware and should be considered experimental until comprehensive testing is completed.
- π¨οΈ Brother P-touch Printer Support: Protocol implementation for 25+ Brother P-touch models (from ptouch-print)
- π Modern Web Interface: Responsive, mobile-friendly design with embedded assets
- π± Cross-Platform: Should work on desktop, tablet, and mobile devices
- π Native USB Host: Direct USB connection using ESP32-S3 USB Host APIs
- π¨ Label Design Tools: Text labels with formatting and layout options
- π Real-time Monitoring: Live printer status via WebSocket connection
- π·οΈ Multiple Tape Formats: Support for various tape sizes and types
- π Auto-Recovery: Automatic USB reconnection and error recovery
- β‘ High Performance: 240MHz dual-core processing with PSRAM support
- π‘οΈ Error Handling: Comprehensive error handling and stability (when tested)
- PT-D450, PT-D460BT, PT-D410, PT-D600, PT-D610BT
- PT-P700, PT-P750W, PT-P710BT, PT-P300BT
- PT-H500, PT-H300, PT-H300LI, PT-E500, PT-E310BT
- PT-2300, PT-2420PC, PT-2450PC, PT-2430PC, PT-2700, PT-2730
- PT-1230PC, PT-1950, PT-1960
- PT-9200DX, PT-9700PC, PT-9800PCN
Protocol support derived from ptouch-print library (25+ models) - actual compatibility unverified
- ESP32-S3-DevKitC-1 with 8MB Flash (standard variant)
- Available from: Amazon, AliExpress, electronics distributors
- Price range: ~$15-25 USD
- Brother P-touch Label Printer (from supported list)
- USB-A to USB-B Cable (standard printer cable)
- WiFi Network (2.4GHz, 802.11 b/g/n)
- Power Supply: 5V via USB-C (ESP32-S3-DevKitC-1)
- External Power Supply: For high-power printers
- USB Hub: For multiple printer support
- Case/Enclosure: For permanent installations
Option A: Using uv (Recommended)
# Install uv package manager
curl -LsSf https://astral.sh/uv/install.sh | sh
source $HOME/.local/bin/env
# Install PlatformIO
uv tool install platformioOption B: Using pip
# Install PlatformIO
pip install platformio# Clone the repository
git clone https://github.com/tanvach/ptouch-esp32.git
cd ptouch-esp32
# Copy configuration template
cp include/config.example.h include/config.hConfiguration: Edit the settings in include/config.h:
// Configuration settings in include/config.h
// WiFi Configuration
#define WIFI_SSID "Your_WiFi_Network" // π§ Set your WiFi network name
#define WIFI_PASSWORD "Your_WiFi_Password" // π§ Set your WiFi password
// Web server configuration
#define WEB_SERVER_PORT 80
// USB Debug configuration
#define ENABLE_USB_DEBUG true // π§ Set to true for debugging!
#define USB_DEBUG_LEVEL PTOUCH_DEBUG_LEVEL_INFO // Set debug levelDebug Levels Available:
PTOUCH_DEBUG_LEVEL_NONE- No debug output (production)PTOUCH_DEBUG_LEVEL_ERROR- Errors onlyPTOUCH_DEBUG_LEVEL_WARN- Warnings + errorsPTOUCH_DEBUG_LEVEL_INFO- General info (recommended for debugging)PTOUCH_DEBUG_LEVEL_DEBUG- Detailed logging with hex dumpsPTOUCH_DEBUG_LEVEL_VERBOSE- Everything (very detailed)
Debug Features: When enabled, you get comprehensive USB packet logging, Brother P-touch protocol analysis, interactive console commands, and performance statistics - perfect for troubleshooting printer communication!
# Build for ESP32-S3-DevKitC-1
pio run --environment esp32-s3-devkitc-1
# Upload firmware
pio run --environment esp32-s3-devkitc-1 --target upload
# Monitor serial output
pio device monitor --baud 115200Expected Output:
I (2340) main: WiFi connected to: Your_WiFi_Network
I (2345) main: IP address: 192.168.1.100
I (2350) main: Web server started on port 80
I (2355) usb_host: USB Host initialized successfully
I (2360) main: System ready - connect your printer!
- Access Interface: Navigate to
http://[ESP32_IP_ADDRESS]in your browser (if WiFi works) - Connect Printer: Plug your Brother P-touch printer into the ESP32-S3 via USB (may not work)
- Verify Connection: Check status panel for printer detection (unverified)
- Start Printing: Use the web interface to create and print labels (untested)
- π Status Dashboard: Real-time printer status and connection info (theoretical)
- βοΈ Text Labels: Rich text input with formatting options (web UI only)
- π Layout Tools: Margin, alignment, and sizing controls (not tested)
- π¨ Design Options: Font selection and text styling (implementation unclear)
- π Print Queue: Job management and history (not implemented)
- βοΈ Settings: Printer configuration and preferences (not implemented)
# Get printer status (may return placeholder data)
curl http://[ESP32_IP]/api/status
# Print text label (may fail with real printers)
curl -X POST http://[ESP32_IP]/api/print/text \
-H "Content-Type: application/json" \
-d '{"text": "Hello World!", "margin": 3}'
# Reconnect printer (functionality unverified)
curl -X POST http://[ESP32_IP]/api/reconnect
# List supported printers (theoretical list only)
curl http://[ESP32_IP]/api/printers// Connect to real-time updates (may not work)
const ws = new WebSocket('ws://[ESP32_IP]/ws');
// Listen for status updates (data may be placeholder)
ws.onmessage = (event) => {
const status = JSON.parse(event.data);
console.log('Printer:', status.connected ? 'Connected' : 'Disconnected');
console.log('Model:', status.model);
console.log('Status:', status.printerStatus);
};
// Send print commands (may fail with real printers)
ws.send(JSON.stringify({
command: 'printText',
text: 'Hello World!',
options: { margin: 3, copies: 1 }
}));- Native USB Host APIs: Direct hardware access with
usb_host.h - Advanced WiFi Management: Dual-mode support with
esp_wifi.h - HTTP Server: High-performance
esp_http_server.himplementation - FreeRTOS: Dual-core task management and real-time scheduling
- SPIFFS: Embedded file system for web assets
- PSRAM Support: Extended memory management
ESP32-S3 USB Host Stack
βββ Device Enumeration & Detection
βββ Endpoint Configuration & Management
βββ Bulk Transfer Implementation
βββ Error Handling & Recovery
βββ Status Monitoring & Events
βββ Brother P-touch Protocol Layer
- Dual-Core Processing: Protocol handling on dedicated core
- PSRAM Integration: Extended memory for large print jobs
- DMA Transfers: Hardware-accelerated USB communication
- Interrupt-Driven I/O: Non-blocking operations
- Connection Pooling: Persistent WebSocket connections
Recent Major Bug Fixes:
- β Initialization Sequence: Fixed 102-byte invalidate command
- β
PackBits Compression: Corrected compression command to
{0x4d, 0x02} - β Info Command: Fixed byte positioning and media width settings
- β D460BT Magic Commands: Updated magic sequences for newer models
- β Raster Data: Implemented proper PackBits compression
- β Print Finalization: Corrected eject (0x1a) and chain (0x0c) commands
- β Status Parsing: Enhanced error detection and reporting
ptouch-esp32/
βββ platformio.ini # ESP32-S3 configuration
βββ sdkconfig.defaults # ESP-IDF optimized settings
βββ default_8MB.csv # Custom partition table (8MB)
βββ include/
β βββ config.example.h # Configuration template
β βββ ptouch_esp32.h # Main library header
βββ src/
β βββ main.cpp # Application entry point (ESP-IDF)
βββ components/
β βββ ptouch-esp32/ # ESP-IDF component
β βββ CMakeLists.txt # Component build config
β βββ include/
β β βββ ptouch_esp32.h # Public API
β βββ src/
β βββ ptouch_printer.cpp # Core printer logic
β βββ ptouch_printing.cpp # Print job management
β βββ ptouch_image.cpp # Image processing
β βββ ptouch_utils.cpp # Utility functions
βββ examples/
βββ basic_printing/ # Arduino-style examples
βββ basic_printing.ino
- ESP-IDF Build System: Compilation successful
- USB Host Stack: Code compiles but hardware enumeration NOT tested
- WiFi Connectivity: Basic connection code implemented (not stress tested)
- Web Server: Basic HTTP server code (not load tested)
- Protocol Implementation: Code review against original library only
- Memory Management: No stress testing performed
- Error Handling: Code paths exist but not validated with real scenarios
- β NO ACTUAL PRINTER TESTING: Zero validation with any Brother P-touch printer
- β USB Host Functionality: ESP32-S3 USB Host communication not validated
- β Print Quality Assessment: No print output testing whatsoever
- β Protocol Compatibility: Brother P-touch protocol not tested on ESP32-S3
- β Long-term Stability: No extended operation testing
- β Edge Case Handling: No testing of unusual printer behaviors
- β Performance Benchmarking: No measurement of actual print speeds
- β Error Recovery: Real-world error scenarios not tested
A comprehensive mock-based testing suite is available for software validation:
π Complete Testing Guide - Detailed documentation covering:
- Test Architecture: Custom lightweight framework with hardware mocks
- Build & Run Instructions: Step-by-step setup and execution
- Test Categories: 22 tests covering USB Host, protocol, integration scenarios
- Mock Capabilities: Simulated Brother P-touch printers with error injection
- Blind Spots: Honest assessment of what's NOT tested (real hardware, timing, electrical)
- Future Roadmap: Plans for hardware-in-the-loop testing
Quick Start:
cd test
mkdir -p build && cd build
cmake .. && make
./ptouch_tests --verboseβ All 22 tests passing with comprehensive USB Host simulation, protocol validation, and error handling scenarios.
This project URGENTLY needs hardware testing before any other development work.
This is the #1 priority. Before any other features or improvements:
- Test with actual Brother P-touch printers (any model)
- Report whether USB Host detection works at all
- Document any printer communication (success or failure)
- Share detailed error messages and logs
- Test basic print functionality
If you test with hardware, please provide:
- ESP32-S3 Board: Exact model and specifications
- Printer Model: Exact model number and firmware version
- Connection Results: Success/failure with detailed error messages
- USB Host Behavior: Device enumeration, communication attempts
- Print Results: Did anything print? Quality? Errors?
- Serial Output: Complete logs with debug enabled
- Issues Found: Every bug, crash, or unexpected behavior
- Fix hardware compatibility issues
- Additional printer model support
- Advanced label design features
- Performance optimizations
- Mobile app development
- Cloud integration
# Check USB Host initialization
pio device monitor --filter=esp32_exception_decoderPotential Solutions (NOT VALIDATED):
- Printer Not Detected: Try different USB cable, check power (may not help)
- Connection Timeouts: Increase timeout in configuration (untested)
- Transfer Errors: Verify adequate power supply (5V, 2A recommended) (theoretical)
- Enumeration Failures: Some printers need warm-up time (assumption only)
# Clean build environment
pio run --target clean
# Verify ESP-IDF configuration
pio run --environment esp32-s3-devkitc-1 --verboseConfiguration Checks:
- Flash Size: Verify 8MB flash detection
- Partition Table: Ensure
default_8MB.csvis used - Board Type: Confirm
esp32-s3-devkitc-1target - Dependencies: Check ArduinoJson library installation
- WiFi Connection: Verify 2.4GHz network (5GHz not supported)
- IP Assignment: Check DHCP configuration
- Firewall: Ensure port 80 access allowed
- Browser Cache: Clear cache if web interface doesn't load
Current Optimization (8MB Flash):
- Application Size: 897KB (28.5% of flash)
- Available Flash: 2.2MB for future features
- RAM Usage: 34KB (10.6% of 320KB)
- Partition Layout:
- Application: 3MB
- Storage (FAT): 1MB
- SPIFFS: 4MB
- System: 256KB
This project is licensed under the MIT License. See the LICENSE file for full details.
- ptouch-print by Dominic Radermacher - Original protocol implementation
- Espressif Systems - ESP-IDF framework and ESP32-S3 hardware
- ESP Boards Database - Comprehensive ESP32 board specifications
- uv Package Manager by Astral - Modern Python package management
Getting Help:
- π Bug Reports: Open GitHub Issue
- π¬ Discussions: GitHub Discussions
- π Documentation: Check troubleshooting section above
- π€ Community: Hardware testing reports welcome!
Before Opening Issues:
- Check existing issues and discussions
- Include printer model and ESP32-S3 board details
- Provide serial monitor output
- Include steps to reproduce problems
This project is licensed under the GNU General Public License v3.0 (GPL-3.0).
- Based on: ptouch-print library
- Original Authors: Familie Radermacher and contributors
- Original License: GPL-3.0
- Derivative Work: ESP32-S3 port with web interface and USB Host implementation
- β Commercial Use: Permitted
- β Modification: Permitted
- β Distribution: Permitted
- β Private Use: Permitted
- β License and Copyright Notice: Required
- β State Changes: Must document modifications
- β Disclose Source: Must provide source code
- β Same License: Derivative works must use GPL-3.0
For the full license text, see the LICENSE file.
By contributing to this project, you agree that your contributions will be licensed under the GPL-3.0 license.
Disclaimer: This project is not affiliated with Brother Industries, Ltd. Brother and P-touch are registered trademarks of Brother Industries, Ltd. This software is provided "as is" without warranty of any kind as specified in the GPL-3.0 license.