Setting up a USB thermal printer with a Raspberry Pi 3B+
- Get link
- X
- Other Apps
It involves a few key steps. Here’s a complete guide to get it working:
1. Gather Required Materials
- Raspberry Pi 3B+ (with Raspbian OS installed)
- USB thermal printer
- USB cable to connect the printer
- Printer paper
- Power supply for the Raspberry Pi and printer
2. Connect the Printer
- Connect the thermal printer to the Raspberry Pi via the USB port.
- Ensure the printer is powered on and loaded with paper.
3. Install Required Packages
Open the terminal on your Raspberry Pi and install the necessary software:
Download the driver software for the printer.
Use install.sh file to install it.
$chmod +x install.sh // make the install.sh file executable
$sudo ./install.sh // run the install.sh
$sudo apt install cups libcups2-dev printer-driver-escpr
- CUPS (Common Unix Printing System) is a printing system that allows the Raspberry Pi to communicate with printers.
printer-driver-escprincludes drivers for many thermal printers.
4. Add User to the lpadmin Group
This gives your user permissions to manage printers:
$sudo usermod -a -G lpadmin pi
Log out and log back in to apply the changes.
5. Configure CUPS
Open the CUPS web interface:
$sudo cupsctl --remote-any$sudo systemctl restart cups- Go to the "Administration" tab in the CUPS interface.
- Click on "Add Printer."
- Select your thermal printer from the list of detected printers.
- Choose the appropriate driver for your printer (e.g., ESC/POS or a specific model).
Access the web interface by navigating to
http://localhost:631in your browser. You can Replacelocalhostwith your Raspberry Pi's IP address.Add your printer:
Configure printer settings as needed (e.g., paper size).
6. Test the Printer
Send a test print from the CUPS interface or the terminal:
echo "Test print from Raspberry Pi" | lp
7. Install Python Library for Thermal Printers (Optional)
If you plan to use Python for controlling the printer, install libraries like python-escpos:
Use virtual environment for few packages if pip install ask for --break-system-packages. Create a virtual environment in your project folder and then install the required packages.
- Create a virtual environment : Go the folder using CD command
- $cd /Project Folder/
- $python3 -m venv venvName #create virtual environment
- $source venvName/bin/activate #activate the environment
- Install following packages in the virtual environment:
- $pip install python-escpos
- $pip3 install pyusb
- $sudo apt install libusb-1.0-0-dev libudev-dev -y
- $sudo apt install usbutils
- $sudo nano /etc/udev/rules.d/99-escpos.rules
- add the below line in the file
- SUBSYSTEM=="usb", ATTRS{idVendor}=="0483", ATTRS{idProduct}=="5743", MODE="0666", GROUP="lp"
Example Python script for printing:
from escpos.printer import Usb
# Replace with your printer's VendorID and ProductID
printer = Usb(0x0483, 0x5743, 0)
printer.text("Hello, Thermal Printer!\n")
printer.cut()
printer.close()Find the Vendor ID and Product ID of your printer using following command:
$lsusb
8. Troubleshooting
- Printer not detected: Check the USB connection and power.
- Driver issues: Ensure you’ve selected the correct driver in CUPS.
- Permission errors: Ensure the
piuser is in thelpadmingroup.
Once everything is configured, your thermal printer should be ready for use with your Raspberry Pi 3B+.
- Get link
- X
- Other Apps
Comments
Post a Comment