A Raspberry Pi print server for the Epson TM-m50II-H receipt printer. Receives print jobs over HTTP via ngrok and prints formatted receipts using a custom font and banner image.
- Raspberry Pi 4 Model B
- Epson TM-m50II-H receipt printer (USB)
- MicroSD card (32GB+)
- USB-C power supply (15W/3A)
| File | Description |
|---|---|
server.py |
Flask server that receives print jobs and sends them to the printer |
receipt.py |
Receipt builder — handles image rendering, font, banner tiling, and ESC/POS output |
start.sh |
Startup script that runs Flask and ngrok together |
SweetBastard-Regular.otf |
Custom font used for receipt text |
SBDiamond.png |
Banner image tiled across the top and bottom of each receipt |
Download Raspberry Pi Imager on your laptop.
- Device: Raspberry Pi 4
- OS: Raspberry Pi OS Lite (64-bit)
- Click the pencil/settings icon before writing and configure:
- Hostname
- Username and password
- WiFi network name and password
- Enable SSH (under the Services tab) → Use password authentication
Write to the SD card, insert into the Pi, and power on. Wait 90 seconds for first boot.
From your laptop terminal:
ssh -v yourusername@yourhostname.localOr use the IP address if the hostname doesn't resolve:
ssh yourusername@192.168.x.xFind the IP by checking your router's connected devices list or running ping yourhostname.local.
sudo apt update && sudo apt upgrade -ysudo apt install python3-pip python3-pil libusb-1.0-0 git -y
pip3 install flask python-escpos pyusb pillow --break-system-packagescd ~
git clone https://github.com/svralph/sb-printer.git
cd sb-printer
cp * ~/
cd ~echo "blacklist usblp" | sudo tee /etc/modprobe.d/blacklist-usblp.conf
echo "install usblp /bin/false" | sudo tee -a /etc/modprobe.d/blacklist-usblp.conf
sudo update-initramfs -uSign up for a free account at ngrok.com, then:
curl -s https://ngrok-agent.s3.amazonaws.com/ngrok.asc | sudo tee /etc/apt/trusted.gpg.d/ngrok.asc >/dev/null
echo "deb https://ngrok-agent.s3.amazonaws.com buster main" | sudo tee /etc/apt/sources.list.d/ngrok.list
sudo apt update && sudo apt install ngrok -y
ngrok config add-authtoken YOUR_TOKEN_HEREPlug in the printer and run:
lsusbYou should see the Epson listed as ID 04b8:0e34. If your printer has different IDs, update the Usb(0x04b8, 0x0e34 ...) lines in receipt.py and server.py to match.
Every time you need the print server running:
./start.shThis will:
- Remove the
usblpkernel module - Start the Flask server on port 5000
- Start ngrok and expose it publicly
Copy the ngrok URL that appears (e.g. https://abc123.ngrok-free.app) and update it in your client app.
To run Flask and ngrok in separate terminals instead:
Terminal 1:
sudo rmmod usblp 2>/dev/null
python3 server.pyTerminal 2:
ngrok http 5000Send a POST request to your ngrok URL:
curl -X POST https://YOUR-NGROK-URL/print \
-H "Content-Type: application/json" \
-d '{"text": "your receipt text here"}'Or from Python/Node:
import requests
requests.post(
"https://YOUR-NGROK-URL/print",
json={"text": "your receipt text here"}
)await fetch("https://YOUR-NGROK-URL/print", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ text: "your receipt text here" })
});If the Pi is already running and you want to add a new network:
sudo nmcli dev wifi connect "NetworkName" password "NetworkPassword"If you can't SSH in (e.g. moving to a new location), reflash the SD card with the new WiFi credentials using Raspberry Pi Imager, then clone this repo again after booting.
SSH times out — SSH may not be enabled. Reflash the SD card and make sure "Enable SSH" is checked in the Imager settings.
Printer not found (lsusb shows nothing) — Check USB cable, try a different port, make sure the printer is powered on.
[Errno 16] Resource busy — The usblp kernel module has reloaded. Run sudo rmmod usblp then restart Flask.
ngrok URL not working — The URL changes every time ngrok restarts. Check the current URL in the ngrok terminal and update your client app.
Nothing prints but no error — Check the printer display for error messages, make sure paper is loaded, and try the printer's feed button to confirm it's online.