Multi-Purpose Portable Wireless Thermal Printer

: Traditional thermal printers have low quality and slow speed in mixed printing of images and texts, so more intelligent processing programs are needed to improve printing quality and speed. This system has designed a thermal printer based on Wi-Fi MCU ESP8266. The printer uses this chip as the main controller, and combines thermal printing principle, stepping motor control technology, micro B/S architecture technology, wireless communication and other technologies to design. This printer adopts independent design, and is compatible with multiple control terminals. It is ready to use without complicated settings. It has a simple and friendly control interface and is worthy of promotion and application in more fields, more diversified and personalized scenes.


Introduction
Since the beginning of the 21st century, the thermal printing market has consistently maintained a sustained growth, and has been widely used in retail, transportation, logistics, commerce and other industries [1]. Thermal printing requires no ink and is fast. However, due to the single color, it is mainly used for printing barcode, label, bill, etc. With the rise of artificial intelligence and the Internet of Things, thermal printing will usher in new market growth points in education and training, entertainment, healthcare and other fields, because these industries need more and more convenient, efficient, fast, low-cost image and text presentation and long-term preservation methods [2,3].
The traditional thermal printer is generally embedded into other equipment as an accessory part, which has problems such as closed design, single function, low print quality, high production cost and maintenance cost. The independent portable handheld printer generally uses wired or wireless Bluetooth to connect to the main device [4]. The connection preparation is complex and cumbersome, and professional drivers and application software need to be installed. The printing content is relatively fixed and single, mainly based on bills, rarely involving the printing and output of documents and graphics [5]. At the same time, the transmission speed of the Bluetooth method to obtain the print data is slow, the processing speed of the image and text output microcontroller has a low impact on the efficiency, and the print output quality is poor. There is a relative lack of independent, portable, fast and high-quality thermal printer products in the market. Therefore, this paper proposes and designs a wireless thermal printer system based on Wi-Fi, which is independent, portable and cost-effective.

Principle Scheme
The system uses the 32-bit microprocessor chip ESP8266 [6] with Wi-Fi as the core control chip, embedded with efficient monochrome image processing algorithm, integrated with a micro WEB server, and compatible with the rapid connection of mobile phones, tablets, computers and other terminal devices through the B/S architecture [7]; Users do not need complicated hardware connection or software installation. They can use it out of the box and achieve highquality image and text output anytime and anywhere [8]. The overall design scheme is shown in Figure 1. This project technically includes hardware circuit design and software design. The hardware circuit includes the power supply circuit of the MCU and motor, the interface circuit of the main control chip, the driving circuit of the stepping motor and the print head, the printing paper and the temperature monitoring circuit; The software design mainly focuses on the programming of the core controller, including Wi-Fi communication module, WEB service module, SPI communication module [9], artificial intelligence image processing module, printing control module, etc. The relevant software code is compiled and stored in the Flash memory.

Hardware System Design
The core circuit of the wireless thermal printer is shown in Figure 2. The core chip required by the core circuit is Esp8266 as the MCU, and TB6612 as the main control chip of the stepping motor [10], respectively connected to the thermal print head JX-2R-05. The chip Esp8266 is a 32-bit Wi-Fi MCU with the clock frequency of 80MHz. 20% of the chip's processing capacity is used to run Wi-Fi protocols and real-time operating systems. The remaining 80% of the chip's processing capacity can be used for programming and development. So it can be used as the master chip of thermal printers. The micro Web server code, stepping motor control code, print head control code, etc. can be realized by the chip.
The TB6612 motor drive module has two channels of output. It can control two DC motors or a two phase four wire stepping motor. It can output 1.2A of motor drive current. The peak starting current can reach 2A, which can meet the needs of the print head motor. The thermal print head uses a stepper motor to control the paper feeding, and pins AIN2, AIN1, BIN1, BIN2 are the input terminals of the step pulse. AO1, AO2, BO1 and BO2 are the output terminals of the step pulse, which are respectively connected with MTRA+, MTRA -, MTRB+ and MTRB -of the thermal print head. The stepping motor section control code of this system adopts the 4-beat drive mode, that is, the pulse input terminal is continuously pulsed according to the 4-beat drive sequence of the drive sequence diagram. The phase beat of the motor is shown in Figure 3, and the beat interval is 1ms. The print head model adopts the line type thermal print head Jingxin [11] JX-2R-05, and the point density is 384 points/line, that is, 48 bytes * 8bit should be input for each line of data. The schematic diagram is shown in Figure 4. The VH pin is the print head heater with a voltage range of 4.2V-8.5V. PHK, VSEN and PHE are respectively the cathode, power supply and reflector of the reflective photoelectric onoff paper shortage detection sensor. DI pin is the serial input pin of the print head data, which is used to receive the print data of MCU. CLK pin is the serial input clock, which sends data at the rising edge. STB1~STB6 are the power supply control signals for the thermal head, and the heating time of the print head is controlled at 800us. TM pin is the print head temperature sensor pin, which is connected to the analog to digital conversion pin AD0 of ESP8266.  The software mainly focuses on the design of built-in WEB server, print head control and the compilation of client interface program. Users do not need to install any third-party APP or driver, and can easily print documents, pictures or bills by opening a browser or WeChat [13] applet. The user is allowed to store a variety of print templates, and the program can automatically generate two-dimensional code, barcode and other data. The depth learning contour extraction algorithm and image binarization algorithm designed for MCU are used to generate data suitable for thermal printing, so that the printing effect is better.
Mobile phones, computers or tablets with browsers can be used as upper computers. After the upper computer connects to the web server of Esp8266 through Wi-Fi, it downloads HTML and JavaScript web page code and runs it, further establishes the WebSocket connection, uploads the processed images and text, and controls the thermal printing progress in real time. The whole function is shown in Figure 6. The software functions to be realized by MCU include: establishing Wi-Fi connection of AP or station, establishing web server, establishing HTML and JS file server, establishing WebSocket server, stepping motor control, data transmission with print head, print point heating control, paper shortage detection, print head temperature detection, etc.

Wireless Connection
The Esp8266 supports Arudino [14] programming, which can be used to turn on the MCU's Wi-Fi signal as a wireless access point for the host computer to connect directly. Or make it work by scanning Wi-Fi routers and connecting them. In short, the upper computer and the thermal printer are connected to the same local area network. This allows the printer to communicate with the host computer at a speed of 2Mbps, laying the foundation for subsequent services.

Web and WebSocket Server
The system builds a micro web server supporting HTTP protocol and WebSocket protocol [15] based on TCP protocol in MCU. Its purpose is to transmit HTML and JavaScript code and data files between the upper computer and the lower computer, and to communicate with each other in real time.
These HTML, JavaScript and Arduino codes run in upper computer browser and MCU respectively to realize user interface, real-time transmission, picture editing, motion control, status monitoring and other functions.

Hardware Control Code
The thermal print head is integrated with a stepping motor, which can be directly driven by the chip TB6612. The input pin of the TB6612 is connected to the GPIO5, GPIO2, GPIO0 and GPIO4 pins of the MCU Esp8266. The program needs to set these four pins as the output, and output the high level for 1 millisecond according to Figure 3. The motor will take a paper step of 0.0625 mm.
It should be noted that the number of GPIOs of Esp8266 is limited, and some time-sharing multiplexing pins are required. For example, GPIO0 is used as an input pin during startup. If it is pulled down, it will set the ESP8266 to the boot loader mode, and switch to the output pin to control the motor operation during normal operation.
The thermal printer core adopts a reflective photoelectric on-off detection sensor, which is mainly used to detect the paper shortage and locate the printing paper through the marks on the printing paper. Refer to Figure 2 for the connection circuit, which is connected to GPIO16 of Esp8266. Set GPIO16 as the input mode, and read the level value to reflect the paper status: when there is no reflected light, the photocell is cut off, which is called low level. When there is white paper, the light is reflected to the photocell, and the photocell is conductive, showing high level.

Verification
The design prototype and software operation interface are shown in Figure 7. After the printer is connected to the power supply, connect it to the mobile phone or computer through wireless Wi-Fi. Enter the printer IP address through the browser to enter the built-in server and start the operation interface. In this interface, you can draw, input text, edit pictures, press the print button, and the data processed into binary images will be transferred to the thermal printer through WebSocket, and printed out quickly. The test shows that images or characters can be printed clearly, and the printing depth can be adjusted by modifying the printing heating time. Under 20% coverage, the printing speed can reach 80mm/s. The printing point spacing is 0.125mm. Temperature detection and paper shortage detection can work normally. The image editing function is convenient and easy to use. The multi terminal connection interfaces of mobile phones, tablets and computers are consistent, the operation is unified and the functions are normal.

Summary
The advantage of this design is that the equipment can realize intelligent high-quality graphic and text rapid printing through Wi-Fi without complex program installation. The utility model fundamentally solves the problems of single function, poor universality and complex setting of the thermal printer. The problem of poor printing effect of thermal printing image is basically solved. Due to the limitation that thermal printing only supports monochrome output, it partly solves the needs of consumers for printing at any time and personalized printing.