PSoC® 4 BLE – Thermal Printer

PSoC® 4 BLE – Thermal Printer
PSoC® 4 BLE – Thermal Printer
Objective
This example demonstrates the ability of PSoC 4 BLE to drive a Thermal Printer using hardware logic, and print the data
received from the Smart Phone.
Overview
This example uses a BLE Pioneer Kit, interfaced to a Thermal Print head to print data received from a BLE Central device,
which could be a Smart Phone or PC running a specific application or through CySmart. The Thermal Printer is a common
type of printer used in Billing / Receipt printing in Point of Sale Systems, ticketing systems & portable Printers. This design is
only a Proof of Concept, will need many more features to make it complete solution.
The Thermal printer heads have a unique driving method, and need a sequence of signals to print the received data. This
design takes advantage of the highly flexible Digital resources contained in the UDB’s to offload the signaling sequence for
printing a single line from the Cortex M0 core. The digital logic elements used in this design are available by default in PSoC
Creator 3.1 onwards by default, and are not customized. It is also possible to create a custom component to logic. Besides this
an ADC is used to monitor the thermal head temperature, SPI to send one line of data to Thermal Head, a Timer for timing &
other housekeeping.
A Custom BLE profile is used to communicate the data to the Printer. The profile is same as the BLE-UART example, it uses 2
Characteristics, UART_Tx (Notification) & UART_Rx (WriteWithoutResponse)
For detailed information on the Thermal Printer Head and its operation, please refer to the links in the Appendix of this file.
Figure 1: PSoC 4 BLE Thermal Printer Application Block diagram
BLE Central
(CySmart)
BLE Peripheral
(PSoC 4 BLE)
Write
Command
Server_UART
GATT client
GATT
server
Notification
UART_Tx
Custom
Thermal
Printer
Shield
UART_Rx
Requirements
Design Tool: PSoC Creator 3.2 CySmart 1.0
Programming Language: C (GCC 4.8.4 – included with PSoC Creator)
Associated Devices: All PSoC 42XX series BLE devices
Required Hardware: CY8CKIT-042-BLE Bluetooth® Low Energy (BLE) Pioneer Kit and Custom Thermal Printer Shield.
Hardware Setup
The BLE Pioneer Kit has sufficient GPIO’s to drive the Thermal Printer Head. A new shield was designed to allow the
connection of the Printer Head to the kit. The shield also has the LB1936 printer motor head driver. The board is designed to fit
PSoC 4 / PSoC 4 BLE & PSoC 4M kits. No modifications are needed in the BLE kit.
www.cypress.com
1
PSoC 4 BLE - Pressure Sensor
Figure 2: Block Diagram
BLE Pioneer Kit
BLE
Connection
PSoC 4 BLE
BLE-USB Bridge
Bluetooth Low
Energy
Subsystem
(BLESS)
ARM
Cortex-M0
CySmart BLE
Test and Debug
Tool
SPI
Strobe & Motor
Drive Logic
Thermal
Printer
Shield
ADC
Figure 3: BLE Pioneer Kit with the Thermal Printer Shield
www.cypress.com
2
PSoC 4 BLE - Pressure Sensor
PSoC Creator Schematic
Figure 4: PSoC Creator Schematic
www.cypress.com
3
PSoC 4 BLE - Pressure Sensor
Firmware Flow
This example project contains the following source files:
main.c: This file contains the main function, which is the entry point and execution of the firmware application. It also
contains function definitions for initializing the BLE, system interrupts & other component needed to control the print head.
There is also a house keeping interrupt to read the switches & Printer platen roller status at regular intervals.
app_Ble.c: This file contains function definitions related to BLE communication and operation. It contains the event
callback function definition that is registered with the BLE Component at startup and used by the Component to send
various BLE events from the BLE Stack to the application layer for processing. It contains functions to send notifications to
the GATT Client device (currently not used) and a receive Characteristic to get print data from the Client.
app_Uart.c: This file contains the function call back for the Received data processing, print command decoding to print
received text / Solid Line / Blank Space or stored Logo. There is also a Tx Function callback that can be used to send
notifications to the Client, mainly Error Messages like Paper Out / Over Temperature / Platen Not detected.
TH_Printer.c: Contains the functions to control the printer head. The print head has 382 dots that can be printer in a line.
This equates to 48 bytes that are serially shifted into the print head through an SPI Component. The data is then latched
by toggling the LAT pin. After which 0x01 is written to the PRN_1 (Control Register) to start the print sequence. At the end
of the print sequence a StepDone interrupt is generated. The stepper motor & Strobe signals are all generated by the
Hardware logic, reducing the CPU Usage to toggle pins. It also contains functions to print lines, text & simple graphics.
Build and Program
This section shows how to build the project and program the PSoC 4 BLE device. If you are using a development kit with a
built-in programmer (BLE Pioneer Kit, for example), connect the BLE Pioneer Baseboard to your computer using the USB
Standard-A to Mini-B cable. For other kits, refer to the kit user guide.
If you are developing on your own hardware, you need a hardware debugger, for example, a Cypress CY8CKIT-002
MiniProg3.
1.
On PSoC Creator, select Build > Clean and Build PSoC_4_BLE_Pressure_Sensor, as shown in Figure 5.
Figure 5: Build Project
2.
On a successful build, the total Flash and SRAM usage is reported as shown in Figure Figure 6.
Figure 6: Build Succeeded
www.cypress.com
4
PSoC 4 BLE - Pressure Sensor
3.
Select Debug > Select Debug Target, as shown in Figure7.
Figure 7: Selecting Debug Target
4.
In the Select Debug Target dialog box, click Port Acquire, and then click Connect as shown in Figure 88. Click OK to
close the dialog box.
Figure 8: Connecting to a Device
If you are using your own hardware, make sure the Port Setting configuration under Select Debug Target dialog box for your
programming hardware is configured as per your setup.
5.
Select Debug > Program to program the device with the project, as shown in Figure9.
Figure 9: Programming the Device
You can view the programming status on the PSoC Creator status bar (bottom-left corner), as shown in Figure 10.
Figure 50: Programming Status
www.cypress.com
5
PSoC 4 BLE - Pressure Sensor
Testing
After programming the device successfully by following the steps in Build and Program, the board will start advertising itself as
BLE_Print
Testing with the CySmart BLE Test and Debug Utility for iPhone / Android:
1.
2.
Turn on the power to the Printer board.
Start the CySmart Mobile app and search for the BLE_Print device. The CySmart app is not optimized for a printer
application which would need text entry for printing. But the current version of the App can definitely be used to test
and validate the functionality of the printer.
Figure 6: Select BLE Target & Sending Data.
3.
Select the BLE_Print device -> Gatt DB Service -> Unknown Service -> Write: Unknown Characteristic, as shown in
the above sequence of screen shots. The next screen in which the data to be printed has to be entered.
www.cypress.com
6
PSoC 4 BLE - Pressure Sensor
Figure 72: Entering the Data to be printed
4.
Click on the Write button, which will bring up the prompt to enter the data as shown in Error! Reference source not
found.2. The data can be print text, or one of the values for special functions & printing text as shown in the Table 1
below. Pressing Ok will print the function slected.
Table 1: Print Commands
Values
Function
0xFF
Print Cypress Logo (Stored in flash)
0xFE
Print 10 Blank Lines / Vertical spacing
0xFD
Print 10 Solid Lines / Vertical Bar
0xFC
Start Test Print
0xFB
Stop Test Print
0x30 0x31 0x32 0x33 0x34
Prints Numbers – 01234 (App accepts only Hex value, 0x31 is ASCII value for 1)
0x40 0x41 0x42 0x43 0x44
Print Alphabets – ABCD (App accepts only Hex values, 0x40 is ASCII value for A)
www.cypress.com
7
PSoC 4 BLE - Pressure Sensor
Hardware Schematic:
Figure 14: Thermal Printer Shield schematic.
Related Documents
Table 2 lists all relevant application notes, code examples, knowledge base articles, device datasheets, and Component / user
module datasheets.
Table 2: Related Documents
Document
Title
Comment
AN91267
Getting Started with PSoC 4 BLE
Provides an introduction to PSoC 4 BLE
device that integrates a Bluetooth Low
Energy radio system along with
programmable analog and digital
resources.
AN91445
Antenna Design Guide
Provides guidelines on how to design an
antenna for BLE applications.
Other Links:
Thermal Head Details: FTP-628MCL103
Thermal Printer Head driving Waveforms: Refer to Figure 5
Thermal Head Motor Driver: LB1936
www.cypress.com
8
Was this manual useful for you? yes no
Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Download PDF

advertising