george_ferg17
Posts: 22
Joined: Wed Nov 15, 2023 3:43 pm
Location: uk

[FIXED]Thermal Printer Firmware with RPI 3a+ Troubleshoot

Mon Dec 04, 2023 7:01 pm

I am trying to use a thermal printer i got from ali express to perform a simple python code from this website and i was following all the steps correctly when it came to powering up, downloads and connections but i ran into problems when one of the code functions in what i was using below for getting a test asked for firmware version. The website listed examples such as 2.69, 2.34 etc the one i received on the test paper i ran was PT701-9013 It gave me other useful information such as braudrate being 9600 and the amount of volts 5.004v . I attempted to implement it within the code but i had no clue how. Searching online for manufacturers and where i bought from or similar products provided no help. What does this mean? The product says its compatible so there must be a correct format for this i hope or maybe theres a different way to code this. My end goal is to display an image on to the paper so i hope its compatible.
Here is my code (missing space is where firmware version goes).

import board
import busio
import serial
import adafruit_thermal_printer
uart = serial.Serial ("/dev/serialo", baudrate=9600, timeout=3000)
ThermalPrinter = adafruit_thermal_printer.get_printer_class ()
printer = ThermalPriter (uart)
printer. test_page ()

here is link to my product
QR701 TTL RS232 Printer Embedded POS Receipt Printer 58mm ATM Thermal Ticket Micro Panel USB Arduino
https://www.aliexpress.com/i/4000701951402.html

here is the link to the steps i was following
https://cdn-learn.adafruit.com/download ... rinter.pdf

Let me know what you think
Last edited by george_ferg17 on Mon Dec 18, 2023 11:20 pm, edited 1 time in total.

ame
Posts: 8737
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: Thermal Printer Firmware with RPI 3a+ Troubleshoot

Mon Dec 04, 2023 8:21 pm

The default version number is 268. You could use that.

Look at the source of Adafruit's thermal_printer class. You can see it uses the version number to decide what features the printer has. If you pick the wrong version number then the driver might try to use a function that your printer doesn't have, but most features should work.

Or you could throw away Adafruit's stuff and just treat the printer as an ESC/POS device, and send your own commands.
Oh no, not again.

george_ferg17
Posts: 22
Joined: Wed Nov 15, 2023 3:43 pm
Location: uk

Re: Thermal Printer Firmware with RPI 3a+ Troubleshoot

Mon Dec 04, 2023 9:36 pm

ame wrote:
Mon Dec 04, 2023 8:21 pm
The default version number is 268. You could use that.

Look at the source of Adafruit's thermal_printer class. You can see it uses the version number to decide what features the printer has. If you pick the wrong version number then the driver might try to use a function that your printer doesn't have, but most features should work.

Or you could throw away Adafruit's stuff and just treat the printer as an ESC/POS device, and send your own commands.
After using this, my printer works. However, after adding the commands printer.feed(2) and printer.print("Hello"), it only displays in chinese. Is there any simple way whether through code or commands the way it receives these lines of code to do what i want. Its langauge according to the test is in pc936

ame
Posts: 8737
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: Thermal Printer Firmware with RPI 3a+ Troubleshoot

Mon Dec 04, 2023 9:58 pm

Are you sure it's "pc936"?

Anyway, you need to try setting the code page to your own language, assuming it's not Chinese.

The ESC/POS command for setting Code Page is 'ESC t n' (ASCII) or '1B 74 n' (Hex) where 'n' is page n of the character code table. Luckily there is a function in the Adafruit library:

Code: Select all

setCodePage(val)
There is a list of code page codes here:
https://github.com/escpos/escpos/blob/m ... /escpos.rb

Pick the one you like. Hopefully your printer supports it.
Oh no, not again.

george_ferg17
Posts: 22
Joined: Wed Nov 15, 2023 3:43 pm
Location: uk

Re: Thermal Printer Firmware with RPI 3a+ Troubleshoot

Wed Dec 06, 2023 8:14 pm

ame wrote:
Mon Dec 04, 2023 9:58 pm
Are you sure it's "pc936"?

Anyway, you need to try setting the code page to your own language, assuming it's not Chinese.

The ESC/POS command for setting Code Page is 'ESC t n' (ASCII) or '1B 74 n' (Hex) where 'n' is page n of the character code table. Luckily there is a function in the Adafruit library:

Code: Select all

setCodePage(val)
There is a list of code page codes here:
https://github.com/escpos/escpos/blob/m ... /escpos.rb

Pick the one you like. Hopefully your printer supports it.
Yes the test page which i couldnt print through code but just by button showed (Langauge: PC936 [GB18030]). So firstly the setCodePage(val) doesnt work unless i havent got the correct library installed or its for a different language as i have seen it on the c program adafruit library. Following the link i inserted the each of those Cp_CP lines in individually and no change. I was wondering if maybe the chinese i received could be translated for printer.feed(2) and printer.print('hello') as the same/similar lines kept getting printed even when alternating whats getting printed. The code must be fine as this is the official adafruit code. Maybe theres a way of configuring it before coding or atleast a line of code to help encode right. Here is my self test and many lines of code output. Hopefully they display something useful instead of being gibberish. https://imgur.com/01xuNVp
https://imgur.com/a/InYOeFX

ame
Posts: 8737
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: Thermal Printer Firmware with RPI 3a+ Troubleshoot

Wed Dec 06, 2023 9:43 pm

Ok. "PC936" should probably be "CP936", for Code Page 936, which is simplified Chinese:
https://en.m.wikipedia.org/wiki/Code_pa ... t_Windows)

And GB18030 is the Chinese character set:
https://en.m.wikipedia.org/wiki/GB_18030

That is the default setting for your printer. Every time you power up the printer it will reset to Chinese.

So, you need to send the Set Code Page command every time the printer is reset, so you might as well send it at the beginning of every job. A good choice to start with would be CP437, which is code 0.

Also, don't assume that Adafruit's code is good. In fact don't assume anyone's code is good. Unfortunately, using a library is no guarantee that something will work. It just means that someone has packaged up the tedious stuff that must be done, so that you don't have to. However, before you use a library you need to know what it's trying to do, so that you can be comfortable it is doing the right thing.

In this case you need to know how printers work and how the ESC/POS protocol works. When you are happy that your printer is working, then you can let someone else's library or driver take over. Until then it's just getting in the way.

So, you can just get rid of the Adafruit library and send raw data to the serial port.

I'd try a simple test, without the library:
Power cycle the printer
Open serial port
Send "ESC t 0"
Send "Hello world."

I'm on my phone right now, so I can't test this:

Code: Select all

import serial
uart = serial.Serial ("/dev/serial0", baudrate=9600, timeout=3000)
uart.write(b'\x1Bt\x00') # ESC t 0, set code page 0 CP437
uart.write(b'Hello world.')
uart.close()
Oh no, not again.

george_ferg17
Posts: 22
Joined: Wed Nov 15, 2023 3:43 pm
Location: uk

Re: Thermal Printer Firmware with RPI 3a+ Troubleshoot

Wed Dec 06, 2023 11:48 pm

Code: Select all

import serial
uart = serial.Serial ("/dev/serial0", baudrate=9600, timeout=3000)
uart.write(b'\x1Bt\x00') # ESC t 0, set code page 0 CP437
uart.write(b'Hello world.')
uart.close()
When running this code there are no errors but the printer doesnt do anything currently. I am also not sure on how to apply setcodeval() too.
Last edited by george_ferg17 on Thu Dec 07, 2023 12:08 am, edited 2 times in total.

ame
Posts: 8737
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: Thermal Printer Firmware with RPI 3a+ Troubleshoot

Thu Dec 07, 2023 12:04 am

george_ferg17 wrote:
Wed Dec 06, 2023 11:48 pm

When running this code there are no errors but the printer doesnt do anything currently.
Hmm. Ok. Let's try a newline at the end.

Code: Select all

import serial
uart = serial.Serial ("/dev/serial0", baudrate=9600, timeout=3000)
uart.write(b'\x1Bt\x00') # ESC t 0, set code page 0 CP437
uart.write(b'Hello world.\n')
uart.close()
Oh no, not again.

ame
Posts: 8737
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: Thermal Printer Firmware with RPI 3a+ Troubleshoot

Thu Dec 07, 2023 12:16 am

You can also try it without the code page change:

Code: Select all

import serial
uart = serial.Serial ("/dev/serial0", baudrate=9600, timeout=3000)
uart.write(b'Hello world.\n')
uart.close()
That is probably the simplest example. It might print something in Chinese. Remember to power cycle the printer first to reset any errors or other settings.
Oh no, not again.

ame
Posts: 8737
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: Thermal Printer Firmware with RPI 3a+ Troubleshoot

Thu Dec 07, 2023 12:16 am

george_ferg17 wrote:
Wed Dec 06, 2023 11:48 pm

Code: Select all

import serial
uart = serial.Serial ("/dev/serial0", baudrate=9600, timeout=3000)
uart.write(b'\x1Bt\x00') # ESC t 0, set code page 0 CP437
uart.write(b'Hello world.')
uart.close()
When running this code there are no errors but the printer doesnt do anything currently. I am also not sure on how to apply setcodeval() too.
What is setcodeval()? Do you mean setCodePage(val)? It is not needed for the test.
Oh no, not again.

george_ferg17
Posts: 22
Joined: Wed Nov 15, 2023 3:43 pm
Location: uk

Re: Thermal Printer Firmware with RPI 3a+ Troubleshoot

Thu Dec 07, 2023 12:30 am

ame wrote:
Thu Dec 07, 2023 12:04 am

Hmm. Ok. Let's try a newline at the end.

Code: Select all

import serial
uart = serial.Serial ("/dev/serial0", baudrate=9600, timeout=3000)
uart.write(b'\x1Bt\x00') # ESC t 0, set code page 0 CP437
uart.write(b'Hello world.\n')
uart.close()
So when i ran the code and a line printed but it wasnt understandable but it was different from previous lines. However running the code again, nothing happened. So when i ran the code without '\n' and the same line output occured and again running it there was no output. Here was the output.
https://imgur.com/a/XAVWSf6

ame
Posts: 8737
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: Thermal Printer Firmware with RPI 3a+ Troubleshoot

Thu Dec 07, 2023 12:37 am

george_ferg17 wrote:
Thu Dec 07, 2023 12:30 am
ame wrote:
Thu Dec 07, 2023 12:04 am

Hmm. Ok. Let's try a newline at the end.

Code: Select all

import serial
uart = serial.Serial ("/dev/serial0", baudrate=9600, timeout=3000)
uart.write(b'\x1Bt\x00') # ESC t 0, set code page 0 CP437
uart.write(b'Hello world.\n')
uart.close()
So when i ran the code and a line printed but it wasnt understandable but it was different from previous lines. However running the code again, nothing happened. So when i ran the code without '\n' and the same line output occured and again running it there was no output. Here was the output.
https://imgur.com/a/XAVWSf6
Ok. This is excellent. It shows that there is communication from the Pi to the printer. It also shows two sets of the same gibberish, which is good because you ran the code twice.

It might look disappointing, but it's great! It's possible that CP437 is not supported.

I don't suppose you have a manual? I need to think.
Oh no, not again.

ame
Posts: 8737
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: Thermal Printer Firmware with RPI 3a+ Troubleshoot

Thu Dec 07, 2023 12:49 am

Ok. Searching for QR701 got me here:
https://leap.tardate.com/playground/the ... 701basics/

From there is a link to a manual (at Adafruit). I'll look for some simple commands to test the printer.

One question, how many wires do you have from the Pi to the printer for serial communication? Do you have two (transmit data and ground), or do you have three (transmit data, receive data, and ground)?
Oh no, not again.

george_ferg17
Posts: 22
Joined: Wed Nov 15, 2023 3:43 pm
Location: uk

Re: Thermal Printer Firmware with RPI 3a+ Troubleshoot

Thu Dec 07, 2023 12:52 am

ame wrote:
Thu Dec 07, 2023 12:37 am

Ok. This is excellent. It shows that there is communication from the Pi to the printer. It also shows two sets of the same gibberish, which is good because you ran the code twice.

It might look disappointing, but it's great! It's possible that CP437 is not supported.

I don't suppose you have a manual? I need to think.
Sadly not as i got it from ali express and that also came with no link to it. Sorry but another thing is that i will have to correct myself as the output lines are slightly different i will send you the first one now for when ' \n' was used. They didnt print after repeating tho. Regarding pins i am using 3 out of 5 pins (GND, RX, TX) and then a separate 2 pin (VH, GND). I have only managed to make it work this way and no else. I can apparently ask the people from ali express for a manual and they will send it. As well as that, the adafruit manual was the one i have previously used and gave me previous errors.


https://imgur.com/a/FOPbZNa
Last edited by george_ferg17 on Thu Dec 07, 2023 1:10 am, edited 2 times in total.

User avatar
scruss
Posts: 5727
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON

Re: Thermal Printer Firmware with RPI 3a+ Troubleshoot

Thu Dec 07, 2023 1:00 am

Glad you got this, ame. This looks like a bog-standard 701 thermal printer. They all talk the same commands

For simple, ASCII-ish text only it's faster to use these without CUPS. They only have a 8600 baud interface, and sending bitmaps over that is slow.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.
Pronouns: he/him

ame
Posts: 8737
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: Thermal Printer Firmware with RPI 3a+ Troubleshoot

Thu Dec 07, 2023 2:45 am

scruss wrote:
Thu Dec 07, 2023 1:00 am
Glad you got this, ame. This looks like a bog-standard 701 thermal printer. They all talk the same commands

For simple, ASCII-ish text only it's faster to use these without CUPS. They only have a 8600 baud interface, and sending bitmaps over that is slow.
Thanks. No worries. We have established the correct port, correct wiring (I think) and correct baud rate. Next is selecting the language and character set. If it works with hard-coded ESC-POS commands it will work with something more complicated if necessary. Unfortunately, providing assistance via a forum is a slow process, like playing "Twenty Questions" by pigeon post, but we'll get there.
Oh no, not again.

george_ferg17
Posts: 22
Joined: Wed Nov 15, 2023 3:43 pm
Location: uk

Re: Thermal Printer Firmware with RPI 3a+ Troubleshoot

Sun Dec 10, 2023 1:49 am

Hello again, i have tried small tweaks but i am still struggling on the same problem i just dont know a clear way to change the code page language for this escpos printer. But i have found these manuals but not sure how to interpret this.
https://ebc81.wordpress.com/2014/08/02/ ... ter-qr701/
https://view.officeapps.live.com/op/vie ... BROWSELINK

ame
Posts: 8737
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: Thermal Printer Firmware with RPI 3a+ Troubleshoot

Sun Dec 10, 2023 4:08 am

Hmm. Some useful information in those links.

Try this:

Code: Select all

import serial
uart = serial.Serial ("/dev/serial0", baudrate=9600, timeout=3000)
uart.write(b'\x1C.') # "FS." turn off Chinese mode
uart.write(b'Hello world.\n')
uart.close()
Oh no, not again.

george_ferg17
Posts: 22
Joined: Wed Nov 15, 2023 3:43 pm
Location: uk

Re: Thermal Printer Firmware with RPI 3a+ Troubleshoot

Mon Dec 11, 2023 4:14 pm

ame wrote:
Sun Dec 10, 2023 4:08 am
Hmm. Some useful information in those links.

Try this:

Code: Select all

import serial
uart = serial.Serial ("/dev/serial0", baudrate=9600, timeout=3000)
uart.write(b'\x1C.') # "FS." turn off Chinese mode
uart.write(b'Hello world.\n')
uart.close()
So when i ran the code as it was, the printer was unresponsive. However , after removing '\n' from the write line, it printed but it was still a mix between chinese and other symbols. This alternating of removing and adding the same code is how i only get my output. Tried checking out using RST port to see what that did if implemented. Went to another website which sets up QR701 printers but code gave syntax error for 'dsrtdr'. Also tried emailing company for manual and maybe some interpretation on the output but i havent received a proper response yet.

here is code and websites.

Code: Select all

from escpos.printer import Serial
""" 9600 Baud, 8N1, Flow Control Enabled """
p = Serial(devfile='/dev/serial0,
           baudrate=9600,
           bytesize=8,
           parity='N',
           stopbits=1,
           timeout=1.00,
           dsrdtr=True)
p.text("Hello World\n")
https://circuitdigest.com/microcontroll ... -bar-codes

ame
Posts: 8737
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: Thermal Printer Firmware with RPI 3a+ Troubleshoot

Mon Dec 11, 2023 10:04 pm

Ok. It's still important to get the printer working with direct commands. Until that happens there's no point using a library.

Code: Select all

import serial
uart = serial.Serial ("/dev/serial0", baudrate=9600)
uart.write(b'\x0A')
uart.write(b'\x0A')
uart.write(b'\x0A')
uart.close()
I've removed the timeout value as it's not needed.

This code should cause the printer to move up by three blank lines.
Oh no, not again.

george_ferg17
Posts: 22
Joined: Wed Nov 15, 2023 3:43 pm
Location: uk

Re: Thermal Printer Firmware with RPI 3a+ Troubleshoot

Tue Dec 12, 2023 1:30 am

ame wrote:
Mon Dec 11, 2023 10:04 pm
Ok. It's still important to get the printer working with direct commands. Until that happens there's no point using a library.

Code: Select all

import serial
uart = serial.Serial ("/dev/serial0", baudrate=9600)
uart.write(b'\x0A')
uart.write(b'\x0A')
uart.write(b'\x0A')
uart.close()
I've removed the timeout value as it's not needed.

This code should cause the printer to move up by three blank lines.
This code runs but remains unresponsive. Maybe it could be my configuration too? im assuming i am using the right gpio pins so maybe its like commands, permissions, downloads etc. Or could it still be that due to its code page language it cant interpret the meaning of these commands.

ame
Posts: 8737
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: Thermal Printer Firmware with RPI 3a+ Troubleshoot

Tue Dec 12, 2023 2:10 am

george_ferg17 wrote:
Tue Dec 12, 2023 1:30 am
ame wrote:
Mon Dec 11, 2023 10:04 pm
Ok. It's still important to get the printer working with direct commands. Until that happens there's no point using a library.

Code: Select all

import serial
uart = serial.Serial ("/dev/serial0", baudrate=9600)
uart.write(b'\x0A')
uart.write(b'\x0A')
uart.write(b'\x0A')
uart.close()
I've removed the timeout value as it's not needed.

This code should cause the printer to move up by three blank lines.
This code runs but remains unresponsive. Maybe it could be my configuration too? im assuming i am using the right gpio pins so maybe its like commands, permissions, downloads etc. Or could it still be that due to its code page language it cant interpret the meaning of these commands.
What do you mean by "unresponsive"?
Yes, the code will run, because it's very simple, there are no errors, and it relies on stuff that is present. If the program runs but nothing happens then there's something wrong somewhere.

The program as shown does the absolute minimum to make the printer do something, but I'll go right into the details in case it makes you think of something that could be wrong.

First, the printer must have power, and must be known to work. This is known because you can turn it on and print a test page.

Next, the printer's communication parameters must be known. In this case all we know is the baud rate, which is printed as part of the self test and is 9600. We assume the other RS232 parameters to be the standard 8-bits, 1 stop bit, no parity. The most common problem here is having the incorrect baud rate.

After that, the connection to the host must be considered. In this case we really only need two wires, data from the host to the printer, and GND. It is not necessary to connect data from the printer to the host, but it doesn't hurt.

A common problem here is a mismatch between transmit data and receive data labels. I'm looking at the manual here:
https://cdn-shop.adafruit.com/datasheet ... Manual.pdf

I assume that you have the USB board shown in section 5.3 on page 9. If so, you need to connect the serial output pin on the Pi GPIO to pin 3 on connector CN4 (receive data). You also need to connect GND from the Pi to pin 4 on CN4.

Finally, you need to know which port on the host is connected to the GPIO pins you are using for serial communication. In this case we are assuming it is /dev/serial0, and that this port exists and is connected to the GPIO pins we have connected to the printer.

Now, if you open the port with the correct settings and send a byte the printer will receive it and do something. Usually the byte is a character, so the character is printed. Sometimes the byte is a command, which changes the printer's state. Sometimes the byte is part of a two-byte sequence, or longer.

Assuming you can confirm all of the above details, here's one more thing to try, from page 48, which should cause a test page to be printed:

Code: Select all

import serial
uart = serial.Serial ("/dev/serial0", baudrate=9600)
uart.write(b'\x12T') # Send self test command
uart.close()
You can see, all we do is load up the Python serial module and open the expected port with a speed of 9600. You can look at the pyserial documentation to see what the defaults for the other settings are, but I expect they're fine here.

Next, we send two bytes: DC2 T

DC2 is not a printable character. It is character 18 in decimal, or 12 in hexadecimal. We insert "\x12" into the string we are going to write, because we can't type the character. For this command, DC2 is followed by the letter T. T is character 84 in decimal, or 54 in hexadecimal. We insert "T" into the string because it's easy to type.

Finally we close the port.

So, the program should run without error, but if the printer does nothing then there's a problem somewhere.
Oh no, not again.

Return to “Other projects”