Adafruit Thermal Printer Library
Adafruit_Thermal.h
Go to the documentation of this file.
1 
5 #ifndef ADAFRUIT_THERMAL_H
6 #define ADAFRUIT_THERMAL_H
7 
8 #include "Arduino.h"
9 
10 // Internal character sets used with ESC R n
11 #define CHARSET_USA 0
12 #define CHARSET_FRANCE 1
13 #define CHARSET_GERMANY 2
14 #define CHARSET_UK 3
15 #define CHARSET_DENMARK1 4
16 #define CHARSET_SWEDEN 5
17 #define CHARSET_ITALY 6
18 #define CHARSET_SPAIN1 7
19 #define CHARSET_JAPAN 8
20 #define CHARSET_NORWAY 9
21 #define CHARSET_DENMARK2 10
22 #define CHARSET_SPAIN2 11
23 #define CHARSET_LATINAMERICA 12
24 #define CHARSET_KOREA 13
25 #define CHARSET_SLOVENIA 14
26 #define CHARSET_CROATIA 14
27 #define CHARSET_CHINA 15
28 
29 // Character code tables used with ESC t n
30 #define CODEPAGE_CP437 0
31 #define CODEPAGE_KATAKANA 1
32 #define CODEPAGE_CP850 2
33 #define CODEPAGE_CP860 3
34 #define CODEPAGE_CP863 4
35 #define CODEPAGE_CP865 5
36 #define CODEPAGE_WCP1251 6
37 #define CODEPAGE_CP866 7
38 #define CODEPAGE_MIK 8
39 #define CODEPAGE_CP755 9
40 #define CODEPAGE_IRAN 10
41 #define CODEPAGE_CP862 15
42 #define CODEPAGE_WCP1252 16
43 #define CODEPAGE_WCP1253 17
44 #define CODEPAGE_CP852 18
45 #define CODEPAGE_CP858 19
46 #define CODEPAGE_IRAN2 20
47 #define CODEPAGE_LATVIAN 21
48 #define CODEPAGE_CP864 22
49 #define CODEPAGE_ISO_8859_1 23
50 #define CODEPAGE_CP737 24
51 #define CODEPAGE_WCP1257 25
52 #define CODEPAGE_THAI 26
53 #define CODEPAGE_CP720 27
54 #define CODEPAGE_CP855 28
55 #define CODEPAGE_CP857 29
56 #define CODEPAGE_WCP1250 30
57 #define CODEPAGE_CP775 31
58 #define CODEPAGE_WCP1254 32
59 #define CODEPAGE_WCP1255 33
60 #define CODEPAGE_WCP1256 34
61 #define CODEPAGE_WCP1258 35
62 #define CODEPAGE_ISO_8859_2 36
63 #define CODEPAGE_ISO_8859_3 37
64 #define CODEPAGE_ISO_8859_4 38
65 #define CODEPAGE_ISO_8859_5 39
66 #define CODEPAGE_ISO_8859_6 40
67 #define CODEPAGE_ISO_8859_7 41
68 #define CODEPAGE_ISO_8859_8 42
69 #define CODEPAGE_ISO_8859_9 43
70 #define CODEPAGE_ISO_8859_15 44
71 #define CODEPAGE_THAI2 45
72 #define CODEPAGE_CP856 46
73 #define CODEPAGE_CP874 47
74 
75 
78 enum barcodes {
82  EAN8,
84  ITF,
88 };
89 
93 class Adafruit_Thermal : public Print {
94 
95 public:
96  // IMPORTANT: constructor syntax has changed from prior versions
97  // of this library. Please see notes in the example code!
103  Adafruit_Thermal(Stream *s = &Serial, uint8_t dtr = 255);
104 
105  size_t
111  write(uint8_t c);
112  void
116  begin(uint16_t version=268),
120  boldOff(),
124  boldOn(),
128  doubleHeightOff(),
132  doubleHeightOn(),
136  doubleWidthOff(),
140  doubleWidthOn(),
145  feed(uint8_t x=1),
150  feedRows(uint8_t),
154  flush(),
158  inverseOff(),
162  inverseOn(),
167  justify(char value),
171  offline(),
175  online(),
181  printBarcode(const char *text, uint8_t type),
189  printBitmap(int w, int h, const uint8_t *bitmap, bool fromProgMem=true),
196  printBitmap(int w, int h, Stream *fromStream),
201  printBitmap(Stream *fromStream),
205  normal(),
209  reset(),
214  setBarcodeHeight(uint8_t val=50),
219  setFont(char font='A'),
224  setCharSpacing(int spacing=0), // Only works w/recent firmware
229  setCharset(uint8_t val=0),
234  setCodePage(uint8_t val=0),
238  setDefault(),
243  setLineHeight(int val=30),
248  setMaxChunkHeight(int val=256),
253  setSize(char value),
259  setTimes(unsigned long, unsigned long),
266  setHeatConfig(uint8_t dots=11, uint8_t time=120, uint8_t interval=40),
272  setPrintDensity(uint8_t density=10, uint8_t breakTime=2),
276  sleep(),
281  sleepAfter(uint16_t seconds),
285  strikeOff(),
289  strikeOn(),
293  tab(), // Only works w/recent firmware
297  test(),
301  testPage(),
306  timeoutSet(unsigned long),
310  timeoutWait(),
314  underlineOff(),
319  underlineOn(uint8_t weight=1),
323  upsideDownOff(),
327  upsideDownOn(),
331  wake();
332  bool
337  hasPaper();
338 
339 private:
340  Stream *stream;
341  uint8_t printMode,
342  prevByte, // Last character issued to printer
343  column, // Last horizontal column printed
344  maxColumn, // Page width (output 'wraps' at this point)
345  charHeight, // Height of characters, in 'dots'
346  lineSpacing, // Inter-line spacing (not line height), in dots
347  barcodeHeight, // Barcode height in dots, not including text
348  maxChunkHeight,
349  dtrPin; // DTR handshaking pin (experimental)
350  uint16_t firmware; // Firmware version
351  boolean dtrEnabled; // True if DTR pin set & printer initialized
352  unsigned long
353  resumeTime, // Wait until micros() exceeds this before sending byte
354  dotPrintTime, // Time to print a single dot line, in microseconds
355  dotFeedTime; // Time to feed a single dot line, in microseconds
356  void writeBytes(uint8_t a), writeBytes(uint8_t a, uint8_t b),
357  writeBytes(uint8_t a, uint8_t b, uint8_t c),
358  writeBytes(uint8_t a, uint8_t b, uint8_t c, uint8_t d),
359  setPrintMode(uint8_t mask), unsetPrintMode(uint8_t mask),
360  writePrintMode(), adjustCharValues(uint8_t printMode);
361 };
362 
363 #endif // ADAFRUIT_THERMAL_H
void tab()
Sends tab to device.
Definition: Adafruit_Thermal.cpp:683
void flush()
Flush data pending in the printer.
Definition: Adafruit_Thermal.cpp:416
void underlineOn(uint8_t weight=1)
Enables underline.
Definition: Adafruit_Thermal.cpp:487
void doubleWidthOff()
Disables double-width text.
Definition: Adafruit_Thermal.cpp:367
void feed(uint8_t x=1)
Feeds by the specified number of lines.
Definition: Adafruit_Thermal.cpp:396
void inverseOn()
Enables white/black reverse printing mode.
Definition: Adafruit_Thermal.cpp:329
void offline()
Put the printer into an offline state. No other commands can be sent until an online call is made...
Definition: Adafruit_Thermal.cpp:592
void feedRows(uint8_t)
Feeds by the specified number of individual pixel rows.
Definition: Adafruit_Thermal.cpp:409
size_t write(uint8_t c)
Writes a character to the thermal printer.
Definition: Adafruit_Thermal.cpp:145
void strikeOn()
Enables delete line mode.
Definition: Adafruit_Thermal.cpp:369
void timeoutSet(unsigned long)
Sets the estimated completion time for a just-issued task.
Definition: Adafruit_Thermal.cpp:76
Definition: Adafruit_Thermal.h:85
void printBitmap(int w, int h, const uint8_t *bitmap, bool fromProgMem=true)
Prints a bitmap.
Definition: Adafruit_Thermal.cpp:495
void boldOff()
Disables bold text.
Definition: Adafruit_Thermal.cpp:375
void setCharset(uint8_t val=0)
Sets the character set.
Definition: Adafruit_Thermal.cpp:670
bool hasPaper()
Whether or not the printer has paper.
Definition: Adafruit_Thermal.cpp:634
void reset()
Reset the printer.
Definition: Adafruit_Thermal.cpp:195
void timeoutWait()
Waits for the prior task to complete.
Definition: Adafruit_Thermal.cpp:82
void justify(char value)
Set the justification of text.
Definition: Adafruit_Thermal.cpp:377
void upsideDownOff()
Disables upside-down text mode.
Definition: Adafruit_Thermal.cpp:353
void underlineOff()
Disables underline.
Definition: Adafruit_Thermal.cpp:493
void setDefault()
Sets the default settings.
Definition: Adafruit_Thermal.cpp:213
void wake()
Wakes device that was in sleep mode.
Definition: Adafruit_Thermal.cpp:613
void online()
Put the printer into an online state after previously put offline.
Definition: Adafruit_Thermal.cpp:595
void doubleHeightOn()
Enables double-height text.
Definition: Adafruit_Thermal.cpp:361
Definition: Adafruit_Thermal.h:87
void boldOn()
Enables bold text.
Definition: Adafruit_Thermal.cpp:373
void setPrintDensity(uint8_t density=10, uint8_t breakTime=2)
Sets print density.
Definition: Adafruit_Thermal.cpp:479
Definition: Adafruit_Thermal.h:82
void test()
Prints test text.
Definition: Adafruit_Thermal.cpp:227
void setFont(char font='A')
Sets the font.
Definition: Adafruit_Thermal.cpp:688
Definition: Adafruit_Thermal.h:83
void strikeOff()
Disables delete line mode.
Definition: Adafruit_Thermal.cpp:371
Definition: Adafruit_Thermal.h:81
void doubleWidthOn()
Enables double-width text.
Definition: Adafruit_Thermal.cpp:365
void inverseOff()
Disables white/black reverse printing mode.
Definition: Adafruit_Thermal.cpp:337
Definition: Adafruit_Thermal.h:79
void begin(uint16_t version=268)
Definition: Adafruit_Thermal.cpp:168
Definition: Adafruit_Thermal.h:80
Adafruit_Thermal(Stream *s=&Serial, uint8_t dtr=255)
Thermal constructor.
Definition: Adafruit_Thermal.cpp:70
Definition: Adafruit_Thermal.h:86
void doubleHeightOff()
Disables double-height text.
Definition: Adafruit_Thermal.cpp:363
void setSize(char value)
Sets text size.
Definition: Adafruit_Thermal.cpp:418
Definition: Adafruit_Thermal.h:84
Definition: Adafruit_Thermal.h:93
void setBarcodeHeight(uint8_t val=50)
Sets the barcode height.
Definition: Adafruit_Thermal.cpp:239
void printBarcode(const char *text, uint8_t type)
Print a barcode.
Definition: Adafruit_Thermal.cpp:246
void testPage()
Prints test page.
Definition: Adafruit_Thermal.cpp:232
void normal()
Sets text to normal mode.
Definition: Adafruit_Thermal.cpp:324
void sleepAfter(uint16_t seconds)
Puts the printer into a low-energe state after the given number of seconds.
Definition: Adafruit_Thermal.cpp:604
void sleep()
Puts the printer into a low-energy state immediately.
Definition: Adafruit_Thermal.cpp:598
void setHeatConfig(uint8_t dots=11, uint8_t time=120, uint8_t interval=40)
Sets print head heating configuration.
Definition: Adafruit_Thermal.cpp:466
void setLineHeight(int val=30)
Sets the line height.
Definition: Adafruit_Thermal.cpp:653
void setTimes(unsigned long, unsigned long)
Sets print and feed speed.
Definition: Adafruit_Thermal.cpp:105
void upsideDownOn()
Enables upside-down text mode.
Definition: Adafruit_Thermal.cpp:345
void setCodePage(uint8_t val=0)
Sets character code page.
Definition: Adafruit_Thermal.cpp:677
barcodes
Definition: Adafruit_Thermal.h:78
void setMaxChunkHeight(int val=256)
Set max rows to write.
Definition: Adafruit_Thermal.cpp:665
void setCharSpacing(int spacing=0)
Sets the character spacing.
Definition: Adafruit_Thermal.cpp:699