1

I have written a very simple program in python to print the text value in the mini thermal receipt printer adafruit.

Code:

# On a CircuitPython microcontroller:
import board
import busio
import serial
#uart = serial.Serial("/dev/ttyUSB0", baudrate=19200, timeout=3000)
#import serial
uart = serial.Serial("/dev/serial0", baudrate=19200, timeout=3000)
import adafruit_thermal_printer
ThermalPrinter = adafruit_thermal_printer.get_printer_class(2.69)
printer = ThermalPrinter(uart)
#print(printer)
printer.print("Hello from CircuitPython")
printer._wait_timeout()
printer.feed(2)

Expected Output:

The thermal printer prints Hello from CircuitPython.

Actual Output:

enter image description here

Any help to resolve this issue must be appreciated.

4
  • I have changed the baud rate of the printer to 9600 and changed the firmware versions also.
    – DRV
    Jan 10, 2022 at 11:44
  • echo -e "This is a test.\\n\\n\\n" > /dev/serial0
    – DRV
    Jan 10, 2022 at 11:53
  • 1
    tried this command in cmd and mini thermal printer printing "This is a test"
    – DRV
    Jan 10, 2022 at 11:53
  • Seems related: raspberrypi.stackexchange.com/q/135640/33476 Jan 18, 2022 at 11:15

2 Answers 2

2
+50

First, make sure the baudrate matches. Your code uses 19200, while in the comments you mention 9600. That alone would explain the garbage you get. Print a test page (by holding the feed button as the printer is being powered) if you're not 100% sure what baudrate it is configured to.

Aslo double-check that the firmware version reported in the test page is really 2.69.

In general, I would try to run an official example before trying out your own code.

Another thing you can try is to see if your printer works with regular python. Since you're running this on a Pi, I don't understand why you are using CircuitPython in the first place.

I would be using this official tutorial to begin with.

0

Maybe the _wait_timeout call isn't working as intended.

These small printers are notoriously unintelligent, and how does the printer communicate to the driver that it is ready to receive the next message? This might be using hardware or software handshake, but maybe this isn't working, so as soon as the 'hello' message is sent, the line feeds are sent without a delay, and the printer can't handle receiving new data and printing at the same time.

A simple test; just replace the wait_timeout call with a simple time delay.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.