One of my embedded projects is to measure the running time in a sports event (see “Sports Timing System in a Lunch Box“). The recorded time is stored in an EEPROM plus sent over USB or wireless connection to the host. It would be great if I could print out the time and ranking directly, so if there is no PC, the system can be small and tiny. So here is my next project and tutorial: Printing with the Freedom board!
The ability to print is a great addition to any other project: I can send messages to be printed out on a remote board, using it as a receipt printer, logging test results and many more things: having printing capabilities is such a great addition to any project, and it does not take much! I have spent this Sunday morning only 4 hours from unpacking, connecting the hardware, programming the first software with CodeWarrior+Processor Expert until I had a “Hello World from the FRDM-KL25Z!” showing up on the printer! And that 4 hours included writing this tutorial :-). So expect it would take you less than one hour with the help of this tutorial.
Adafruit Mini Thermal Receipt Printer
I ordered a small thermal printer from Adafruit (http://learn.adafruit.com/mini-thermal-receipt-printer) which costs $50. I added three thermal paper rolls (http://www.adafruit.com/products/599) to my order to have enough paper to start with :-):
The main features of the printer (from the data sheet):
- Thermal paper printer, 2.25″/57mm wide (effective printing width 48 mm)
- Built-in fonts: small, medium, large text
- Bold, underline and inverted text with left/right/center positioning
- Different bar codes
- Printing monochrome bitmaps and images
- Size: 111x65x57 mm
- 5-9V DC, 1.5 A
- TTL Serial (RS-232, 5V) protocol
- Printer data sheet: http://www.adafruit.com/datasheets/cashino%20thermal%20printer%20a2.pdf
- Printer user manual: http://www.adafruit.com/datasheets/A2-user%20manual.pdf
- Adafruit Thermal Printer Overview: http://learn.adafruit.com/mini-thermal-receipt-printer/overview
With the printer came a test print which has the baud listed. There are printers with 9600 baud and others with 19200, mine came with 19200. More about this later.
Mounting and Connectors
The two brackets are for mounting the printer behind a panel. In order not to lose the parts, I mounted them right away:
The cables get connected to the backside of the printer:
The printer requires a 5-9V power supply. Thermal printing needs a lot of power, so a 1.5 amps power supply is needed! There are many ways how you could give power to the printer. I usually have always a bunch of power supplies, but the challenges is that the plugs never match my needs. So usually I end up cutting the wires and making it fitting my needs. For this project I use a 5V 2A power supply I have left over from a damaged Cisco router:
I cut the 5V wires:
Same for the printer supply wires:
❗ Cut the wires on the 2-pin connector (NOT on the 3-pin side)!
Then remove the isolation:
I’m using heat shrink tubes for isolation, but you can use electrical isolation tape too (not so nice as heat shrink tubes). I cut pieces of different diameter and size:
Put them on the wire before soldering:
Wrap the wires together:
❗ carefully check the wire polarity (what is plus, and what is ground)! In doubt, use a voltage meter to verify it!
Solder the wires:
Then use a hot air gun to shrink it:
The result is a nice connection:
When powered, the green LED flashes. There is a ‘Paper Feed’ button plus a lever to open the printer.
A roll presses the paper on the printer head:
The printer head is near the ‘cut off’ area:
The paper is placed inside the printer. Make sure the paper is clean and has no stickers/etc on it:
Then close the cover:
Making a Test Print
Powering the printer with the ‘paper feed’ button pressed will print a test report:
Now I’m sure my printer is working 🙂
Printer Connection to the FRDM Board
There is problem: the printer uses 5V (TTL) logic levels, while my FRDM board has 3.3V levels. The printer accepts 3.3V input values (on the printer RX line), but it would be a bad idea to connect the printer output 5V TX signal to a microcontroller having 3.3V levels without a level shifter.
As I’m only sending data to the printer, I’m *not* going to connect the printer 5V Tx line to my board. I’m only connecting the GND and the microcontroller Tx with the Printer Rx. For this I’m using connector cables:
Ground is connected to the board GND pin. I’m free to use any available UART Tx pin, and I have used UART0 Tx (Port A, pin 2) PTA2:
In few hours, I have now the ability to print at least some text, using the FRDM-KL25Z and the Adafruit thermal receipt printer. Much faster than I have expected, which is a great thing. Time for having lunch. A next post will be about how to use the software.
But if you cannot wait: the project is already on GitHub: https://github.com/ErichStyger/mcuoneclipse
Happy Printing 🙂
Cool and simple. Great! Thanks Erich
Yes, I love that printer too. Still need to work on all the font and printing images stuff. Hopefully for next week-end…
I have seen on the web and there are many tutorials with Arduino, you could see a little tutorial with PIC or have a library for PIC, before buying I would be sure that it works with the PIC ?
I’m not using PIC with this printer, so I cannot comment much. But as long as the PIC is able to write to a UART, and has the correct logic levels, then I don’t see a reason why it would not work with a PIC.
It seems good work in a short span of time. Actually I’m working on the same project. But we here have a custom board . I just wanted to know how you are saving the data to print. . I’m storing hex values which I got converted from a bit map image using the software lcd assistant mentioned in the same website of adafruit. …
Yes, Adafruit has a conversion utility (I have not used it much), but in general you can use any utility which transforms the bitmap into hex values.
I plan to write a follow-up tutorial about different fonts and using graphics.
great! so basically FRDM board is doing the job of a PC by sending print data… I suppose there is one more MCU inside that printer box
Yes, there is definitely some intelligence in the printer box.
Hi, I tried to send a hex command to another board just like your method, but it failed. i wander if it’s the cw problem because when i import the helloworld project without any change it will run correctly, but if i change the consoleio band to 19200 from 115200, then click “generate code”, then run it on kl25z, it will run uncorrectly, the getchar() will read infinitely FF. Can you give me some tips?
Can you verify the 115200 baud with an oszilloscope to make sure you get that speed? Other than that, I would try and verify if things work with lower speed to isolatethe problem.
it seems that it’s because i use the 5v usb out pin in j9 to supply the power for another board, when i charge the board with another battery, it works. but the band change problem still confuses me a lot.
That 5V USB out pin can only drive a limited number of mA (you need to check the data sheet). That is typically enough to power some small loads (less than 100 mA I think), but for sure not more. So this is probably your problem.
Great article..!! It made my day… 🙂
I was wondering if you could give the link to software tutorial too.. I’m unable to print anything, The Tx signals from my mk10 mc are being transmitted to printer(checked using multi-meter) but nothing is being printed. Kindly help me out… 🙂
Micro controller in use: MK10DN64VLH5
Thermal Printer: EPM207 – HRS
Thanks in advance.
Looking Forward for your response.
checking the signal with a multimeter is not enough: check them with a oszilloscope or logic analyzer if they match the baud for your printer.
I hope this helps,