Cat printer is a portable thermal printer sold on AliExpress for around $20.
This repository contains Python code for talking to the cat printer over Bluetooth Low Energy (BLE). The code has been reverse engineered from the official Android app.
# Clone the repository.
$ git clone [email protected]:rbaron/catprinter.git
$ cd catprinter
# Create a virtualenv on venv/ and activate it.
$ virtualenv --python=python3 venv
$ source venv/bin/activate
# Install requirements from requirements.txt.
$ pip install -r requirements.txt
$ python print.py image --help
usage: print.py [-h] [--log-level {debug,info,warn,error}] [--img-binarization-algo {mean-threshold,floyd-steinberg,halftone}]
[--show-preview] [--devicename DEVICENAME] [--darker]
filename
prints an image on your cat thermal printer
positional arguments:
filename
options:
-h, --help show this help message and exit
--log-level {debug,info,warn,error}
--img-binarization-algo {mean-threshold,floyd-steinberg,halftone}
Which image binarization algorithm to use.
--show-preview If set, displays the final image and asks the user for confirmation before printing.
--devicename DEVICENAME
Specify the Bluetooth Low Energy (BLE) device name to search for. If not specified, the script will try to
auto discover the printer based on its advertised BLE service UUIDs. Common names are similar to "GT01",
"GB02", "GB03".
--darker Print the image in text mode. This leads to more contrast, but slower speed.
% python print.py image --show-preview --filename test.png
โณ Applying Floyd-Steinberg dithering to image...
โ
Done.
โน๏ธ Displaying preview.
๐ค Go ahead with print? [Y/n]?
โ
Read image: (42, 384) (h, w) pixels
โ
Generated BLE commands: 2353 bytes
โณ Looking for a BLE device named GT01...
โ
Got it. Address: 09480C21-65B5-477B-B475-C797CD0D6B1C: GT01
โณ Connecting to 09480C21-65B5-477B-B475-C797CD0D6B1C: GT01...
โ
Connected: True; MTU: 104
โณ Sending 2353 bytes of data in chunks of 101 bytes...
โ
Done.
% python print.py text --show-preview --text "Line 1\nLine two\nLine three"
โน๏ธ Displaying preview.
๐ค Go ahead with print? [Y/n]? Y
โ
Read image: (106, 384) (h, w) pixels
โ
Generated BLE commands: 3570 bytes
โณ Trying to auto-discover a printer...
โ
Got it. Address: E31574CB-2169-4958-D8DC-33A7603F0E09: GB03
โณ Connecting to E31574CB-2169-4958-D8DC-33A7603F0E09: GB03...
โ
Connected: True; MTU: 248
โณ Sending 3570 bytes of data in chunks of 245 bytes...
โ
Done.