This repository has been archived by the owner on Jun 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathprintertest.py
executable file
·89 lines (71 loc) · 2.53 KB
/
printertest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/python
from Adafruit_Thermal import *
from machine import Pin
# Feel free to experiment with heatdots, heattime and heatiniterval
# to nail down your printer's sweet spot :)
printer = Adafruit_Thermal(pins=(Pin.exp_board.G14,), heatdots=5, heatinterval=40)
# Test inverse on & off
printer.inverseOn()
printer.println("Inverse ON")
printer.inverseOff()
# Test character double-height on & off
printer.doubleHeightOn()
printer.println("Double Height ON")
printer.doubleHeightOff()
# Set justification (right, center, left) -- accepts 'L', 'C', 'R'
printer.justify('R')
printer.println("Right justified")
printer.justify('C')
printer.println("Center justified")
printer.justify('L')
printer.println("Left justified")
# Test more styles
printer.boldOn()
printer.println("Bold text")
printer.boldOff()
printer.underlineOn()
printer.println("Underlined text")
printer.underlineOff()
printer.setSize('L') # Set type size, accepts 'S', 'M', 'L'
printer.println("Large")
printer.setSize('M')
printer.println("Medium")
printer.setSize('S')
printer.println("Small")
printer.justify('C')
printer.println("normal\nline\nspacing")
printer.setLineHeight(50)
printer.println("Taller\nline\nspacing")
printer.setLineHeight() # Reset to default
printer.justify('L')
# Change printer settings for smoother barcodes
printer = Adafruit_Thermal(pins=(Pin.exp_board.G14,), heatdots=4, heattime=120, heatinterval=80)
# Barcode examples
printer.feed(1)
# CODE39 is the most common alphanumeric barcode
printer.printBarcode("ADAFRUT", printer.CODE39)
printer.setBarcodeHeight(100)
# Print UPC line on product barcodes
printer.printBarcode("123456789123", printer.UPC_A)
time.sleep(2)
# These settings allow for much cleaner output when printing images
printer = Adafruit_Thermal(pins=(Pin.exp_board.G14,), heatdots=1, heattime=155, heatinterval=1)
# # Print the 75x75 pixel logo in adalogo.py
import adalogo
printer.printBitmap(adalogo.width, adalogo.height, adalogo.data, LaaT=True)
printer.println("Adafruit!")
try:
# # Print the 135x135 pixel QR code stored in the file on disk
printer.printBitmapFromFile(135, 135, '/flash/gfx/qrcode')
# TODO: figure out what's wrong here
time.sleep(2)
# # Print some .bmp bitmap images
printer.printBMPImage('/flash/gfx/aykm.bmp')
printer.printBMPImage('/flash/gfx/notbad.bmp')
except OSError as e:
print(e.errno)
pass
printer.feed(3)
# printer.sleep() # Tell printer to sleep
# printer.wake() # Call wake() before printing again, even if reset
# printer.setDefault() # Restore printer to defaults