Tutorial: Arduino and a Thermal Printer - tronixstuff [PDF]

Jul 8, 2011 - Use inexpensive thermal printers with Arduino in chapter thirty-eight of a series originally titled “Getti

4 downloads 26 Views 2MB Size

Recommend Stories


Brecknell Thermal Printer
Ego says, "Once everything falls into place, I'll feel peace." Spirit says "Find your peace, and then

LAN Thermal Receipt Printer
Knock, And He'll open the door. Vanish, And He'll make you shine like the sun. Fall, And He'll raise

S8000 Plus Thermal Printer datasheet
In every community, there is work to be done. In every nation, there are wounds to heal. In every heart,

The V120i thermal transfer printer
We may have all come on different ships, but we're in the same boat now. M.L.King

Arduino RFID RC522 Quick Start Guide Tutorial
If your life's work can be accomplished in your lifetime, you're not thinking big enough. Wes Jacks

[PDF] Arduino and Kinect Projects
Raise your words, not voice. It is rain that grows flowers, not thunder. Rumi

Citizen CT-S310ii Thermal Receipt Printer Datasheet
Ask yourself: Can I be a better listener? Next

TEC Thermal Printer B-472 Brochure
Be like the sun for grace and mercy. Be like the night to cover others' faults. Be like running water

TDP-225W Desktop Direct Thermal Printer
Why complain about yesterday, when you can make a better tomorrow by making the most of today? Anon

[PDF] Arduino Workshop
Never let your sense of morals prevent you from doing what is right. Isaac Asimov

Idea Transcript


tronixstuff fun and learning with electronics

Home Tronixlabs Kit Reviews Reviews About Contact Us

Categorized | arduino, COM-10438, COM-10560, education, lesson, microcontrollers, printer, sparkfun, thermal, tutorial

Tutorial: Arduino and a Thermal Printer Posted on 08 July 2011. Tags: arduino, barcode, bitmap, COM-10438, COM-10560, DIY, duemilanove, how, interface, inverse, learn, lesson, lessons, printer, receipt, serial, sparkfun, thermal, to, tronixstuff, tutorial, tutorials, understand, uno Use inexpensive thermal printers with Arduino in chapter thirty-eight of a series originally titled “Getting Started/Moving Forward with Arduino!” by John Boxall – a series of articles on the Arduino universe. The first chapter is here, the complete series is detailed here. Updated 05/02/2013 In this article we introduce the inexpensive thermal printer that has recently become widely available from Sparkfun and their resellers. The goal of the article is to be as simple as possible so you can get started without any problems or confusion. In the past getting data from our Arduino to a paper form would either have meant logging it to an SD card then using a PC to finish the job, or perhaps viewing said data on an LCD then writing it down. Not any more – with the use of this cheap and simple serial printer. Before we get started, here is a short demonstration video of it in action:

Not bad at all considering the price. Let’s have a look in more detail. Here is the printer and two matching rolls of thermal paper:

… and the inside of the unit:

Loading paper is quite simple, just drop the roll in with the end of the paper facing away from you, pull it out further than the top of the front lip, then close the lid. The paper rolls required need to be 57mm wide and have a diameter of no more than 39mm. For example. There is a piece of white cardboard stuck to the front – this is an economical cover that hides some of the internals. Nothing of interest for us in there. The button next to the LED on the left is for paper advance, and the LED can blink out the printer status. From a hardware perspective wiring is also very simple. Looking at the base of the printer:

… there are two connections. On the left is DC power, and data on the right. Thankfully the leads are included with the printer and have the plugs already fitted – a great time saver. You may also want to fit your own rubber feet to stop the printer rocking about. Please note – you need an external power supply with a voltage of between 5 and 9 volts DC that can deliver up to 1.5 amps of current. When idling the printer draws less than 10 milliamps, but when printing it peaks at around 1.47 A. So don’t try and run it from your Arduino board. However the data lines are easy, as the printer has a serial interface we only need to connect printer RX to Arduino digital 3, and printer TX to Arduino digital 2, and GND to … GND! We will use a virtual serial port on pins 2 and 3 as 0 and 1 will be taken for use with the serial monitor window for debugging and possible control purposes. If you want to quickly test your printer – connect it to the power, drop in some paper, hold down the feed button and turn on the power. It will quickly produce a test print. Next we need to understand how to control the printer in our sketches. Consider this very simple sketch:

After ensuring your printer is connected as described earlier, and has the appropriate power supply and paper – uploading the sketch will result in the following:

Now that the initial burst of printing excitement has passed, let’s look at the sketch and see how it all works. The first part:

configures the virtual serial port and creates an instance for us to refer to when writing to the printer. Next, four variables are defined. These hold parameters used for configuring the printer. As the printer works with these settings there is no need to alter them, however if you are feeling experimental nothing is stopping you. Next we have the function initPrinter(). This sets a lot of parameters for the printer to ready itself for work. We call initPrinter() only once – in void setup(); For now we can be satisfied that it ‘just works’. Now time for action – void loop(). Writing text to the printer is as simple as:

You can also use .println to advance along to the next line. Generally this is the same as writing to the serial monitor with Serial.println() etc. So nothing new there. Each line of text can be up to thirty-two characters in length. The next thing to concern ourselves with is sending commands to the printer. You may have noticed the line

This sends the command to advance to the next line (in the old days we would say ‘carriage return and line feed’). There are many commands available to do various things. At this point you will need to refer to the somewhat amusing user manual.pdf. Open it up and have a look at section 5.2.1 on page ten. Notice how each command has an ASCII, decimal and hexadecimal equivalent? We will use the decimal command values. So to send them, just use:

Easy. If the command has two or more values (for example, to turn the printer offline [page 11] ) – just send each value in a separate statement. For example:

… will put the printer into offline mode. Notice how we used the variable “zero” for 0 – you can’t send a zero by itself. So we assign it to the variable and send that instead. Odd. For out next example, let’s try out a few more commands: Underlined text (the printer seemed to have issues with thick underlining, however your experience may vary) Bold text Double height and width Here is the sketch:

And the results:

Frankly bold doesn’t look that bold, so I wouldn’t worry about it too much. However the oversized characters could be very useful, and still print relatively quickly. Next on our list are barcodes. A normal UPC barcode has 12 digits, and our little printer can generate a variety of barcode types – see page twenty-two of the user manual. For our example we will generate UPC-A type codes and an alphanumeric version. Alphanumeric barcodes need capital letters, the dollar sign, percent sign, or full stop. The data is kept in an array of characters named … barCode[] and barCode[]2. Consider the functions printBarcode(), printBarcodeThick() and printBarcodeAlpha() in the following example sketch:

Notice in printBarcodeThick() we make use of the ability to change the vertical size of the barcode – the height in pixels is the third parameter in the group. And here is the result:

So there you have it – another practical piece of hardware previously considered to be out of our reach – is now under our control. Now you should have an understanding of the basics and can approach the other functions in the user guide with confidence. Please keep in mind that the price of this printer really should play a large part in determining suitability for a particular task. It does have issues printing large blocks of pixels, such as the double-width underlining and inverse text. This printer is great but certainly not for commercial nor high-volume use. That is what professional POS printers from Brother, Star, Epson, etc., are for. However for low-volume, personal or hobby use this printer is certainly a deal. As always, now it is up to you and your imagination to put this to use or get up to other shenanigans. This article would not have been possible without the example sketches provided by Nathan Seidle, the founder and CEO of Sparkfun. If you meet him, shout him a beer. Please don’t knock off bus tickets or so on. I’m sure there are heavy penalties for doing so if caught.

Have fun and keep checking into tronixstuff.com. Why not follow things on twitter, Google+, subscribe for email updates or RSS using the links on the right-hand column, or join our Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, helpful to each other – and we can all learn something.

Bio

Latest Posts

John Boxall Person. Author of http://arduinoworkshop.com Director of http://tronixlabs.com.au Rare updater of http://tronixstuff.com VK3FJBX

Like this: Loading...

← Kit Reviews: Snootlab Power ScrewShield and I2C Power Protoshield Review: The Gravitech Arduino Nano family Õ

11 Responses to “Tutorial: Arduino and a Thermal Printer”

1.

Ricardo says: August 10, 2013 at 12:14 pm This is amazing, is there a way to print small snips of the google maps? Sometimes i need to give people locations, and it would be amazing if I could use this printer. Reply John Boxall says: August 10, 2013 at 4:17 pm I’m sure you could use the printer, but not with an Arduino – it doesn’t have enough memory to deal with Ethernet and harvesting images from a webpage to the printer. Perhaps a single-board computer instead. Reply Ricardo says: August 11, 2013 at 12:01 am Wow I didnt know you could use the printer with a PC, im new to programming and i recently bought and Odroid U2, could you point me to where i could find a tutorial on how to print google maps or something alike? Thx

John Boxall says: August 11, 2013 at 3:27 pm That’s outside my area of knowledge.

Ricardo says: August 11, 2013 at 3:58 pm Thx anyways, ill just monkey around hehe

2.

dboira says: October 15, 2013 at 8:10 pm it is possible print to this printer from java code? thanks in advance Reply John Boxall says: October 15, 2013 at 8:12 pm Not sure, I don’t code in Java. However if you can send serial data from your Java program to control the printer then you’re fine. Have a look at the manual for the ASCII codes you need to send: http://tronixstuff.com/wp-content/uploads/2011/07/a2-user-manual-1.pdf Reply

3.

Tony Allen says: October 30, 2013 at 4:05 am Great article. I would like to be able to print what I type on a keyboard. how can I alter the sketch so that the Arduino waits for input from a keyboard and then prints what is typed? I have one of these from adafruit which converts ps/2 keystrokes to ttl . http://www.adafruit.com/products/1136. what I am working on is a portable label printer.which waits for user to input product name then price then barcode and prints the data provided. I do not know how to tell the arduino to wait for data and buffer it. can you HELP please Reply John Boxall says: October 30, 2013 at 7:12 am This sounds rough but we don’t have the time to consult on individual projects. Try the Arduino forum etc. Reply

4.

Raffaele says: November 16, 2014 at 3:54 am hello, everything works fine, but I have a problem. I want to print a number such as 99, but must be at least 1 inch high. I tried to follow the manual but did not succeed. Someone did it? Raffaele Reply

5.

sudha4u says: March 31, 2015 at 2:41 pm Hi Am working sparkfun thermal printer and trying to initialize the thermal printer from linux bash. Below commands am using for initialing the printer. stty -F /dev/ttyO4 19200 –> to set baud rate echo -e “\x1B” > /dev/ttyO4 echo -e “\x40” > /dev/ttyO4 –> Initialize (ESC @) echo -e “\x1B” > /dev/ttyO4 echo -e “\x37” > /dev/ttyO4 –> print setting echo -e “\x50” > /dev/ttyO4 –> heating dots echo -e “\xFF” > /dev/ttyO4 –> heating interval (ESC 7 80 255) echo -e “\x18” > /dev/ttyO4 echo -e “\x35” > /dev/ttyO4 –> print density echo -e “\x0A” > /dev/ttyO4 –> Line feed (LF) but when ever i do this some junk characters are been printed. Any idea how to initialize or use the thermal printer from linux bash environment. Reply

Trackbacks/Pingbacks

Leave a Reply Name (required) Mail (will not be published) (required) Website

Submit Comment Notify me of follow-up comments by email. Notify me of new posts by email.

Visit tronixlabs.com Helping you make it with Australia's best value for supported hobbyist electronics from adafruit, Altronics, DFRobot, Freetronics, Pololu and more!

Subscribe via email Receive notifications of new posts by email. Email Address Subscribe

Search the site Search

tronixstuff forum Why not join our moderated discussion forum?

Arduino Tutorials Click for Detailed Chapter Index Chapters 0 1 2 3 4 Chapters 5 6 6a 7 8 Chapters 9 10 11 12 13 Ch. 14 - XBee Ch. 15 - RFID - RDM-630 Ch. 16 - Ethernet Ch. 17 - GPS - EM406A Ch. 18 - RGB matrix - awaiting update Ch. 19 - GPS - MediaTek 3329 Ch. 20 - I2C bus part I Ch. 21 - I2C bus part II Ch. 22 - AREF pin Ch. 23 - Touch screen Ch. 24 - Monochrome LCD Ch. 25 - Analog buttons Ch. 28 - Colour LCD Ch. 29 - TFT LCD - coming soon... Ch. 30 - Arduino + twitter Ch. 31 - Inbuilt EEPROM Ch. 32 - Infra-red control Ch. 33 - Control AC via SMS Ch. 34 - SPI bus part I Ch. 35 - Video-out Ch. 36 - SPI bus part II Ch. 37 - Timing with millis() Ch. 38 - Thermal Printer Ch. 39 - NXP SAA1064 Ch. 40 - Push wheel switches Ch. 40a - Wheel switches II Ch. 41 - More digital I/O Ch. 42 - Numeric keypads Ch. 43 - Port Manipulation - Uno Ch. 44 - ATtiny+Arduino Ch. 45 - Ultrasonic Sensor Ch. 46 - Analog + buttons II Ch. 47 - Internet-controlled relays Ch. 48 - MSGEQ7 Spectrum Analyzer First look - Arduino Due Ch. 49 - KTM-S1201 LCD modules Ch. 50 - ILI9325 colour TFT LCD modules Ch. 51 - MC14489 LED display driver IC Ch. 52 - NXP PCF8591 ADC/DAC IC Ch. 53 - TI ADS1110 16-bit ADC IC Ch. 54 - NXP PCF8563 RTC Ch. 56 - MAX7219 LED driver IC Ch. 57 - TI TLC5940 LED driver IC Ch. 58 - Serial PCF8574 LCD Backpacks Ch. 59 - L298 Motor Control Ch. 60 - DS1307 and DS3231 RTC part I

The Arduino Book

Für unsere deutschen Freunde

Dla naszych polskich przyjaciół ...

Australian Electronics! Buy and support Silicon Chip - Australia's only Electronics Magazine.

Interesting Sites Amazing Arduino Shield Directory David L. Jones' eev blog Silicon Chip magazine Always a great read! Talking Electronics Dangerous Prototypes The Amp Hour podcast Superhouse.tv High-tech home renovation

Use of our content…

tronixstuff.com by John Boxall is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Smile Life

When life gives you a hundred reasons to cry, show life that you have a thousand reasons to smile

Get in touch

© Copyright 2015 - 2024 PDFFOX.COM - All rights reserved.