AS-289R2 Thermal Printer Shield

Raspberry Pi Zero

RASPBERRY PI



Please confirm the position of jumper(JP5)
/boot/cmdline.txt, delete "console=serial0,115200"

[ Python sample ]

# coding: utf-8

# Thermal Printer Shield for Raspberry Zero
# Model:AS-289R2 & AS-289R
# Python source code
# NADA ELECTRONICS, LTD.
# http://www.nada.co.jp
# By. Takehiro Yamaguchi

import serial

ser = serial.Serial("/dev/ttyAMA0", baudrate = 9600, timeout = 2)

# Text Print
ser.write("Thermal Printer Shield\r");
ser.write("Text Printing.\r");
ser.write("\r\r");	# Line Feed x 2

# QRcode Print
ser.write(chr(29))	# 0x1D
ser.write(chr(120))	# 0x78
ser.write(chr(76))	# 0x4C
ser.write(chr(4 ))	# 0x04
ser.write("TEST")	# DATA
ser.write("\r\r\r\r\r\r");	# Line Feed x 6

ser.close()

Raspberry Pi3 Model B

RASPBERRY PI



Please confirm the position of jumper(JP5)
/boot/cmdline.txt, delete "console=serial0,115200"
/boot/config.txt, add the line "core_freq=250" and "enable_uart=1".

[ Pythonサンプル ]

# coding: utf-8

# Thermal Printer Shield for Raspberry Pi3
# Model:AS-289R2 & AS-289R
# Python source code
# NADA ELECTRONICS, LTD.
# http://www.nada.co.jp
# By. Takehiro Yamaguchi

import serial

ser = serial.Serial("/dev/ttyS0", baudrate = 9600, timeout = 2)

# Text Print
ser.write("Thermal Printer Shield\r");
ser.write("Text Printing.\r");
ser.write("\r\r");	# Line Feed x 2

# QRcode Print
ser.write(chr(29))	# 0x1D
ser.write(chr(120))	# 0x78
ser.write(chr(76))	# 0x4C
ser.write(chr(4 ))	# 0x04
ser.write("TEST")	# DATA
ser.write("\r\r\r\r\r\r");	# Line Feed x 6

ser.close()

[ C++ sample ]
Wiring Pi - GPIO Interface library

/*
 * Thermal Printer Shield for Raspberry Pi3
 * Model:AS-289R2 & AS-289R
 * Sample Sourcecode
 * NADA ELECTRONICS, LTD.
 * http://www.nada.co.jp
 * By. Takehiro Yamaguchi
*/

#include <stdio.h>
#include <string.h>
#include <wiringPi.h>
#include <wiringSerial.h>

int main()
{
	int fd;
	if ((fd = serialOpen ("/dev/ttyS0", 9600)) < 0) {
		printf ("can not open serialport.");
	}

	while(1) {
		/* Text Print */
		serialPrintf(fd,"Thermal Printer Shield\r");
		serialPrintf(fd,"Text Printing.\r");
		serialPrintf(fd,"\r\r");	// Line Feed x 2
		/* QRcode Print */
		char GsQr[] = { 0x1D,0x78,0x4C,0x04,0x54,0x45,0x53,0x54 };
		int i;
		for (i = 0; i < sizeof(GsQr); i++) {
			serialPutchar(fd,GsQr[i]);
		}
		serialPrintf(fd,"\r\r\r\r\r\r");	// Line Feed x 6
		/* Wait */
		delay (5000);	//5sec
	}

	return 0;
}

Raspberry Pi2 Model B

RASPBERRY PI



Please confirm the position of jumper(JP5)

[ C++サンプル ]
Wiring Pi - GPIO Interface library

/*
 * Thermal Printer Shield for Raspberry Pi2
 * Model:AS-289R2 & AS-289R
 * Sample Sourcecode
 * NADA ELECTRONICS, LTD.
 * http://www.nada.co.jp
 * By. Takehiro Yamaguchi
*/

#include <stdio.h>
#include <string.h>
#include <wiringPi.h>
#include <wiringSerial.h>

int main()
{
	int fd;
	if ((fd = serialOpen ("/dev/ttyAMA0", 9600)) < 0) {
		printf ("can not open serialport.");
	}

	while(1) {
		/* Text Print */
		serialPrintf(fd,"Thermal Printer Shield\r");
		serialPrintf(fd,"Text Printing.\r");
		serialPrintf(fd,"\r\r");	// Line Feed x 2
		/* QRcode Print */
		char GsQr[] = { 0x1D,0x78,0x4C,0x04,0x54,0x45,0x53,0x54 };
		int i;
		for (i = 0; i < sizeof(GsQr); i++) {
			serialPrintf(fd,GsQr[i]);
		}
		serialPrintf(fd,"\r\r\r\r\r\r");	// Line Feed x 6
		/* Wait */
		delay (5000);	//5sec
	}

	return 0;
}