(SKU: DFR0503) 嵌入式热敏打印机

来自DFRobot Product Wiki
跳转至: 导航搜索
嵌入式热敏打印机

目录

简介

微型热敏打印机采用热敏技术,无需添加墨粉或上墨,性能稳定,身材小巧,节省空间。微型热敏打印机在仪器仪表、食品检测、购物终端等场景应用广泛。生活中的ATM机、存包柜、POS、超市电子称以及外卖小哥的外卖机里都有它。 打印机采用5~9V 宽电压供电方式,电压越高,打印效果越清晰。适用宽度为58MM的热敏纸卷,打印寿命 达50 公里。它支持arduino、树莓派以及Windows 串口与驱动打印。我们可以参照指令集,利用USB串口或TTL通讯接口向热敏打印机发送相应指令,打印机便能根据指令即时打印出你需要的文字、字符,条形码,二维码甚至是黑白图片; 我们可以将它和arduino控制器或树莓派利用串口连接。当配合各种传感器使用时便能DIY电子称、血压指数测量仪、土壤元素分析仪和行车记录仪等实用的仪器设备。我们也可以制作一个属于自己的小票打印机,小票上的内容任由你自己定义,经过开发甚至还可以实现远 程打印功能;

Warning yellow.png

注意事项:

  • 嵌入式热敏打印机电压越高,打印速度越快,打印出来的单据更清晰(电压范围为5~9V,)。同时,产品正常工作电流均在 0.8~1.5A 之间波动。 瞬间电流最高可达到 2A, 若天气寒冷的地方, 电流安数要求也相应增加, 打印图形的功耗一般比较大, 如果打印小票上会涉及到图形, 建议选择适合的电源!
  • 要用arduino进行打印汉字的话,需要建立一个C文件,不能在arduinoIDE下编译(IDE开发环境无法输入中文,使用剪贴板贴入,中文也是UTF8,打印出来是乱码)。C文件中写入相关数组数据进行调用。
  • USB接口的支持电脑系统如XP win7 win8,需要安装驱动才可使用。USB虚拟串口可与安卓平板连接打印。

技术规格

  • 工作电压: 5~9V
  • 工作电流:0.8~1.5A(瞬时电流≈2A)
  • 通信接口:TTL+USB
  • 打印方式:热敏点阵打印
  • 打印颜色:黑白输出
  • 分辨率:203DPI(8点/mm,每行384点)
  • 使用耗材:热敏小票纸卷
  • 纸卷规格:纸卷宽度(58mm±0.5mm)、纸卷直径(30mm)
  • 打印内容:支持文字、图形、一维条码、二维码、曲线等打印
  • 打印宽度:48mm(有效打印宽度)
  • 打印寿命:50公里
  • 打印速度:60mm/s
  • 打印字符:GB18030汉字库(24*24国际一、二级字库),12*24标准ASCII码,并能够对汉字和字符放大1-4倍打印
  • 工作温度:-20℃~50℃
  • 相对湿度:10-80%
  • 打印指令:ESC/POS 兼容指令集(详见《打印机指令集》
  • 外观尺寸:82*58*44 mm
  • 安装尺寸:77*53*42 mm


引脚说明

DFR0503引脚图
TTL通信接口
标号 名称 功能描述
1 GND 电源地
2 DTR 流控制
3 RXD 数据接收端
4 TXD 数据发送端
5 NC 空脚
电源接口
标号 名称 功能描述
1 VCC 5-9V
2 GND 电源地


使用教程


准备

  • 硬件
    • 1 x Arduino UNO控制板
    • 1 x IO 传感器扩展板 V7.1
    • 1 x 直流电源
    • 1 x 热敏打印机
    • 若干 杜邦线
  • 软件


接线图1

  • 如图所示,直流电源为Arduino UNO及热敏打印机提供9V供电。同时,将热敏打印机的TTL接口与此wiki示例程序定义的软串口端口(10-RXD,11-TXD)连接;
DFR0503连接图


打印字符(Arduino)

  • 打印非汉字字符可直接使用print语句,例如英文字母,数字,标点符号......
  • 打印汉字则需要采取下面方式:
    • 1.建一个hz.c的文件,文件内容为新建一个字符数组(关于如何新建.c文件:建立一个.txt文件,然后修改后缀为.c就行)。


constchar hz[][32] 实际上是声明了一个字符串数组,每个字符串不能超过32字节(GB2312编码的汉字16个),如果你要显示的汉字特别长,请修改32这个数字;此种方法实际上是将汉字全部提出到一个数组中, 应用此类方式很容易实现国际版程序,即切换数组就可以实现不同语种的显示; 【注意】:建立这个外挂文件的目的就是为了解决使用IDE编程环境无法编辑GB2312内码汉字的问题,请勿使用IDE编程环境打开编辑此文件,这样操作会将此文件改写为UTF8内码的文件!


const char hz[][32]={
"DFROBOT",	         //0
"极趣科技",	         //1
"嵌入式热敏打印机",	 //2
"arduino开发控制",	 //3
"DIY趣味",	         //4
"让我们一起共创未来",	 //5
"打造我们的DIY世界",	 //6
};


    • 编写程序
#include"C:\Users\Administrator\Documents\Arduino\uart_dayinji\hz.c"     //引用将之前新建的hz.c文件,引号内容为hz.c文件索引地址,需要根据hz.c实际位置作出相应修改
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
void setup()
{
  mySerial.begin(9600);
}
void loop() 
{
  mySerial.println();
  mySerial.println();
  mySerial.println("DFROBOT");
  mySerial.println();
  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]);
  mySerial.println();
  mySerial.println();
  mySerial.println();
  delay(10000);
}
                            


  • 结果在热敏纸上显示下列字符:

DFROBOT

DFROBOT
极趣科技
嵌入式热敏打印机
arduino开发控制
DIY趣味
让我们一起共创未来
打造我们的DIY世界

打印二维码和条形码(Arduino)

  • 参考通用指令集和特殊指令集的条形码和二维码的介绍,写好条形码和二维码的打印指令
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX

/*--------打印条形码指令,其中包含信息为“DFR0503”---------*/
char bar_code[24]={
  0x1b, 0x40,                                                                            
  0x1d, 0x48, 0x02,                                                                         //通用指令第43条,选择打印条形码时其中包含的信息(即HRI字符)的打印位置,0x02意为在条形码下方打印
  0x1d, 0x68, 0x64,                                                                         //设置条形码高度,参考范围“1~255”,示例中设定为“0x64”
  0x1d, 0x77, 0x03,                                                                         //通用指令第45条,设置水平宽度,这里选择“0x03”项                                          
  0x1d, 0x6b, 0x49, 0x09, 0x7B, 0x42, 0x44, 0x46, 0x52, 0x7B, 0x43, 0x05, 0x03              //设置条形码包含信息.“0x09”为条形码长度,对应“DFR0503”. “0x44,0x46,0x52”分别是“DFR”三个字母的ACILL码,“ 0x05, 0x03 ”对应“0503”
};                                                                                          //如果信息为“DFR050308” ,则条码长度为“0x0B”,以此类推                                                        

/*--------打印二维码指令,其中包含信息为“www.dfrobot.com”---------*/
const char QRx[60]={
0x1b,0x40,                                                                                 
0x1d,0x28,0x6b,0x03,0x00,0x31,0x43,0x05,                                                    //参考特殊指令集第一条,“0x05”为二维码的大小等级,
0x1d,0x28,0x6b,0x03,0x00,0x31,0x45,0x30,                                                    //设置QR码的校验等级为L
0x1d,0x28,0x6b,0x12,0x00,0x31,0x50,0x30,0x77,0x77,0x77,0x2E,0x64,0x66,0x72,0x6F,0x62,0x6F,0x74,0x2E,0x63,0x6F,0x6D,    
                                                                                            //“0x12”为QR码包含信息“www.dfrobot.com”(15个字符)的字符个数加3.
                                                                                            //“0x77,0x77,0x77,0x2E,0x64,0x66,0x72,0x6F,0x62,0x6F,0x74,0x2E,0x63,0x6F,0x6D”为网址字符对应ACILL码
0x1b,0x61,0x01,                                                                             //设置图形居中
0x1d,0x28,0x6b,0x03,0x00,0x31,0x52,0x30,                                                    //校验QR码是否正常
0x1d,0x28,0x6b,0x03,0x00,0x31,0x51,0x30                                                     //打印QR码
};       
void setup(){  
  mySerial.begin(9600);
  Serial.begin(9600);  
  while(Serial.read()>= 0){}
  }
void loop(){
  mySerial.println();
  mySerial.print("---------------------------------"); 
  mySerial.println();
  mySerial.write(bar_code,60);                                                              //向打印机发送打印条形码指令       
  delay(5);
  mySerial.println();
  mySerial.write(QRx,60);                                                                   //向打印机发送打印二维码指令
  mySerial.println();
  mySerial.print("---------------------------------"); 
  delay(5000);
}


打印位图

  • 参考官方通用指令集第35条“定义下传位图模式”:
    • 第一步,通过PCtoLCD2002软件给一张位图取字模。(位图尺寸应满足x<255*8,y<48*8;尺寸最好是8的倍数;取字模时配置为阴码、逐列式,顺向);
    • 第二步,新建一个“imege.h”文件,将取字模得到的十六进制数组粘贴到里面,这样便得到一个位图字模库;
unsigned char  show[] = {
0x1B,0x2A,0x20,0xFA,0x00,                                                                                                                   //图片尺寸24*250,参考通用指令集34,35修改参数
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x00,0x00,0xFE,0x00,0x00,0xFE,0x00,0x01,0xFF,
0x00,0x01,0xFF,0x80,0x03,0xFF,0x80,0x03,0xEF,0x80,0x07,0xEF,0xC0,0x07,0xC7,0xC0,0x07,0xC7,0xC0,0x07,0xC7,0xC0,0x07,0xC7,0xE0,0x0F,0x83,0xE0,
0x0F,0x83,0xE0,0x0F,0x83,0xE0,0x0F,0x83,0xE0,0x0F,0x83,0xE0,0x0F,0x83,0xE0,0x0F,0x81,0xF0,0x1F,0x01,0xF0,0x1F,0x01,0xF0,0x1F,0x01,0xF0,0x1F,
0x01,0xF0,0x1F,0x01,0xF0,0x1F,0x01,0xF0,0x1F,0x01,0xF0,0x1F,0x01,0xF0,0x1F,0x01,0xF0,0x1F,0x01,0xF0,0x1F,0x01,0xF0,0x1F,0x01,0xF0,0x1F,0x01,
0xF0,0x1F,0x01,0xF0,0x1F,0x01,0xF0,0x1F,0x01,0xF0,0x1F,0x01,0xF0,0x1F,0x01,0xF0,0x1F,0x01,0xF0,0x1F,0x01,0xF0,0x0F,0x81,0xF0,0x0F,0x83,0xE0,
0x0F,0x83,0xE0,0x0F,0x83,0xE0,0x0F,0x83,0xE0,0x0F,0x83,0xE0,0x0F,0x83,0xE0,0x0F,0xC7,0xE0,0x07,0xC7,0xC0,0x07,0xC7,0xC0,0x07,0xC7,0xC0,0x07,
0xEF,0xC0,0x03,0xEF,0x80,0x03,0xFF,0x80,0x01,0xFF,0x80,0x01,0xFF,0x00,0x00,0xFE,0x00,0x00,0xFE,0x00,0x00,0x38,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x01,0xFF,0x80,0x03,0xFF,0xC0,0x03,0xFF,0xC0,0x03,0xFF,0xC0,0x03,0xFF,0xC0,0x03,0xE7,0xC0,0x03,0xE7,0xC0,0x03,0xE7,0xC0,0x03,0xE7,0xC0,0x03,
0xE7,0xC0,0x03,0xE7,0xC0,0x03,0xE7,0xC0,0x03,0xE7,0xC0,0x03,0xE7,0xC0,0x03,0xE7,0xC0,0x03,0xE7,0xC0,0x03,0xE7,0xC0,0x03,0xE7,0xC0,0x03,0xE7,
0xC0,0x03,0xE7,0xC0,0x03,0xE7,0xC0,0x03,0xE7,0xC0,0x03,0xE7,0xC0,0x03,0xE7,0xC0,0x03,0xE7,0xC0,0x03,0xE7,0xC0,0x03,0xE7,0xC0,0x0F,0xE7,0xF0,
0x1F,0xE7,0xF8,0x1F,0xE7,0xF8,0x1F,0xE7,0xF8,0x1F,0xC3,0xF8,0x0F,0x81,0xF0,0x0F,0x81,0xF0,0x0F,0x81,0xF0,0x0F,0xC1,0xF0,0x07,0xC3,0xE0,0x07,
0xC3,0xE0,0x07,0xC3,0xE0,0x07,0xC3,0xE0,0x03,0xE7,0xC0,0x03,0xE7,0xC0,0x03,0xE7,0xC0,0x03,0xE7,0xC0,0x01,0xFF,0x80,0x01,0xFF,0x80,0x01,0xFF,
0x80,0x01,0xFF,0x80,0x00,0xFF,0x80,0x00,0xFF,0x00,0x00,0xFF,0x00,0x00,0xFF,0x00,0x00,0x7F,0x00,0x00,0x7E,0x00,0x00,0x7E,0x00,0x00,0x7E,0x00,
0x00,0x7E,0x00,0x00,0x3C,0x00,0x00,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x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0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0d,0x0a,
0x1B,0x40,
0x1b,0x2a,0x00,0x0C,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,                                                       //打印一根分割线                            
0x1B,0x33,0x00,
0x0A,
0x1D,0x2F,0x30                                                                                                                              //打印位图指令

};


    • 第三步,编写程序发送指令
#include <SoftwareSerial.h>
#include"D:\image.h"                                                                         //引用将之前新建的image.h文件,根据实际情况修改地址
SoftwareSerial mySerial(10, 11); // RX, TX

/*--------打印条形码指令,其中包含信息为“DFR0503”---------*/
char picture_S[6]={
  0x1b, 0x40,                                                                               
  0x1d, 0x2A, 0x14,0x0A                                                                     //参考通用指令集34和35,0x14和0x0A是根据位图尺寸计算得来
};                                                                                                                                              
char picture_E[3]={
 0xID,0x2F,0x30
};  

void setup(){  
  mySerial.begin(9600);
  Serial.begin(9600);  
  while(Serial.read()>= 0){}
  }
void loop(){
  mySerial.println();
  mySerial.print("---------------------------------"); 
  mySerial.println();

  mySerial.write(show,2237);                                                                //向打印机发送打印位图指令
 
  mySerial.println();
  mySerial.print("---------------------------------"); 
  delay(5000);
}


即时输入,即时打印(一个简单的名片书写程序)

  • 程序功能1.在串口助手上输“Mike”并发送给uno后,打印机会打印出“Name:Mike”;发送“1520000****”时,会自动识别为电话号码,打印机打出“Tel:1520000****”;输入以*开头的一段话“* this is a test”时,会自动识别为标注,打印机会打出“Remarks:”
     
#include "SoftwareSerial.h"
#include "Wire.h"  
char buffer[30]; 
SoftwareSerial mySerial(10, 11); // RX, TX
String comdata = "";
char  comdataX;
int numdata;
void setup()
{ 
  mySerial.begin(9600);
  Serial.begin(9600);  
  while(Serial.read()>= 0){}
}
void loop() 
{
  //Serial_pc();
  Serial_pc1();
}
void Serial_pc()
{ 
while(Serial.available()>0){    
    delay(100);  
    mySerial.print("DFROBOT:");  
    numdata = Serial.readBytes(buffer,30); 
    mySerial.print(buffer);      
    }
    for(int i=0; i<30; i++) 
    buffer[i]=0;
}
void Serial_pc1()
{
 while(Serial.available()>0){  
     delay(100);  
     numdata = Serial.readBytes(buffer,30); 
   
  if(buffer[0]>'/'&&buffer[0]<':')
     {
      mySerial.print("Tel:");
      mySerial.println(buffer); 
      }
  else if(buffer[0]>'@'&&buffer[0]<'{')
    {
      mySerial.print("Name:");
      mySerial.println(buffer);  
      }
  else if(buffer[0]=='*')
    {
      mySerial.print("Remarks:");
      mySerial.println(buffer);  
     }
  else{;}            
  }
  for(int i=0; i<30; i++) 
  buffer[i]=0;
}


常见问题

还没有客户对此产品有任何问题,欢迎通过qq或者论坛联系我们!


更多问题及有趣的应用,可以 访问论坛 进行查阅或发帖。


更多


DFshopping car1.png DFRobot商城购买链接

个人工具
名字空间

变换
操作
导航
工具箱