🔧 RawBT Example 09 - Raw ESC/POS Commands

âš¡ Advanced: This example shows how to send raw ESC/POS commands directly to the printer. Useful for features not covered by the library's high-level API.

Sending Raw Commands

// Using raw() method with byte array job.raw([0x1B, 0x40]); // Initialize printer // Multiple bytes job.raw([0x1B, 0x61, 0x01]); // Center align // You can also build complex commands const ESC = 0x1B; const GS = 0x1D; job.raw([ESC, 0x45, 0x01]); // Bold on

Common ESC/POS Commands Reference

Function Command Bytes (Hex) Try
Initialize Printer ESC @ 1B 40
Line Feed LF 0A
Feed N Lines ESC d n 1B 64 05
Align Left ESC a 0 1B 61 00
Align Center ESC a 1 1B 61 01
Align Right ESC a 2 1B 61 02
Bold On ESC E 1 1B 45 01
Bold Off ESC E 0 1B 45 00
Underline On ESC - 1 1B 2D 01
Underline Off ESC - 0 1B 2D 00
Double Height GS ! n 1D 21 10
Double Width GS ! n 1D 21 20
Double Both GS ! n 1D 21 30
Normal Size GS ! 0 1D 21 00
Full Cut GS V 0 1D 56 00
Partial Cut GS V 1 1D 56 01
Open Drawer ESC p 0 1B 70 00 19 FA

Custom Command Input

Text Size Formula

// GS ! n - where n = (width-1)*16 + (height-1) // Examples: // 1x1 (normal): n = (1-1)*16 + (1-1) = 0x00 // 2x2: n = (2-1)*16 + (2-1) = 16 + 1 = 0x11 // 3x3: n = (3-1)*16 + (3-1) = 32 + 2 = 0x22 // 2x1 (wide only): n = (2-1)*16 + (1-1) = 0x10 // 1x2 (tall only): n = (1-1)*16 + (2-1) = 0x01 job.raw([0x1D, 0x21, 0x11]); // 2x2 size