User Tools

Site Tools


tutorials:products:thermalprinter:index.html

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
tutorials:products:thermalprinter:index.html [2012/05/28 21:03]
pburgess [First Test]
tutorials:products:thermalprinter:index.html [2016/01/28 18:05] (current)
Line 1: Line 1:
-   +====== Moved! ======
-====  ==== +
-[[http://​www.ladyada.net/​images/​thermalprinter/​thermalprinter_t.jpg|{{ ​ http://​www.ladyada.net/​images/​thermalprinter/​thermalprinter_t.jpg?​nolink&​500x385 ​ |}}]]+
  
-Add a mini printer to any microcontroller project with this very cute thermal printer. Thermal printers are also known as receipt printers, they'​re what you get when you go to the ATM or grocery store. Now you can embed a little printer of your own into an enclosure. ​This printer is ideal for interfacing with a microcontroller,​ you simply need a 3.3V-5V TTL serial output from your microcontroller to print text, barcodes, bitmap graphics, even a QR code! +This tutorial has moved! [[http://learn.adafruit.com/​mini-thermal-receipt-printer|Please visit the new Adafruit ​Thermal Printer Tutorial ​at http://learn.adafruit.com/mini-thermal-receipt-printer]]
- +
-This printer uses very common ​[[http://www.adafruit.com/​products/​599|2.25"​ wide thermal paper, available in the adafruit shop]], and any office or stationary supply store. It can fit up to 50 ft of paper in the bay at once. You will also need a 5 to 9VDC regulated power supply, that can provide 1.5A or more during the high-current print - [[https://​www.adafruit.com/​products/​276|our 5V 2A power supply will work very nicely]].  +
- +
-<class center>​ +
-**[[http://​www.adafruit.com/​products/​600|You can pick up a thermal ​printer pack including printer, paper, power supply and terminal-block adapter in the adafruit shop!]]** +
-</​class>​ +
- +
-We really like this printer because its easy to make **Bold, **__underline__, ​ inverted text, variable line spacing, left/​center/​right justification,​ barcodes in 11 standard formats with adjustable height, and even **custom bitmap graphics.** +
- +
-Of course, we wouldn'​t leave you with a datasheet and a "good luck!" - We have a full tutorial and matching Arduino library that demonstrates the following:​ +
- +
- +
-  *Printing with small, medium and large text +
-  ***Bold ** and __underline__text +
-  * Inverted text +
-  *Variable ​ \\ line  \\ spacing +
-  *Left justification,​ center justification,​ right justification +
-  *Barcodes in the following standard formats: **UPC A, UPC E, EAN13, EAN8, CODE39, I25, CODEBAR, CODE93, CODE128, CODE11** and **MSI** - with adjustable barcode height +
-  *Custom monochrome bitmap graphics! +
-  *How to include a QR code  +
-==== Power  ==== +
- +
- +
-These  printers use a thermal head to heat the special ​receipt ​paper and draw images & text. That makes the printer very small there'​s no moving ink head - but it means they require a lot of power. This printer ​in particular requires **5 to 9 volts, 1.5A current!** That means you will need a fairly beefy supply and you **cannot** run it off of USB power. An external adapter is required! +
- +
-{{  http://​www.ladyada.net/​images/​thermalprinter/​5v2A_MED.jpg?​nolink&​400x308  ​|}} +
- +
- +
- +
-[[http://​www.adafruit.com/​products/​276|We suggest using the 5V 2A power supply in our shop]], its got plenty of power to keep the printer happy and you can also use it to run some microcontrollers or sensors off of the remaining 500 mA current that is not required by the printer. +
- +
-{{  http://​www.ladyada.net/​images/​thermalprinter/​5v2Alabel_MED.jpg?​nolink&​400x308 ​ |}} +
- +
- +
- +
-Note that the power usage is only when the printer is actually printing. Otherwise it uses much less power but you do need to have the capability to provide 1.5A during the printing +
- +
- +
- +
-A quick way to power the printer is by just using a [[http://​www.adafruit.com/​products/​368|2.1mm jack adapter (also available in the Adafruit ​shop)]], which you can attach to the red/black wires. +
- +
-[[http://​www.ladyada.net/​images/​thermalprinter/​poweradapt.jpg|{{ ​ http://​www.ladyada.net/​images/​thermalprinter/​poweradapt_t.jpg?​nolink&​500x272 ​ |}}]] +
- +
- +
-==== First Test  ==== +
- +
- +
-The first test you should do is to just make sure that the printer is running and you have the power wired up right. First up, pull the little plastic tab up top to open up the paper holder. Then insert a roll of 57.5mm (2 1/4 inches) thermal paper into the bay as shown below. The optimal length of the paper will be 50 feet (about 15 meters) so try to pick up that size. Sometimes if you buy paper from an office supply shop, its a little longer, around 80 or 85 feet in which case you'll need to remove paper from the roll until its 1.5"/​40mm in diameter and fits easily. Make sure that the paper doesn'​t '​bind'​ or '​stick',​ it should rotate freely +
- +
-[[http://​www.ladyada.net/​images/​thermalprinter/​insertpaper.jpg|{{ ​ http://​www.ladyada.net/​images/​thermalprinter/​insertpaper_t.jpg?​nolink&​500x412 ​ |}}]] +
- +
-Power the printer using  5V-9V 1.5A or higher power supply, such as wiring up a 2.1mm DC power jack +
- +
-[[http://​www.ladyada.net/​images/​thermalprinter/​poweradapt.jpg|{{ ​ http://​www.ladyada.net/​images/​thermalprinter/​poweradapt_t.jpg?​nolink&​500x272 ​ |}}]] +
- +
-Hold down the button on the top of the printer while plugging in the power, you should see a receipt print out with the font table and some diagnostics. +
- +
-[[http://​www.ladyada.net/​images/​thermalprinter/​testprint.jpg|{{ ​ http://​www.ladyada.net/​images/​thermalprinter/​testprint_t.jpg?​nolink&​500x357 ​ |}}]] +
- +
-If you don't get a print out, check that the paper is inserted right, can turn, power is correctly wired, retry etc. +
- +
-Note the baud rate on the test page. This may be 19200 or 9600. We'll need this number later: +
- +
-{{ :​tutorials:​products:​thermalprinter:​test-baud.jpg?​nolink&​ |}} +
- +
-==== Microcontroller ​ ==== +
- +
- +
-To send data to the printer, we will use 5V TTL serial ​at 19200 baud - this is not the same voltage as +-10V RS232 serial that comes out of the back of a computer in a DB-9 port. While it is possible to use something like an FTDI cable to talk to the printer, we're assuming that nearly everyone will want to use it with a microcontroller. This tutorial will show how to wire it up to an Arduino and our code is Arduino-compatible. Any microcontroller that can output TTL serial 19200 baud will work, with adaptation to the code +
- +
- +
- +
-To start, we'll connect to the data cable of the printer, which has black/​yellow/​green wires. An easy way to connect is to simply plug in 22AWG or so wires of matching colors into the plug, then use those to bring the signal to an Arduino +
- +
-[[http://www.ladyada.net/​images/​thermalprinter/​cableextend.jpg|{{ ​ http://​www.ladyada.net/​images/​thermalprinter/​cableextend_t.jpg?​nolink&​500x356 ​ |}}]] +
- +
-Then we'll connect to the Arduino, **green** goes to **digital pin 2, yellow** goes to** digital pin 3** and black connects to any of the **GND** pins. You can change the digital pins later, but to match the example code, stick to this for now! +
- +
-[[http://​www.ladyada.net/​images/​thermalprinter/​arduinowire.jpg|{{ ​ http://​www.ladyada.net/​images/​thermalprinter/​arduinowire_t.jpg?​nolink&​500x380 ​ |}}]] +
- +
-Now its time to download the Arduino library code. Visit the A[[https://​github.com/adafruit/​Adafruit-Thermal-Printer-Library|darfuit Thermal Arduino library]] . To download. click the **DOWNLOADS** button in the bar,  rename the uncompressed folder **Adafruit_Thermal**. Check that the **Adafruit_****Thermal** folder ​ contains Adafruit_Thermal.cpp and Adafruit_Thermal.h. Place the **Adafruit_Thermal** library folder in your  <​arduinosketchfolder>/​libraries/​ folder. You may need to create the **libraries** subfolder if  its your first library. Restart the IDE.  +
- +
- +
- +
-You'll also need to install the NewSoftSerial library if running Arduino 23 or earlier. [[http://​arduiniana.org/​NewSoftSerial/​NewSoftSerial10c.zip|Download it by clicking this link]] and install it as you did the Thermal library. Restart the IDE.  +
- +
- +
- +
-OK now you're finally ready to run the printer demo. Open up the Arduino IDE and select **File→Examples→Thermal→printertest **sketch ​ and upload it to the Arduino. You should see the printer print out the example receipt which includes all the capabilities of the library +
- +
-[[http://​www.ladyada.net/​images/​thermalprinter/​printdemo.jpg|{{ ​ http://​www.ladyada.net/​images/​thermalprinter/​printdemo_t.jpg?​nolink&​500x389 ​ |}}]] +
- +
- +
- +
-If its not working, first check that the printer and Arduino are both powered, that the printer has power and that the yellow/​green wires are connected properly to the Arduino. +
- +
- +
-==== Printing Text  ==== +
- +
- +
-The thermal ​printer has a few handy things it can do, most of which are in the **printertest** sketch. These are shown in the image above, in order starting from the top. [[http://​www.ladyada.net/​images/​thermalprinter/​printdemo.jpg|Click here to see the high-resolution image]] +
- +
- +
-  *Inverted text - this is invoked by calling **inverseOn()** - you will get text thats 'white on black' instead of 'black on white' **inverseOff()** turns it off +
-  *Double height - this makes text thats extra tall, call **doubleHeightOn()** likewise, turn off with **doubleHeightOff()** +
-  *Left/​Center/​Right justified - this makes the text appear to bump against the left or right edge, or centered. You can set the justification by calling **justify('​R'​) **(for right-justified),​ **justify('​C'​) **(for center-justified) or **justify('​L'​) **(for left-justified) +
-  *Bolded text - makes it stand out a bit more, call with **boldOn()** and turn off with **boldOff()** +
-  *Underlined text - makes it stand out a bit more, call with **underlineOn()** and turn off with **underlineOff()** +
-  *Large/​Medium/​Small text - by default we use small, medium is twice as tall, large is twice as wide/tall. Set the size with **setSize('​L'​)**,​ **setSize('​M'​)** or **setSize('​S'​)** +
-  *Line spacing - you can change the space //​between//​lines of text by calling **setLineHeight(<​numpix>​)** where **numpix** is the number of pixels. By default its 32 but you can make it more to give more space.  +
-==== Bitmaps ​ ==== +
- +
- +
-This printer can print out bitmaps, which can add a touch of class to a receipt ​with your logo or similar. +
- +
- +
- +
-The first step is to get the logo prepared. The printer can only do monochrome (1-bit) images, and the max width/​height seems to be 384 pixels. We suggest starting with a small bitmap (100 pixels or less on a side) and then experimenting to get the size and look you want.  +
- +
- +
- +
-Use a image-editing program to save your image as a 1-bit BMP - we use **paint** which is built into Windows +
- +
-{{  http://​www.ladyada.net/​images/​thermalprinter/​saveasbmp.gif?​nolink&​563x419 ​ |}} +
- +
-Then start up **LCD Assistant** which is windows only but does a really fantastic job!Load in the BMP you generated +
- +
-{{  http://​www.ladyada.net/​images/​thermalprinter/​lcdassistlogo.gif?​nolink&​528x427 ​ |}} +
- +
-It will auto-detect the width and height. Set the **Byte orientation** to **Horizontal**,​ **Little** endian and **8** pixels/​byte. Set the tablename to something short but descriptive. Then **Save Output** and save it as something like **<​tablename>​.cpp** where **<​tablename>​** is the short & descriptive name +
- +
- +
- +
-Open up the new **cpp**file and edit the top definition with static unsigned char __attribute__ ((progmem)) ​ to match this  +
- +
-{{  http://​www.ladyada.net/​images/​thermalprinter/​changeattrib.gif?​nolink&​526x245 ​ |}} +
- +
-You can now include it into your sketch. We like to make a new **tab** (the right arrow in the Arduino IDE bar) and save the image data in there. Then in your main sketch be sure to **#include "​tablename.cpp"​** where tablename is what you saved it in the tab. Check the **printertest** example sketch if you're not sure how to include the code properly. +
- +
-You can now draw it by calling** printBitmap(width,​ height, tablename) **which will print out the logo in black & white. The printer ​is about 250 DPI (0.1mm per pixel) luckily the pixels are '​square'​ +
- +
-[[http://​www.ladyada.net/​images/​thermalprinter/​logoprinted.jpg|{{ ​ http://​www.ladyada.net/​images/​thermalprinter/​logoprinted_t.jpg?​nolink&​500x352 ​ |}}]] +
- +
- +
-==== Barcodes ​ ==== +
- +
- +
-Thermal printers are really good at printing barcodes! This printer supports 11 different codes - **UPC A, UPC E, EAN13, EAN8, CODE39, I25, CODEBAR, CODE93, CODE128, CODE11** and **MSI**. It only supports linear (1-D) barcodes, and can't generate 2-D barcodes like QR codes (although there is a hack you can do, see below!) Barcodes are generated 'on the fly' which is nice - you can customize the height and data included quite easily +
- +
- +
- +
-You can make a barcode by calling **printBarcode("​barcodedata",​ BARCODETYPE)**. where **BARCODETYPE** can be **UPC_A, UPC_E, ****EAN13, EAN8, CODE39, I25, CODEBAR, CODE93, CODE128, CODE11** or **MSI**.  +
- +
- +
- +
-Some barcodes are very restricted - you can only put in 12 numbers, no characters. Others are very flexible and take nearly any character input.[[http://​en.wikipedia.org/​wiki/​Barcodes#​Linear_barcodes| Please check out the wikipedia list detailing kinds of barcodes ]]to pick the right one for your application +
- +
-{{  http://​www.ladyada.net/​images/​thermalprinter/​adaqr.bmp?​nolink ​ |}} +
- +
- +
- +
-Its also possible to print QR codes, if you're willing to pregenerate them. This might be handy if you want to say include a URL into the receipt and the URL doesn'​t change. [[http://​qrcode.kaywa.com/​|You can generate QR codes at many sites including this one.]] Use the smallest QR code size. The image will be in **PNG** format so you need to convert it to 1-bit monochrome BMP - we use **paint** on windows. Then you can use the graphics-conversion technique above \\  +
- +
-[[http://​www.ladyada.net/​images/​thermalprinter/​printedqr.jpg|{{ ​ http://​www.ladyada.net/​images/​thermalprinter/​printedqr_t.jpg?​nolink&​500x356 ​ |}}]] +
- +
- +
-==== Downloads ​ ==== +
- +
-  *[[https://​github.com/​adafruit/​Adafruit-Thermal-Printer-Library|Adarfuit Thermal Arduino library]] . To download. click the **DOWNLOADS** button in the bar,  rename the uncompressed folder **Adafruit_Thermal**. Check that the **Adafruit_****Thermal** folder ​ contains Adafruit_Thermal.cpp and Adafruit_Thermal.h. Place the **Adafruit_Thermal** library folder in your  <​arduinosketchfolder>/​libraries/​ folder. You may need to create the **libraries** subfolder if  its your first library. Restart the IDE.  +
-  *[[http://​arduiniana.org/​NewSoftSerial/​NewSoftSerial10c.zip|NewSoftSerial library]] - required for the Thermal library. Download and install it as you did the Thermal library. Restart the IDE.  +
-  *[[http://​en.radzio.dxp.pl/​bitmap_converter/​|LCD Assistant - bitmap converter]] +
-  *[[http://​www.adafruit.com/​datasheets/​A2-user%20manual.pdf|Printer User Manual]] +
-  *[[http://​www.adafruit.com/​datasheets/​cashino%20thermal%20printer%20a2.pdf|Printer Product sheet]]  +
/home/ladyada/public_html/wiki/data/attic/tutorials/products/thermalprinter/index.html.1338239039.txt.gz · Last modified: 2016/01/28 18:05 (external edit)