|
3 | 3 | import board
|
4 | 4 | import busio
|
5 | 5 |
|
6 |
| -# Pick which version thermal printer to import. Only ONE of these lines should |
7 |
| -# be uncommented depending on the version of your printer. Hold the button on |
8 |
| -# the printer as it's powered on and it will print a test page that displays |
9 |
| -# the firmware version, like 2.64, 2.68, etc. |
10 |
| -# Use this line for printers with version 2.68 or higher: |
11 |
| -import adafruit_thermal_printer.thermal_printer as thermal_printer |
12 |
| -# Use this line for printers with version 2.64 up to (but not including) 2.68: |
13 |
| -#import adafruit_thermal_printer.thermal_printer_264 as thermal_printer |
14 |
| -# Use this line for printers with version up to (but not including) 2.64: |
15 |
| -#import adafruit_thermal_printer.thermal_printer_legacy as thermal_printer |
| 6 | +import adafruit_thermal_printer |
| 7 | + |
| 8 | + |
| 9 | +# Pick which version thermal printer class to use depending on the version of |
| 10 | +# your printer. Hold the button on the printer as it's powered on and it will |
| 11 | +# print a test page that displays the firmware version, like 2.64, 2.68, etc. |
| 12 | +# Use this version in the get_printer_class function below. |
| 13 | +ThermalPrinter = adafruit_thermal_printer.get_printer_class(2.69) |
16 | 14 |
|
17 | 15 | # Define RX and TX pins for the board's serial port connected to the printer.
|
18 | 16 | # Only the TX pin needs to be configued, and note to take care NOT to connect
|
|
28 | 26 | uart = busio.UART(TX, RX, baudrate=19200)
|
29 | 27 |
|
30 | 28 | # Create the printer instance.
|
31 |
| -printer = thermal_printer.ThermalPrinter(uart) |
| 29 | +printer = ThermalPrinter(uart, auto_warm_up=False) |
32 | 30 |
|
33 | 31 | # Initialize the printer. Note this will take a few seconds for the printer
|
34 | 32 | # to warm up and be ready to accept commands (hence calling it explicitly vs.
|
35 |
| -# automatically in the initializer above). |
36 |
| -printer.begin() |
| 33 | +# automatically in the initializer with the default auto_warm_up=True). |
| 34 | +printer.warm_up() |
37 | 35 |
|
38 | 36 | # Check if the printer has paper. This only works if the RX line is connected
|
39 | 37 | # on your board (but BE CAREFUL as mentioned above this RX line is 5V!)
|
|
57 | 55 | printer.bold = False
|
58 | 56 |
|
59 | 57 | # Print a normal/thin underline line of text:
|
60 |
| -printer.underline = thermal_printer.UNDERLINE_THIN |
| 58 | +printer.underline = adafruit_thermal_printer.UNDERLINE_THIN |
61 | 59 | printer.print('Thin underline!')
|
62 | 60 |
|
63 | 61 | # Print a thick underline line of text:
|
64 |
| -printer.underline = thermal_printer.UNDERLINE_THICK |
| 62 | +printer.underline = adafruit_thermal_printer.UNDERLINE_THICK |
65 | 63 | printer.print('Thick underline!')
|
66 | 64 |
|
67 | 65 | # Disable underlines.
|
|
93 | 91 | printer.strike = False
|
94 | 92 |
|
95 | 93 | # Print medium size text.
|
96 |
| -printer.size = thermal_printer.SIZE_MEDIUM |
| 94 | +printer.size = adafruit_thermal_printer.SIZE_MEDIUM |
97 | 95 | printer.print('Medium size text!')
|
98 | 96 |
|
99 | 97 | # Print large size text.
|
100 |
| -printer.size = thermal_printer.SIZE_LARGE |
| 98 | +printer.size = adafruit_thermal_printer.SIZE_LARGE |
101 | 99 | printer.print('Large size text!')
|
102 | 100 |
|
103 | 101 | # Back to normal / small size text.
|
104 |
| -printer.size = thermal_printer.SIZE_SMALL |
| 102 | +printer.size = adafruit_thermal_printer.SIZE_SMALL |
105 | 103 |
|
106 | 104 | # Print center justified text.
|
107 |
| -printer.justify = thermal_printer.JUSTIFY_CENTER |
| 105 | +printer.justify = adafruit_thermal_printer.JUSTIFY_CENTER |
108 | 106 | printer.print('Center justified!')
|
109 | 107 |
|
110 | 108 | # Print right justified text.
|
111 |
| -printer.justify = thermal_printer.JUSTIFY_RIGHT |
| 109 | +printer.justify = adafruit_thermal_printer.JUSTIFY_RIGHT |
112 | 110 | printer.print('Right justified!')
|
113 | 111 |
|
114 | 112 | # Back to left justified / normal text.
|
115 |
| -printer.justify = thermal_printer.JUSTIFY_LEFT |
| 113 | +printer.justify = adafruit_thermal_printer.JUSTIFY_LEFT |
116 | 114 |
|
117 | 115 | # Print a UPC barcode.
|
118 | 116 | printer.print('UPCA barcode:')
|
|
0 commit comments