Use a Adafruit print on the Raspberry pi with Mono

This post is different from previous posts. This post only combines the information from these 3 webpages:
Printing on a thermal printer from .Net: http://electronicfields.wordpress.com/2011/09/29/thermal-printer-dot-net/
Installing a the Adafruit printer on a Raspberry: http://pikiosk.tumblr.com/post/38866317521/printing-with-raspberry
Changing the TTL setting on the Raspberry: http://64.13.91.137:86/Comp/RPi/Serial.html

When you know the information on these 3 pages it is quite simple to get the Adafruit thermal print, which is very cheap $50 or so, working on the Raspberry Pi and controlling it with Mono.

  1. The first thing you have to do is change the TTL port setting of the Raspberry Pi. Default this port is used for remote SSH, so you can connect you’re PC/laptop using a 10 bucks converter. But we want the Raspberry Pi to use the TTL port as a serial port. To change these settings we must edit 1 file:
  2.     /etc/inittab.
  3. If you know VI or can use an other editor on Linux, use that otherwise install GEDIT (85mb for a text editor, dear anyone say something about Windows). To do that, open a terminal window and type the following command:
  4.     sudo apt-get install gedit
  5. After confirmation an some waiting the installation is ready, the you can edit the txt file using this command:
  6.     sudo gedit /etc/inittab
  7. In the editor, find a line containing this text:

  8.     T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
  9. Add a hash tag # before that line:
    •     #T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
    • And save. Now turn the Raspberry Pi off:
    •     sodu halt
  10. Next thing we need to do is to connect the printer to the raspberry. You can read the full story on the this site. The short version is:
  11. Get a descent power supply for the printer (9V 2A is the best)
  12. Connect the power to the printer, – = black, + = red
  13. Test the printer, check if the led blinks and check if the button feeds the paper
  14. The next step is scary, cut the green wire from the printer, if you don’t do it, the printer might damage your Pi.
  15. Connect the printer to the Raspberry Pi, black wire goes on pin 6 (third pin from the corner) the yellow wire goes on pin 8 (forth pin from the corner), the connector fist perfectly
  16. Last step it programming. Download the open source printer library, create a new solution, add a reference to the newly downloaded library. The print use this code:
  17. SerialPort printerPort = new SerialPort("/dev/ttyAMA0", 19200);
    printerPort.Open();
    ThermalPrinter printer = new ThermalPrinter(printerPort);
    printer.WakeUp();   // Let's wake up the printer
    printer.WriteLine("Hello from Pi");
    printer.LineFeed(); // Feed paper
    printer.Sleep();    // Save some energy
    Console.WriteLine("Printer is now offline.");
    printerPort.Close();

    Especially the first line is very important and it took me quite some time to find the correct setting.

    Test it and have funGlimlach

Comments are closed.