:Using the RS232 module control a thermal printer
In this tutorial we will take a look at how to control a thermal printer with the RasPiComm+ RS-232 module. The RasPiComm+ has been designed for the Raspberry Pi and is available for preorder on Indiegogo!
I'm using an Epson M-T102 printer with an Able Systems ATB 102 controller board since I had them handy. Other printers/controller boards might need different voltages or wirings, so please check the manuals and data sheets.
|Raspberry Pi B+||RS 8111284|
|RasPiComm+ RS-232 Module||TBA|
|Thermal Printer||Epson M-T102||Printer Controller Board||Able Systems ATB 102||a few wires|
- Hardware Setup
Let's get our gear in place! On the left: RS-232 module, RasPiComm+, Raspberry Pi B+. Then some cables I soldered to a Dsub9 according to the cabling requirements of the ATB102 (more about that in a minute), and on the right the thermal printer, controller board and some thermal printer paper.
and slide the RS232 module into the RasPiComm+ module slot or your choice. I'll use module slot 1.
- Software Setup
If you have read my tutorials so far, you already know the drill! If you haven't already, download the Setup-Script:
and make it executable:
Then execute the automated setup
chmod +x rpc+setup.sh
- Using the RS232 module to print a line
Let's check the installed firmware for module slot 1. Nope, it's not necessary for this tutorial, but hey, this is supposed to be educational, right?
Module Slot tty Slot 1 /dev/ttyRPC+0
Slot 2 /dev/ttyRPC+2
Slot 3 /dev/ttyRPC+4
Slot 4 /dev/ttyRPC+6
In our example the RS232-module is located in slot 1, which means we can adress it with /dev/ttyRPC+0.
Pro Tip: The RS232 module can not only be used as 1xRS-232+Hardware-Handshake, but also as 2xRS-232 in which case we would use both ttyRPC+0 and ttyRPC+1 for communications!
So now that we have found which tty-device we need to use for our printer, let's print something! I will send some text to the printer using the echo command, but you could also use screen (check out the GSM tutorial for reference, we use the screen command there!)
Normally the echo-command would send the string that I type to the screen. Since I do not want it to be displayed on the screen, I will simply pipe (">") the echo-command to my ttyRPC+0 device that is connected to the printer.
We'll need to activate the line feed a bit to see the printed text. We can either connect the pins 4&5 on our controller board, or simply enter
echo "RasPiComm+ printer test" > /dev/ttyRPC+0
a few times, thus sending an empty string to the printer.
echo "" > /dev/ttyRPC+0
- Using the RS232 module to print a file
I've got some lyrics in a file named "rhcp.txt" in my home folder (~) on the Raspberry Pi. Let's try printing those! To show the content of a file on screen we can use the cat-command.
cat ~/rhcp.txt > /dev/ttyRPC+0
You are not restricted to files when using the ">" pipe to the TTY device. Try
date > /dev/ttyRPC+0
uname -a > /dev/ttyRPC+0
If you have questions or feedback, please check out the following Resources:
|RasPiComm+ Support Forum||Official RasPiComm+ Support Forum|