Adafruit Thermal Printer Library haspaper() Function Fix

I posted this ‘fix’ on Adafruits’ forum as well.

I have been playing with their mini Thermal Printer (

I started testing the haspaper function in their thermal printer library which returns true if there is paper else false. In the library I have, it fails to detect paper out.

After researching the problem, the only comment I can find is this function is iffy. Might work, might not, depending on the printer.

That seemed kind of odd to me because the printer obviously knows paper is out – it flashes its LED 3 times fast to let the user know and if you attempt to print something, it will not let you print. So if the sensor is there, why wouldn’t they let the end-user sense it?

I found the datasheet for the printer ( and found the escape sequence to detect the printer status is <esc>v<null>. Looking at the code for hasprinter, they are sending <gs>r<null>.

<gr>r<null> is used to determine if the paper is nearly out. If there is no paper, it doesn’t indicate that.

I changed the escape sequence in the hasprinter function from

writeBytes(ASCII_GS, 'r', 0);


writeBytes(ASCII_ESC, 'v', 0);

Now the hasprinter() function in the Adafruit library works properly for me, letting me know when I’m out of paper.

This entry was posted in c-arduino, c-electronics and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s