Giter Club home page Giter Club logo

catprinter's Introduction

Cat Printer

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.

Installation

# 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

$ 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.

Example

Printing an image

% 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.

Printing text (e.g. label)

% 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.

Different Algorithms

Mean Threshold: Mean threshold

Floyd Steinberg (default) Floyd Steinberg

Halftone dithering Halftone

catprinter's People

Contributors

c7h avatar david-lor avatar dependabot[bot] avatar hexpunk avatar jauderho avatar omgmog avatar rbaron avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.