Embedded Thermal Printer - DFRobot

DFR0503-EN Embedded Thermal Printer - TTL Serial

Introduction

The micro thermal printer uses thermal technology, does not need to add toner or ink, has stable performance, is compact and saves space. Micro thermal printers are widely used in instrumentation, food testing, shopping terminals and other scenarios. It is used in ATM machines, lockers, POS, supermarket electronic scales and takeaway machines in life. The printer uses a 9~24V wide voltage power supply method. The higher the voltage, the clearer the printing effect. It is suitable for thermal paper rolls with a width of 58MM and a printing life of up to 50 kilometers. It supports Arduino, Raspberry Pi and Windows serial port and driver printing. We can refer to the instruction set and use the USB serial port or TTL communication interface to send corresponding instructions to the thermal printer. The printer can instantly print out the text, characters, barcodes, QR codes and even black and white pictures you need according to the instructions; We can connect it to the Arduino controller or Raspberry Pi using the serial port. When used with various sensors, you can DIY practical instruments and equipment such as electronic scales, blood pressure index measuring instruments, soil element analyzers and driving recorders. We can also make a receipt printer of our own. The content on the receipt is up to you to define. After development, it can even realize remote printing function;

warning_yellow.png NOTE:

The higher the voltage of the embedded thermal printer, the faster the printing speed, and the clearer the printed documents (the voltage range is 9-24V). At the same time, the normal working current of the product fluctuates between 0.5-2.5A. The instantaneous current can reach up to 2.5A. If the weather is cold, the current ampere requirement will also increase accordingly. The power consumption of printing graphics is generally large. If graphics are involved in printing receipts, it is recommended to choose a suitable power supply!

If you want to use Arduino to print Chinese characters, you need to create a C file, which cannot be compiled under Arduino IDE (the IDE development environment cannot input Chinese, use the clipboard to paste, and Chinese is also UTF8, which is garbled when printed). Write the relevant array data in the C file for calling.

Specification

Board Overview

DFR0503-EN Embedded Thermal Printer - TTL Serial Pinout

Interface Description

Power Port RS232/TTL Serial Port USB Port 485 Serial Port
XH2.54 2Pin PH2.0 4Pin PH2.0 4Pin PH2.0 2Pin

Interface Configuration

Serial Port Communication Baud Rate Parity Data Bit Stop Bit
USB Port (Default Virtual Printer Port Mode, Can Be Virtualized as Serial Port Mode) 115200 None 8 1

Dimensional Drawing

DFR0503-EN Embedded Thermal Printer - TTL Serial Pinout

Tutorial

Requirements

Connection Diagram

TTL interface wiring method

Printer Arduino UNO
DTR red line Floating
TXD black line Pin 10
RXD blue line Pin 11
GND green line GND

Sample Code

Printing characters in receipt mode

You can directly use the print statement to print non-Chinese characters, such as English letters, numbers, punctuation marks, etc. To print Chinese characters, you need to take the following approach: Create a hz.c file, the content of which is to create a character array (about how to create a new .c file: create a .txt file, then change the suffix to .c, open it with Notepad, then select Save As, select ANSI encoding and save it.). constchar hz[][32] actually declares a string array, each string cannot exceed 32 bytes (16 Chinese characters encoded in GB2312). If the Chinese characters you want to display are particularly long, please modify the number 32; this method actually puts all Chinese characters into an array. This method is easy to implement the international version of the program, that is, switching arrays can achieve display in different languages; [Note]: The purpose of creating this plug-in file is to solve the problem that the GB2312 internal code Chinese characters cannot be edited using the IDE programming environment. Do not use the IDE programming environment to open and edit this file, as this operation will rewrite this file into a UTF8 internal code file!

const char hz[][32]={
"DFROBOT",           //0
"极趣科技",          //1
"嵌入式热敏打印机",  //2
"arduino开发控制",   //3
"DIY趣味",             //4
"让我们一起共创未来",     //5
"打造我们的DIY世界",    //6
};
#include"E:\ces\hz.c" //Reference the newly created hz.c file. The quotation marks are the index address of the hz.c file. It needs to be modified according to the actual location of hz.c
#include <SoftwareSerial.h>
uint8_t Com[7] = { 0x1F, 0x2F, 0x0B, 0x00, 0x01, 0x00, 0x00}; //Switch to receipt mode
SoftwareSerial mySerial(10, 11); // RX, TX
void setup()
{
mySerial.begin(115200);
mySerial.write(Com, 7);//Switch to receipt mode
}
void loop()
{
mySerial.println("SKU:DFR0503-CN");
mySerial.println(hz[0]);
mySerial.println(hz[1]); 
mySerial.println(hz[2]);
mySerial.println(hz[3]);
mySerial.println(hz[4]);
mySerial.println(hz[5]);
mySerial.println(hz[6]);
 delay(10000);
}

Example result:

Print the following content every 10 seconds

Label mode print characters

#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11);                                // RX, TX
uint8_t Com[7] = { 0x1F, 0x2F, 0x0B, 0x00, 0x01, 0x01, 0x01 };  //Switch to tab mode
uint8_t Com1[2] = { 0x1F, 0x63 };//Label verification
const char QRx[200] = {
0x1B,0x40,

0x1A,0x5B,0x01,0x00,0x00,0x00,0x00,0x90,0x01,0x40,0x01,0x02,

0x1A,0x31,0x00,0x05,0x02,0x1E,0x00,0x1E,0x00,0x04,0x00,0x77,0x77,0x77,0x2E,0x64,0x66,0x72,0x6F,0x62,0x6F,0x74,0x2E,0x63,0x6F,0x6D,0x00,

0x1A,0x54,0x01,0xC8,0x00,0x14,0x00,0x18,0x00,0x00,0x11,0x44,0x46,0x52,0x4F,0x42,0x4F,0x54,0x00,

0x1A,0x54,0x01,0xC8,0x00,0x37,0x00,0x18,0x00,0x00,0x11,0x53,0x4B,0x55,0x3A,0x44,0x46,0x52,0x30,0x35,0x30,0x33,0x2D,0x43,0x4E,0x00,

0x1A,0x54,0x01,0xC8,0x00,0x5A,0x00,0x18,0x00,0x00,0x11,0x77,0x77,0x77,0x2E,0x64,0x66,0x72,0x6F,0x62,0x6F,0x74,0x2E,0x63,0x6F,0x6D,0x00,

0x1A,0x5D,0x00,

0x1A,0x4F,0x00
};

void setup() {
  mySerial.begin(115200);
  Serial.begin(9600);
  mySerial.write(Com, 7);  //Switch to tab mode
  delay(1000);
  mySerial.write(Com1, 2);
  while (Serial.read() >= 0) {}
}
void loop() {
  mySerial.println();
  mySerial.write(QRx, 200);  //Send a print command to the printer
  mySerial.println();
  delay(10000);
}

Example result:

Print the following content every 10 seconds

More Documents

Print Command Example

Development Manual.pdf