How can I get Chinese Characters on the Mini Thermal Printer

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
ArtificialFoxx
 
Posts: 3
Joined: Mon Oct 13, 2014 5:20 pm

How can I get Chinese Characters on the Mini Thermal Printer

Post by ArtificialFoxx »

Hi,

In the specs for the Mini Thermal Receipt Printer it shows: "Character Set: ASCII,GB2312-80(Chinese)"

I'm unsure how I would go about using the GB2312-80 / chinese character set?

The manual doesn't mention it as far as I can see.

Of course just printer.write("按"); isn't doing it, has anyone managed to print chinese characters before or have any ideas what I could try?

Grateful for any responses.

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: How can I get Chinese Characters on the Mini Thermal Pri

Post by adafruit_support_rick »

Not sure why the product page says that. I don't believe that the thermal printer does comes with a Chinese character set. But I'll double-check.

User avatar
adafruit2
 
Posts: 22200
Joined: Fri Mar 11, 2005 7:36 pm

Re: How can I get Chinese Characters on the Mini Thermal Pri

Post by adafruit2 »

ArtificialFoxx wrote:Hi,

In the specs for the Mini Thermal Receipt Printer it shows: "Character Set: ASCII,GB2312-80(Chinese)"

I'm unsure how I would go about using the GB2312-80 / chinese character set?

The manual doesn't mention it as far as I can see.

Of course just printer.write("按"); isn't doing it, has anyone managed to print chinese characters before or have any ideas what I could try?

Grateful for any responses.
we just used the spec sheet for the specs - we haven't actually tried anything other than english - however it loks like you can set languages and code pages...may want to check out page 16 of the user manual for "ESC t n" and "ESC R n" commands - let us know if you find out anything!

User avatar
ArtificialFoxx
 
Posts: 3
Joined: Mon Oct 13, 2014 5:20 pm

Re: How can I get Chinese Characters on the Mini Thermal Pri

Post by ArtificialFoxx »

Thanks for the responses.
adafruit2 wrote: we just used the spec sheet for the specs - we haven't actually tried anything other than english - however it loks like you can set languages and code pages...may want to check out page 16 of the user manual for "ESC t n" and "ESC R n" commands - let us know if you find out anything!
Unfortunately this seems to only re-map some of the exisiting characters to few different hex codes rather than provide a different font set entirely.

The command below that looks interesting but it only mentiones the 437 and 850 character sets.

After doing some more searching around for general information about character sets I found the following:
Every Chinese character is represeneted by a two byte code. The MSB of both the first and second bytes are set. Thus, they can be easily identified from documents that contain both GB characters and regular ASCII characters.
Perhaps that means that you can access them without changing the character set?

The site provides this table: http://www.khngai.com/chinese/charmap/tblgb.php?page=0
Presumably A4C0 would be a chinese character etc.

Could that be done like this: printer.write(0xa4c0); ? - I'll give this a go when I next have access to my printer!

User avatar
brandon_r87
 
Posts: 1
Joined: Fri Feb 19, 2016 3:56 am

Re: How can I get Chinese Characters on the Mini Thermal Pri

Post by brandon_r87 »

Did you ever get this figured out? I'm working on this too. I've been researching for the past hour. From looking at the manual https://www.adafruit.com/datasheets/CSN ... Manual.pdf, page 29 refers to changing the printer to Chinese using ESC 9 n where n is your encoding (0: GBK, 1: UTF-8, or 3: Big8). I would assume afterwards you change it back to your own character code table (ESC t 0 is default). I wrote the following code in the Adafruit_Thermal.py file:

Code: Select all

def chineseOn(self):
     self.writeBytes(27, 57, 1) #ESC 9 1

def chineseOff(self):
     self.writeBytes(27, 116, 0) #ESC t 0
I then did something like this:

Code: Select all

#!/usr/bin/python
# -*- coding: utf-8 -*-
from Adafruit_Thermal import *

printer = Adafruit_Thermal("/dev/ttyAMA0", 19200, timeout=5)

a = u"你好世界" # "Hello World"

printer.chineseOn()
printer.println(a)
printer.chineseOff()
Unfortunately, I get this still doesn't work. I always get an error like this, even though I've tried playing around with encodings:

Code: Select all

UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-3: ordinal not in range(128)
Hopefully this gets closer or someone will see how to fix it.

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: How can I get Chinese Characters on the Mini Thermal Pri

Post by adafruit_support_rick »

So, this is a python error from using println. I don't know a lot about python, but I think you want to be using a binary output method, not an ascii output method. Is there a "write" method that outputs a binary buffer?

User avatar
ArtificialFoxx
 
Posts: 3
Joined: Mon Oct 13, 2014 5:20 pm

Re: How can I get Chinese Characters on the Mini Thermal Pri

Post by ArtificialFoxx »

brandon_r87 wrote:Did you ever get this figured out?
Unfortunately I didn't make any further progress on this. I didn't get around to trying to change modes.

Best of luck, if you do get it working let us know - it seems a few people are trying to do this.

User avatar
dhalbert
 
Posts: 401
Joined: Tue Feb 17, 2015 6:18 pm

Re: How can I get Chinese Characters on the Mini Thermal Pri

Post by dhalbert »

Dealing with unicode in Python 2 is somewhat fiddly. I did some experimentation. I don't have a printer to try this on, but try this code:

Code: Select all

a = u"你好世界" # "Hello World"

printer.chineseOn()
printer.write(a.encode("utf-8"))
printer.write("\n")
printer.chineseOff()
You may also be able to do this to get the newline included:

Code: Select all

printer.println(a.encode("utf-8"))

User avatar
Wang_shinchih
 
Posts: 1
Joined: Mon Jun 10, 2019 2:10 am

Re: How can I get Chinese Characters on the Mini Thermal Pri

Post by Wang_shinchih »

How can I print Chinese with Arduino UNO

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”