English | ç®€ä½“ä¸æ–‡
A CLI for Niimbot thermal label printers, written in pure C: libc, termios,
and Linux sockets only. No external dependencies — it ships its own PNG/DEFLATE
decoder, protocol implementation, and rasterizer.
Hardware testing: only Niimbot B1 Pro (id 0x1001, 300 dpi, 567-dot
printhead) over USB. Other models (B1, B21, B18, D11, D110) are implemented
from the protocol documentation and verified against an emulator, but not on
real hardware. Bluetooth (RFCOMM/SPP) is also untested on hardware.
makeRequirements: Linux, gcc or clang, make. The binary is niimcli, object files
live in build/; make clean removes both.
Arch/Manjaro:
sudo usermod -aG uucp "$USER" # then log in againDebian/Ubuntu use the dialout group. Alternatively, run with sudo.
# identify the model, protocol, dpi and printhead width
./niimcli -a /dev/ttyACM0 --info
# print the 48x30 mm, 300 dpi example (B1 Pro)
sudo ./niimcli -m auto -a /dev/ttyACM0 -i examples/48x30mm_300dpi.png -d 3 -m, --model MODEL b1|b18|b21|d11|d110|auto (default: b21)
-c, --conn CONN usb|bluetooth (default: usb)
-a, --addr ADDR Bluetooth MAC or serial device path
-d, --density N print density 1..5 (default: 5)
-r, --rotate DEG 0|90|180|270 clockwise (default: 0)
-i, --image PATH image to print, PNG or PNM
--width-mm MM scale image to this physical width
-n, --dry-run encode only, write 1-bit PBM to stdout
--info query printer model and protocol, then exit
--reverse-feed experimental 0x1E reverse feed
(used alone if --image is omitted)
--serial-cmd TEXT send text to the USB service console
--serial-eol MODE crlf|cr|lf|none (default: crlf)
-v, --verbose dump packets
-h, --help show this help
-m auto queries the printer and selects the protocol, dpi and printhead width
automatically. For a B1 Pro that means 300 dpi and 567 px.
The printer maps one image pixel to one printhead dot. DPI metadata in the file is ignored. The physical size is:
width_mm = pixels * 25.4 / dpi
| Model | dpi | Printhead | Max width |
|---|---|---|---|
| B1 Pro | 300 | 567 px | 48 mm |
| B1 / B21 | 203 | 384 px | 48 mm |
| D11 / D110 | 203 | 96 px | 12 mm |
Images wider than the printhead are scaled down automatically. Narrower images
are not upscaled: use --width-mm N to target a physical width (for example
--width-mm 50; excess is clamped to the printhead).
-n/--dry-run shows exactly what would be sent: a 1-bit PBM on stdout, no
connection needed.
./niimcli -n -m b1 -i image.png --width-mm 48 > out.pbm- PNG: non-interlaced, 1/2/4/8/16-bit depth, grayscale/RGB/palette/RGBA. Transparency is composited onto white.
- PNM: P4, P5, P6.
- JPEG is not supported.
Before sending, the image is converted to luma, inverted and Floyd–Steinberg dithered (same as Pillow). Thermal printers are binary, so gradients are reproduced only as dot density.
BlueZ must be running. The connection uses RFCOMM/SPP, channel 1:
sudo ./niimcli -m auto -c bluetooth -a AA:BB:CC:DD:EE:FF -i examples/48x30mm_300dpi.pngSome models advertise two MAC addresses with the same last three bytes; the
working one is the address that lists a Serial Port UUID in bluetoothctl info.
-vdumps every protocol frame (send:/recv:).--serial-cmd TEXTtalks to the printer's service console while the printer is off (charge mode), for example--serial-cmd "#10001".--reverse-feedis an experimental0x1Ecommand. B1/B1 Pro answer "not supported"; there is no standard label rewind in the protocol.
MIT, see LICENSE.
Protocol commands come from public documentation and reverse engineering (see Acknowledgements). The implementation itself is original code.
- NIIMBOT Community Wiki — protocol documentation (CC BY-SA 4.0).
- niimbluelib (MIT) — cross-check of command sequences and print modes.
- niimprint (MIT) — the original Python client.
- Dithering follows the Pillow implementation (Copyright © 1997-2011 by Secret Labs AB, Copyright © 1995-2011 by Fredrik Lundh, HPND license).