Raspberry Pi barcode scanner: connect OEM barcode scanners modules with Raspberry Pi microcontroller (MCU)

 

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.

 

Contents

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

Part II: Connection solutions

  • Solution 1: Dupont interface
  • Solution 2: Connect via USB interface

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

  1. TTL-232 Communication& Python Sample code
  2. USB CDC Communication
  3. USB-HID

Part VI: Video Demo

 

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.

 

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

#RT214 python test demo
#ttl232 readme
#by RTSCAN 20200901

import sys
import serial
import time


#default usb device /dev/ttyACM0 9600 8n1
ser = serial.Serial("/dev/ttyS0",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('0x%02x'%ord(i)),
    print("")



def trigger_stop_settings():
    print("Trigger_stop_settings");
    # time.sleep(0.1)
    # t = ser.read(ser.in_waiting)
    t = ser.read()
    print("reply")
    printHex(t)
    return


def analog_trigger_setting():
    print("analog_trigger_setting");
    ser.write("\x1b\x31")
    # time.sleep(0.1)
    # t = ser.read(ser.in_waiting)
    t = ser.read()
    print("reply")
    printHex(t)
    return



def automatic_reading_settings():
    print("Automatic reading settings");
    ser.write("\x1b\x32")
    t = ser.read()
    print("reply")
    printHex(t)
    return



def continuous_reading_settings():
    print("Continuous reading settings");
    ser.write("\x1b\x33")
    t = ser.read()
    print("reply")
    printHex(t)
    return




def query_ESN():
    print("query ESN");
    ser.write("\x7E\x00\x00\x05\x33\x48\x30\x32\x30\xB3")
    ...

Please contact us to get full sample codes: sales@rtscan.net

 


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

#RT214 python test demo
#
#by RTSCAN 20200901



import sys
import serial
import time


#default usb device /dev/ttyACM0 9600 8n1
ser = serial.Serial("/dev/ttyACM0",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('0x%02x'%ord(i)),
    print("")



def trigger_stop_settings():
    print("Trigger_stop_settings");
    ser.write("\x1b\x30")
    time.sleep(0.1)
    t = ser.read(ser.in_waiting)
    print("reply")
    printHex(t)
    return



def analog_trigger_setting():
    print("analog_trigger_setting");
    ser.write("\x1b\x31")
    time.sleep(0.1)
    t = ser.read(ser.in_waiting)
    print("reply")
    printHex(t)
    return
...

Please contact us to get full sample codes: sales@rtscan.net


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:

https://www.youtube.com/watch?v=M9ATa9BmlrU&feature=emb_logo

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

 

17477 View