Thursday, 27 December 2012

Little Box of Geek Project - Part 1

You will need:

Prepare the thermal printer by connecting the cables. First plug in the data cables (green, yellow and black) to the printer. Next connect the power cable (red, black).

Cut off the end of the power connector and replace it with the solder less dc connector so that it can be plugged into a dc power supply (must be between 5 and 9v, 2a). Make sure that the red wire is put into the positive (+) and the black wire into the negative (-). Screw in tightly.

Test that the printer works with your power supply by plugging it in. If the green light flashes and when you press the paper feed button, the paper comes out, the printer is ready to be plugged into the Raspberry Pi GPIO pins.

Using male to female jumper cables attach the RX of the printer (yellow) to pin 8 and the ground of the printer (black) to pin 6 on the Pi. GPIO layout Note: Make sure you read this first :)

Connect your pi to a keyboard, mouse, monitor etc. You should have already setup your raspberry pi, if you have not done this yet check out GGD episode 5.

We need to first setup the Raspberry Pi serial port and change some settings.
Install the required files by typing the following into a terminal window.

sudo apt-get install python-serial
sudo apt-get install python-imaging-tk

Next give the serial port permission to dialout using:
sudo usermod -a -G dialout pi

We also need to edit this file:
sudo nano /boot/cmdline.txt

By deleting:
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait

and replacing it with:
dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait

Finally remove the last line of /etc/inittab and restart your raspberry pi using:
sudo shutdown -r now

(With thanks to tutorial)

Next we need to download the python files needed to print from github. First you will need to install git-core onto your pi using:
sudo apt-get install git-core

create a directory on your pi to download your files from git hub to using:

to download the printer repository use:
git clone git://

Finally we need to edit the following file:
sudo nano 

To add this line at the top:
#!/usr/bin/env python 

and to check that it is pointing to the correct port:

Run and a test page should print.

What are you waiting for? Hot foot it to Part 2 for more fun!


  1. I like the style of this tutorial. It's important to have tests at key steps in the construction process.

  2. I like this, I think I'll try it, but include a camera, that would take a photo, photo booth style, convert it to a suitable sized grey scale 'sketch' and print it above the fortune. Even better have the camera behind a one way mirror, smile at the mirror press the button and receive the fortune customized with your photo, 'looking good today', 'Got out the wrong side of the bed today did we?' that sort of thing...

    1. That sounds awesome. Would love to see the finished project.

      Thanks for your comment and good luck!

  3. Hi,
    Good tutorial, one question, will I get away with using the kit from here: ?


  4. This is pretty good. I followed the instructions, although I do not yet have a thermal printer. Some small corrections:

    1. 'cd~/git' is coded incorrectly. The real code sequence is:
    mkdir git
    cd !$
    (or 'cd git')

    2. 'sudo nano' is not needed, since we do not need root permissions to edit One can just type:

    3. When checking that is pointing to the correct serial port, you want to edit the line:

    SERIALPORT = '/dev/tty02'

    to read

    SERIALPORT = '/dev/ttyAMA0'

    Since I don't yet have a thermal printer or have made any hardware connections, I'll follow up with this once all the hardware arrives in the mail. This is a very good preparation step to take, even without the hardware.

  5. Thanks for using my Thermal printing library. I'll add a note for Raspberry Pi setup in the code (originally written for Beaglebone) and a link pointing here for more detailed instructions.

    1. Awesome. Thanks for creating the library :)

  6. I'm totally new to programming anything- and when I saw this project accompanied by your step by step video, I thought "I'm gonna buy a pi and try it out". It took me a bit to get everything up and running- like 2 weeks. I thought I'd point out the three spots that were hiccups for me- I'm sure someone with more experience wouldn't even think of telling people such basic info:

    (1) I live in the states so I couldn't just buy off your parts list. The cables you'll need to buy are male-female... male-male won't work...
    (2) The raspberry pi needs to be connected to the internet so that it can "fetch" what it needs- if you're having errors that mention a failure to fetch- make sure you're connected to the internet (the raspberry pi has an ethernet port- so just plug in to the internet).
    (3) The listed permissions file didn't work for me- I had to use:
    sudo chmod a+rw /dev/ttyAMA0
    I'll post the hiccups I came across in part 2 as well-
    Thanks so much for the project!

  7. I read your blogs regularly. Your humoristic way is amusing, continue the good work!Lend A Box

  8. This comment has been removed by a blog administrator.

  9. hi, thanks to make this tutorial, this is great tutorial, but i have a question, when i'm trying run, why the printout is the chinese character ?, please help me

  10. Hi I'm trying to follow this tutorial but my raspberry pi didnt like that I changed the cmdline. Now it doesnt want to boot. I have a Raspberry pi B. Thanks for your help.

  11. On the PI3 the Serial Port is named "ttyS0" and not ttyAMA0 so follow these Steps to get the printer running:

    sudo raspi-config
    9 -> Advanced Options
    A8 -> Serial

    then open and set ttyS0 instead of ttyAMA0 and it just work :-) (took me hours of research :'-()