All Projects → bitrate16 → ppa6-python

bitrate16 / ppa6-python

Licence: MIT license
Python module and documentation for direct printing on Peripage A6 / A6+ thermal printer via bluetooth

Programming Languages

python
139335 projects - #7 most used programming language
Jupyter Notebook
11667 projects
Batchfile
5799 projects

Projects that are alternatives of or similar to ppa6-python

MindSetUWP
NeuroSky MindWave & MindWave Mobile EEG Headset library for Windows 10 Universal applications
Stars: ✭ 14 (-62.16%)
Mutual labels:  bluetooth
ZfSnapGeoip
Maxmind Geoip module for Zend Framework 2
Stars: ✭ 15 (-59.46%)
Mutual labels:  module
atomic-calendar-revive
An advanced calendar card for Home Assistant Lovelace.
Stars: ✭ 218 (+489.19%)
Mutual labels:  module
cala
Cross-platform system interface for hardware IO
Stars: ✭ 46 (+24.32%)
Mutual labels:  bluetooth
netdev stdlib
Netdev is a vendor-neutral network abstraction framework maintained by Puppet, Inc
Stars: ✭ 30 (-18.92%)
Mutual labels:  module
SmartSpin2k
Transform your spin bike into a Smart Trainer!
Stars: ✭ 88 (+137.84%)
Mutual labels:  bluetooth
icingaweb2-module-businessprocess
Create top-level views of your applications in a graphical editor. Rules express dependencies between existing hosts and services and let you alert on application level. Business processes are displayed in a tree or list overview.
Stars: ✭ 106 (+186.49%)
Mutual labels:  module
theheraldproject.github.io
Herald - Proximity Detection Protocol and research documentation, including the Fair Efficacy Formula
Stars: ✭ 17 (-54.05%)
Mutual labels:  bluetooth
react-native-easybluetooth-classic
⚛ A Library for easy implementation of Serial Bluetooth Classic on React Native (Android Only).
Stars: ✭ 44 (+18.92%)
Mutual labels:  bluetooth
DualSenseWindows UE4
Unreal Engine 4 port of the Windows API for the PS5 DualSense controller created at Ohjurot/DualSense-Windows
Stars: ✭ 25 (-32.43%)
Mutual labels:  bluetooth
iconsole-android
OpeniConsole connects to an iConsole+ fitness bike head unit over bluetooth.
Stars: ✭ 27 (-27.03%)
Mutual labels:  bluetooth
SnipWire
Full Snipcart shopping cart integration for ProcessWire CMF
Stars: ✭ 16 (-56.76%)
Mutual labels:  module
polybar-bluetooth
A fully functional bluetooth module for polybar
Stars: ✭ 59 (+59.46%)
Mutual labels:  bluetooth
SwiftyTeeth
A simple, lightweight library intended to take away some of the cruft and tediousness of using CoreBluetooth
Stars: ✭ 21 (-43.24%)
Mutual labels:  bluetooth
diffusion-maps
Fast computation of diffusion maps and geometric harmonics in Python
Stars: ✭ 36 (-2.7%)
Mutual labels:  module
daydream-node
Quick Node.js module to connect to the Daydream controller and receive all the data
Stars: ✭ 17 (-54.05%)
Mutual labels:  bluetooth
puppetlabs-docker
The Puppet Docker repository
Stars: ✭ 78 (+110.81%)
Mutual labels:  module
wiimote-webhid
A Wiimote implementation using WebHID - AKA: Wiimote for the Web
Stars: ✭ 31 (-16.22%)
Mutual labels:  bluetooth
icingaweb2-module-fileshipper
Provide CSV, JSON, XML and YAML files as an Import Source for the Icinga Director and optionally ship hand-crafted additional Icinga2 config files
Stars: ✭ 25 (-32.43%)
Mutual labels:  module
automatic-vendor-federation
Utility to enable automatic vendor sharing within bundles using Module Federation
Stars: ✭ 69 (+86.49%)
Mutual labels:  module

ppa6-python

Python module for printing on Peripage A6 and A6+

This project is a continued development of the original project made by Elias Weingärtner. This module combined all results of reverse engineering of the Peripage A6/A6+ protocol in a python utility providing interface and CLI tool for printing on this thermal printer.

The original introduction

The Peripage A6 F622 is an inexpensive portable thermal printer. It provides both Bluetooth and USB connectivity. Unlike most other thermo printers it does not seem to support ESC/POS or any other standardized printer control language.

So far, the Peripage A6 F622 can be only controlled using a proprietary app (iOS / Anndroid). There is also a driver for Windows with many limitations, most notably the need of defining a page size before printing; this is a huge limitation, as the Peripage prints on continuous form paper.

The script provided here was built based on an analysis of captured Bluetooth traffic between the printer and an Android device. The Peripage A6 uses the serial profile (BTSPP) and RFCOMM.

Essentially, the script takes an input images, scales it to the printers native X resolution of 384 pixels, and then sends it to the printer.

Current abilities

  • Printing text of any length encoded in ASCII
  • Printing Images using PIL library
  • Printing raw bytes representing image in binary (black/white) form
  • Printing a page break of desired size (in pixels)
  • Printing using generator/iterator which returns image row by row in form of bytes or PIL Images
  • Requesting printer details (Serial Number, Name, Battery Level, Hardware Info and an option the meaning of which i don't know)
  • Configuring print concentration (light, gray, black)
  • Configuring printer poweroff timeout

Prerequirements

  • Peripage A6/A6+ printer
  • Python 3

Installation

Install from git clone

pip install -r requirements.txt
pip install . --user

Install from pypi using pip

pip install ppa6

Dependencies

  • PyBluez==0.30
  • Pillow==8.1.2
  • argparse==1.1 (for CLI)

Install dependencies with pip install -r requirements.txt

On windows you may need to install PyBluez 0.3

git clone https://github.com/pybluez/pybluez
cd pybluez
pip install . --user

On raspberry pi it may require to install additional libraries

sudo apt install libbluetooth-dev libopenjp2-7 libtiff5

And in some cases you will have to restart the bluetooth adapter and service on raspberry pi when it fails to connect or device is busy

sudo systemctl restart bluetooth
sudo hciconfig hci0 reset

Identify printer Bluetooth MAC address

On linux:

user@name:~$ hcitool scan
Scanning ..
00:15:83:15:bc:5f    PeriPage+BC5F

On windows:

You may use BluetoothCL

PS E:\E\E> .\BluetoothCL.exe
BluetoothCL v1.07
Copyright (c) 2009 - 2014 Nir Sofer
Web Site: http://www.nirsoft.net

syntax:
BluetoothCL -timeout [seconds]

-timeout is optional parameter. The default value is 15 seconds.


Scanning bluetooth devices... please wait.

00:15:83:15:bc:5f    Imaging                         PeriPage+BC5F

CLI usage

On linux

Install module and run ppa6 <args>

On windows

Install module and run python -m ppa6 <args>

Options

usage: ppa6 [-h] -m MAC [-c [0-2]] [-b [0-255]] [-p {A6,A6p,A6+}] [-n]
                   (-t TEXT | -s | -i IMAGE | -q QR | -e)

Print on a Peripage A6 / A6+ via bluetooth

optional arguments:
  -h, --help            show this help message and exit
  -m MAC, --mac MAC     Bluetooth MAC address of the printer
  -c [0-2], --concentration [0-2]
                        Concentration value for printing (0, 1, 2)
  -b [0-255], --break [0-255]
                        Size of the break that should be inserted after the
                        print (max 255)
  -p {A6,A6p,A6+}, --printer {A6,A6p,A6+}
                        Printer model name (A6 or A6+/A6p (both allowed))
  -n, --newline         Force printer to add newline at the end of the printed
                        text and flush the buffer
  -t TEXT, --text TEXT  ASCII text that should be printed. Add a line break at
                        the end of the string to avoid it being cut. String
                        can be empty, so just page break will be printed
  -s, --stream          Reads an input from stdin and prints as ASCII text
  -i IMAGE, --image IMAGE
                        Path to the image that should be printed
  -q QR, --qr QR        String for QR code print
  -e, --introduce       Ask the printer to introduce himself

Print image example

Print image from file with following break for 100px and concentration set to 2 (HIGH) on A6+

ppa6 -m 00:15:83:15:bc:5f -p A6p -b 100 -c 2 -i honk.png

Print text example

Print some random text followed by newline and break for 100px on A6+

ppa6 -m 00:15:83:15:bc:5f -p A6p -b 100 -t "HONK" -n

Newline is required to fush the internal printer buffer and force it to print all text without cutting

Print Service example

Print 50 text tasks on A6+

import ppa6
import print_service

# Ping battery every 60 seconds
# Send task every 5 seconds
# Try to reconnect after waiting 5 seconds
# Wait 1 second before send after connecting/reconnecting to printer
# Print only after pinging printer and waiting for 1 second
service = print_service.PrintService(60, 5, 5, 1, 1)
service.start('00:15:83:15:bc:5f', ppa6.PrinterType.A6p)
for i in range(50):
	service.add_print_ascii(f'number {i}', flush=True)

Newline is required to fush the internal printer buffer and force it to print all text without cutting

Suggestions

  • Don't forget about concentration, this can make print brighter and better visible.
  • Split long images into multiple print requests with cooldown time for printer (printer may overheat during a long print and will stop printing for a while. This will result in partial print loss because the internal buffer is about 250px height). For example, when you print looooooooooooooooooooooooooooooongcat.jpg, split it into at least 20 pieces with 1-2 minutes delay because you will definetly loose something without cooling. Printer gets hot very fast. Yes, it was the first that i've printed.
  • Be carefull when printing lots of black or using max concentration, as i said, printer heats up very fast.
  • The picture printed at maximum concentration has the longest shelf life.
  • Turn printer off then long press the power button till it becomes orange. Release the button and look at the another useless feature.
  • Be aware of cats, they have paws 🐾

Code example

View this python notebook for tutorial

Printer disassembly

Disassembly for A6+

TODO

  • Fix page sometimes get cutted off for some rows
  • Fix delays
  • Python 2.7 support
  • Implement overheat protection
  • Implement cover open handler
  • Tweak wait timings to precisely match the printing speed
  • Implement printer renaming
  • Implement printing stop operation
  • Reverse-engineer USB driver and add support for it
  • FIX: Print randomly gets cropped (some images getting cropped)
  • FIX: 1 type conversion is low quality

Credits

Disclaimer

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

License

MIT License

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].