Skip to content

SebastianAigner/Thermal-Kotlin

Repository files navigation

Thermal-Kotlin

Kotlin Driver for A2 Micro Panel Thermal Printer. Provides an easy to use API to print text and images to the 2.25" printer model. (Get one here)

Adafruit Thermal Printer Example

Features

  • Print text strings
  • Underline text
  • Bold Text
  • Inverse Text
  • Automatic Line Breaks for Text
  • Print 1-bit images
  • Resize and dither colored images (using Floyd-Steinberg dithering)
  • Throttled data transfer to allow for large images
  • Rich text string DSL
  • Print barcodes

Usage with Gradle

Step 1: Add the JitPack repository to your build file:

allprojects {
	repositories {
		//...
		maven { url 'https://jitpack.io' }
	}
}

Step 2: Add the dependency:

dependencies {
	implementation 'com.github.SebastianAigner:Thermal-Kotlin:master-SNAPSHOT'
}

This library is still very new, and has not reached a stable state yet. Expect changes in the API from snapshot to snapshot. To bind yourself to a specific commit, check out the Commits tab on JitPack.

Quick Start

  1. Set up the printer using val printer = ThermalPrinter("/dev/serial0", 19200), adjusting communication port and Baud rate if necessary.
  2. Connect to the printer using printer.connect().
  3. Write text using printer.writeLine() for a single line and printer.writeText if you need automatic line-breaking.
  4. Adjust text by changing the doubleWidth, justification, inverted, bold properties. Don't forget to change them back when you're done!
  5. Print images calling writeImage() with a BufferedImage of your choice. It is automatically scaled and dithered.
  6. Close the connection using printer.disconnect().

How to determine Baud rate

Disconnect the Thermal Printer from the power supply. Press and hold the paper feed button, and plug in the power. The printer will output a Character Code Table as well as its Baudrate and other useful information that might be interesting for debugging.

Further Reading

About

Kotlin Driver for A2 Micro Panel Thermal Printer

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages