Raspberry Pi barcode scanner: connect OEM barcode scanners modules with Raspberry Pi

If you are using Raspberry Pi microcontroller / single-board computer to develop your system and need a 1d/ 2d OEM barcode scanner module at the same time, then this article would be helpful for you: here we introduce how we connect the Raspberry Pi 3 Model B+ micro-controller with RTscan OEM barcode scanner modules and how to make them work each other.

When we try to integrate an OEM barcode scanner with the Raspberry Pi microcontroller board, we would meet these problems:

  1. The OEM barcode scanner module with 12pins TTL interface, but Raspberry Pi board without this type of connector, then how can we connect them together?
  2. Whatever the OEM barcode scanner module we choose, how can we make the barcode scanner to work with Raspberry Pi and also upload decoded data to the Raspberry Pi system?

Read below and find how RTscan provides solutions for the above questions.

Part I: Introduction of Raspberry Pi 3 Model B+ and RTscan OEM barcode scanners

Raspberry Pi 3B+:

Raspberry Pi 3 Model B is the latest iteration of the most popular single-board computer. It provides a quad-core 64-bit ARM Cortex-A53 CPU running at 1.2GHz, four USB 2.0 ports, wired and wireless networking, HDMI and composite video output, and a 40-pin GPIO connector for physical interfacing projects.

Raspberry Pi 3 Pinout

And for our application to connect with the OEM barcode scanner module, we need the 3.3V (or the 5.0v) power supply pin, and GND pin, RXD, TXD pins.

And also, we will demo how to connect our OEM barcode scanner with Raspberry Pi via the USB interface.

RTscan OEM barcode scanners:

 

They all with 12pins connector and TTL-232 signal, and use FFC cable and connector like this :

And if we use an EVK board, they can come out with a USB interface:

In this article, we choose RT214 as an example to do the connection and integration.

 

Part II: Connection solutions:

RTscan provides two types of solutions:

Solution1: Dupont interface

RTscan provides the following DuPont interface EVK kit (with trigger button and buzzer) to connect the OEM barcode scanner module with Raspberry Pi:

This is a simple solution, just connect the 5.0V power supply (the EVK needs a 5.0v power supply), GND, RX, and TX pins.

 

RT214-12pins Pinout

PIN# Signal Name I/O State Function
1 NC
2 VDD 3.3V power input
3 GND Power-supply ground
4 RXD I TTL level 232 receives data
5 TXD O TTL level 232 transmits data
6 USB_D- USB_D- signal
7 USB_D+ USB_D+ signal
8 NC
9 BUZ O Beeper output
10 LED O Good Read LED output
11 nRST I Reset signal input
12 nTRIG I Trigger signal input

After connecting with the EVK board, it comes out 6pins:

 

PIN Connection:

PIN# Signal Name I/O State Function
1 GND Ground Power-supply ground
2 RXD I/O TTL level 232 receive
3 TXD I/O TTL level 232 transmits
4 USB_D+ I/O USB_D+ signal
5 USB_D- I/O USB_D- signal
6 VBUS Power-supply 5V

PIN Connection:

RT203/RT206/RT207/RT208/RT211/RT214/ RT830B+EVK board 6pins out Raspberry Pi 3B+
Pin6 Vin 5V(Pin2)
Pin1 GND GND(Pin6)
Pin2 RX Tx(Pin8)
Pin3 TX Rx(Pin10)

 

♠ OEM Scanner Modules that compliant with this solution:

RT203 RT206 RT207 RT208 RT212 RT211 RT214

∗please click the model number to view the full product introduction page.

24 January 2022

Solution 2: Connect via USB interface

For Raspberry Pi, if you prefer to connect the OEM barcode scanner module via USB interface, it also is fine, setup RTscan’s barcode scanner to HID mode (work directly) or USB CDC/Virtual Com mode (follow Part III/USB CDC communication).

 

♠ Barcode Scanner Modules that compliant with this solution:

All barcode scanners that have a USB interface.  All OEM scanner modules, all fixed-mount types, all handheld types. 

 

Part III: Make the OEM barcode scanner module work with Raspberry Pi system/ Python Sample code:

We developed Python sample code to work with our scanners so that you can copy our source codes and program your system very quickly and no need to write the whole code one by one; save your time and speed up your integration work!

In this article, we choose RT214 as an example to do the programming. Below we show how they work together when they connect via TTL-232, USB-CDC, and USB-HID.

1. TTL-232 Communication& Python Sample Code

Step 1: Hardware connection

Connect the 5.0v power supply pin, and GND pin, RXD, TXD pins via Dupont cable. Please refer to the image in “Solution1: Dupont interface”

 

RT214+EVK board 6pins out Raspberry Pi 3B+
Pin6 Vin 5V(Pin2)
Pin1 GND GND(Pin6)
Pin2 RX Tx(Pin8)
Pin3 TX Rx(Pin10)

 

Step 2: RT214 settings

RT214 scanner needs to be set to TTL-232 mode, scan the following barcode:

For more setting codes, please refer to “RT214_User_Guide”.

 

Step 3: Raspberry Pi Settings

(Ignore if you already have done this.)

(1).Enable serial port ttyS0

Open the serial port/dev/ttyS0 
Via the command window, input:
sudo rasp-config

Open the system configuration interface as shown below, select Interfacing Options

Then select serial:

Select No:

Then Yes:

Finally choose to save and exit.

 

At this time, enter the following command to see the serial port ttyS0:
ls -la /dev/
But if it still cannot be used, please double-check and re-configure it.

 

(2). Close the Console

In the terminal, input:

sudo systemctl stop serial-getty@ttyS0.service
sudo systemctl disable serial-getty@ttyS0.service

Then, restart.

And then input:

sudo systemctl mask serial-getty@ttyS0.service

Then it works!

 

(3). Modify Raspberry Pi CPU frequency (optional)

After the above steps 1 and 2, the settings are theoretically completed, but some times:

(1)After sending a string via serial port, in most cases the receiver shows up garbled data.

(2)When the serial port receives data, it appears data like **\xe8 \xe9**

This would be caused by the wrong working frequency of the Raspberry Pi, information link:
Raspberry Pi 3 login via UART on GPIO Baud Rates broken

The modification method is described as below:

sudo vim /boot/config.txt

Find out whether the sentence core_freq=250 is enabled. If not, remove the # number in front of this sentence, or add core_freq=250 at the boot/config.txt, done.

 

Step 4: Run the Python sample code

Run: RT214_TTL_RS232.py

#!/usr/bin/python
# -*- coding: utf-8 -*-

# RT214 scaner python test demo
#
# by RTSCAN 20200901

import sys
import serial
import time

tel
web
# raspberry pi usb cdc
# default usb device /dev/ttyACM0 115200 8n1
# ser = serial.Serial("/dev/ttyACM0", 115200, timeout=0.5)

# raspberry pi ttl
ser = serial.Serial("/dev/ttyS0", 115200, timeout=0.5)

#windows
# ser = serial.Serial("COM45", 115200, timeout=0.5)

print('serial test start ...')
if ser != None:
print('serial ready...')
else:
print('serial not ready')
sys.exit()

ser.timerout = 1 # read time out
ser.writeTimeout = 0.5 # write time out.

def printHex(_str):
for i in _str:
print('%02x' % i, end=" ")
print("")

# Command Syntax
#
# Prefix Storage Tag SubTag {Data} [, SubTag {Data}] [; Tag SubTag {Data}] […] ;
# Suffix Among which, {data} means integrant while [data] means optional data.
#
# Prefix: “~0000” (HEX: 7E 01 30 30 30 30), 6 characters.
# StorageType:
# “@” or “#”,1 character.
# “@” means permanent setting which will not be lost by removing power from the scanner or rebooting it;
# “#” means temporary setting which will be lost by removing power from the scanner or rebooting it.
# Tag:
# A 3-character case-sensitive field that identifies the desired command group.
# For example, the Tag for the Enable Code 11 is C11 (see Example 1 of Chapter 1).
# SubTag:
# A 3-character case-sensitive field that identifies the desired parameter within the tag group.
# For example, the SubTag for the Enable Code 11 is ENA (see Example 1 of Chapter 1).
# Data:
# The value for a feature or parameter setting, identified by the Tag and SubTag.
# For example, the Data for the Enable Code 11 is 1 (see Example 1 of Chapter 1).
# Suffix:
# “;” (HEX: 3B 03), 2 characters.

def send_cmd(StorageType_Tag):
Prefix = bytes("\x7E\x01\x30\x30\x30\x30", encoding="utf-8")
Suffix = bytes("\x3B\x03", encoding="utf-8")

cmd = Prefix + bytes(StorageType_Tag, encoding="utf-8") + Suffix

print("Sending:")
printHex(cmd)

ser.write(cmd)

time.sleep(0.1)
recv = ser.read(ser.in_waiting)
print("Response:")
printHex(recv)

def start_scanning():
print("start scanning")
send_cmd("#SCNTRG1")
return

def stop_scanning():
print("stop scanning")
send_cmd("#SCNTRG0")
return

...

Please contact us to get full sample codes

Output:And the RT214 automatically detects and reads bar code.

2. USB CDC Communication

If we want to use the USB port and make it work as a virtual serial port, set up the RT214 to USB Com port emulation mode. And the RT214 scanner will be detected as a COM device in Raspberry Pi.

 

Step 1: Hardware connection

Connect RT214 + USB Kit board to the USB port of Raspberry Pi:

 

Step 2: RT214 settings

RT214 set to USB CDC mode, scan the following Setting bar code

Enter setup

Set to USB-CDC mode

 Exit setup

 

Step 3: Raspberry Pi Settings

The RT214 USB CDC mode is the USB Com port emulation mode, the device name usually is:

/dev/ttyACM*

 

Step 4: Run the Python sample code

Run:  python RT214_USB_CDC.py

<br />import sys<br />import serial<br />import time</p><p># raspberry pi usb cdc<br /># default usb device /dev/ttyACM0 115200 8n1<br />ser = serial.Serial("/dev/ttyACM0", 115200, timeout=0.5)</p><p># raspberry pi ttl<br /># ser = serial.Serial("/dev/ttyS0", 115200, timeout=0.5)</p><p>#windows<br /># ser = serial.Serial("COM45", 115200, timeout=0.5)</p><p>print('serial test start ...')<br />if ser != None:<br />print('serial ready...')<br />else:<br />print('serial not ready')<br />sys.exit()</p><p>ser.timerout = 1 # read time out<br />ser.writeTimeout = 0.5 # write time out.</p><p>def printHex(_str):<br />for i in _str:<br />print('%02x' % i, end=" ")<br />print("")</p><p># Command Syntax<br />#<br /># Prefix Storage Tag SubTag {Data} [, SubTag {Data}] [; Tag SubTag {Data}] […] ;<br /># Suffix Among which, {data} means integrant while [data] means optional data.<br />#<br /># Prefix: “~0000” (HEX: 7E 01 30 30 30 30), 6 characters.<br /># StorageType:<br /># “@” or “#”,1 character.<br /># “@” means permanent setting which will not be lost by removing power from the scanner or rebooting it;<br /># “#” means temporary setting which will be lost by removing power from the scanner or rebooting it.<br /># Tag:<br /># A 3-character case-sensitive field that identifies the desired command group.<br /># For example, the Tag for the Enable Code 11 is C11 (see Example 1 of Chapter 1).<br /># SubTag:<br /># A 3-character case-sensitive field that identifies the desired parameter within the tag group.<br /># For example, the SubTag for the Enable Code 11 is ENA (see Example 1 of Chapter 1).<br /># Data:<br /># The value for a feature or parameter setting, identified by the Tag and SubTag.<br /># For example, the Data for the Enable Code 11 is 1 (see Example 1 of Chapter 1).<br /># Suffix:<br /># “;” (HEX: 3B 03), 2 characters.</p><p>def send_cmd(StorageType_Tag):<br />Prefix = bytes("\x7E\x01\x30\x30\x30\x30", encoding="utf-8")<br />Suffix = bytes("\x3B\x03", encoding="utf-8")</p><p>cmd = Prefix + bytes(StorageType_Tag, encoding="utf-8") + Suffix</p><p>print("Sending:")<br />printHex(cmd)</p><p>ser.write(cmd)</p><p>time.sleep(0.1)<br />recv = ser.read(ser.in_waiting)<br />print("Response:")<br />printHex(recv)</p><p>def start_scanning():<br />print("start scanning")<br />send_cmd("#SCNTRG1")<br />return</p><p>def stop_scanning():<br />print("stop scanning")<br />send_cmd("#SCNTRG0")<br />return<br />...<br />Please contact us to get full sample codes: sales@rtscan.net<br />

Output:

 

3. USB-HID

If you prefer to connect the OEM barcode scanner module via USB Keyboard simulation, it also is fine, setup RTscan’s barcode scanner to HID mode,

Then open “Text editor” from Raspberry Pi software, run the bar code scanning, the decoded data will show up directly.

 

The above python sample code can be used for most of our OEM barcode scanners, includes RT206 RT207 RT208 RT209 RT214,  if you want to learn more about them, please view the link below: 

 

https://www.rtscan.net/barcode-readers/oem-barcode-scanners/

Part VI: Video Demo

You can also refer to the following video demo to see how the OEM barcode scanner works with Raspberry Pi:

If you need a barcode scanner module for the Arduino microcontroller, please read:

 Arduino barcode scanner

If you need an embedded type 2d and QR barcode scanner for Arduino, please read:

Embedded QR Code scanner for Arduino

If you need an Embedded barcode scanner for Raspberry Pi, please read:

Embedded barcode scanner for Raspberry Pi

Ask A Sample To Test Now!