Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rbaron/catprinter
đąđ¨
https://github.com/rbaron/catprinter
Last synced: about 1 month ago
JSON representation
đąđ¨
- Host: GitHub
- URL: https://github.com/rbaron/catprinter
- Owner: rbaron
- License: mit
- Created: 2021-08-14T07:26:18.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-08-27T07:54:44.000Z (4 months ago)
- Last Synced: 2024-08-27T22:15:24.883Z (4 months ago)
- Language: Python
- Size: 4.7 MB
- Stars: 737
- Watchers: 6
- Forks: 53
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- starred - rbaron/catprinter - đąđ¨ (Python)
README
![Cat Printer](./media/hackoclock.jpg)
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](https://play.google.com/store/apps/details?id=com.frogtosea.iprint&hl=en_US&gl=US).
# Installation
```bash
# 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
```# Usage
```bash
$ ./print.py --help
usage: print.py [-h] [-l {debug,info,warn,error}] [-b {mean-threshold,floyd-steinberg,atkinson,halftone,none}] [-s] [-d DEVICE] [-e ENERGY]
filenameprints an image on your cat thermal printer
positional arguments:
filenameoptions:
-h, --help show this help message and exit
-l {debug,info,warn,error}, --log-level {debug,info,warn,error}
-b {mean-threshold,floyd-steinberg,atkinson,halftone,none}, --img-binarization-algo {mean-threshold,floyd-steinberg,atkinson,halftone,none}
Which image binarization algorithm to use. If 'none' is used, no binarization will be used. In this case the image has to
have a width of 384 px.
-s, --show-preview If set, displays the final image and asks the user for confirmation before printing.
-d DEVICE, --device DEVICE
The printer's Bluetooth Low Energy (BLE) address (MAC address on Linux; UUID on macOS) or advertisement name (e.g.:
"GT01", "GB02", "GB03"). If omitted, the the script will try to auto discover the printer based on its advertised BLE
services.
-e ENERGY, --energy ENERGY
Thermal energy. Between 0x0000 (light) and 0xffff (darker, default).
```# Example
```bash
% ./print.py --show-preview 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.
```# Different Algorithms
**Mean Threshold:**
![Mean threshold](./media/grumpymeanthreshold.png)
**Floyd Steinberg (default):**
![Floyd Steinberg](./media/grumpyfloydsteinbergexample.png)
**Atkinson:**
![Atkinson](./media/grumpyatkinsonexample.png)
**Halftone dithering:**
![Halftone](./media/grumpyhalftone.png)
**None (image must be 384px wide):**
![None](./media/grumpynone.png)