Support Forums


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

 

Read More


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

If you are using an Arduino microcontroller to develop your system, and you 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 Arduino Uno microcontroller with RTscan OEM barcode scanner modules and make them work.

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

  1. The OEM barcode scanner with 12pins TTL interface, but Arduino board without this connector, how can we connect them?
  2. Whatever OEM barcode scanners we choose, how can we control the barcode scanner by Arduino and also upload decoded data to the Ardunio system?

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

 

Contents

Part I: Introduction of Arduino UNO and RTscan OEM barcode scanner modules

Part II: Connection solutions

Part III: Get the OEM barcode scanner module work with the Arduino system /Arduino C++ sample code:

  1. For TTL-232 Communication& Python Sample code
  2. For USB CDC Communication
  3. For USB-HID keyboard simulation communication

Part VI: Video Demo

 

 

Part I: Introduction of Arduino UNO and RTscan barcode scanners

Arduino UNO:

The UNO is the most used and documented board of the whole Arduino microcontrollers family, many people choose this model for their projects. Arduino Uno has 14 digital input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs, a 16 MHz quartz crystal, a USB connection, a power jack, and ICSP header, and a reset button. It contains everything needed to support the microcontroller.

 

Arduino UNO Pinout

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

 

RTscan OEM barcode scanners:

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

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:

 

 

Solution 1: UART TTL Interface

RTscan developed a multi-interface Shield, connect the shield with Arduino UNO, connect the OEM barcode scanners to our EVK board (with trigger button and beeper ), then connect them via a 6pins UART TTL cable:

 

Via this solution, we make the connection between the barcode scanner engine and Arduino much durable/ solid.


And for this solution, the RT214 scanner needs to be set to TTL-232 Communication (follow Part III/TTL-232 communication).

 

♠ OEM Scanner Modules that compliant with this solution:

RT217

RT206 RT207 RT208 RT214 RT214B RT214C

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

 

Note: we have similar solutions for fixed mount type scanner RT830C and RT830i

UART-TTL:

12pins flat cable TTL-232:

If you prefer this type of scanner, please contact our sales team to get detailed information: sales@rtscan.net

 

 

Solution 2: Connect via USB host A

If you prefer your barcode scanner with a USB interface instead of a UART TTL cable,  then you can use this solution:  use an Arduino USB host shield.

The Arduino USB Host Shield allows you to connect a USB barcode scanner to your Arduino board, set up RTscan’s barcode scanner to HID mode, or USB CDC (Virtual Com mode).

 

Please follow Part III/USB CDC Communication/USB-HID Communication to check how to make them work together.

 

♠ Barcode Scanner Modules that compliant with this solution:

All barcode scanners have a USB interface.  All RTscan’s OEM scanner modules, fixed-mount types, and handheld types. 

 

 

Part III:

Get the OEM barcode scanner module work with the Arduino system /Arduino C++ sample code:

 

We developed sample code (only compatible with RTscan’s scanners) 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.

 

 

1. UART-TTL Communication

 

Step 1: Hardware connection

Connect RT214+EVK board to Arduino UNO as said above

 

Step 2: RT214 settings

RT214 needs to be set up with TTL-232 mode, scan the following barcode

Set to TTL-232 Mode, the default baud rate is 9600, 8-n-1

Enter setup

Set to TTL-232 mode

For more details, please refer to “RT214_User_Guide”

 

Step 3: Run the sample code

Upload the below sample code rt214_test_demo.ino to Arduino UNO.

 

 
 
/*
RT214 Test demo
by RTSCAN 20200903
*/
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX

void printHex(char *p, int len)
{
  char tmp[5];
  for (int i = 0; i < len; i++)
  {
    sprintf(tmp, "%02x ", p[i]);
    Serial.print(tmp);
  }
  Serial.println();
}

bool check_response(unsigned long timeout, String response)
{
  char c;
  String buffer;
  bool found = false;
  unsigned long t = millis();

  while (millis() - t < timeout)
  {
    if (mySerial.available() > 0)
    {
      c = mySerial.read();
      buffer += c;
      if (buffer.indexOf(response) != -1 || buffer.equals(response))
      {
        found = true;
        break;
      }
    }
  }

  while (mySerial.available() > 0)
  {
    c = mySerial.read();
    buffer += c;
  }

  Serial.println(buffer);
  printHex(buffer.c_str(), buffer.length());

  return found;
}

void send_cmd(char * p)
{
  mySerial.print(p);
  check_response(100, "\x06");
}

void trigger_stop_settings() 
{
  Serial.println("trigger_stop_settings");
  send_cmd("\x1b\x30");
}

void analog_trigger_setting() 
{
  Serial.println("analog_trigger_setting");
  send_cmd("\x1b\x31");
}

void automatic_reading_settings() 
{
  Serial.println("automatic_reading_settings");
  send_cmd("\x1b\x32");
}

void continuous_reading_settings() 
{
  Serial.println("continuous_reading_settings");
  send_cmd("\x1b\x33");
}

void query_ESN() 
{
  Serial.println("query_ESN");
  send_cmd("\x7E\x00\x00\x05\x33\x48\x30\x32\x30\xB3");
}

void setup()
{
  Serial.begin(115200);
  while (!Serial)
  {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  Serial.println("RT214 Test demo");

  mySerial.begin(9600);

  query_ESN();
  
  trigger_stop_settings();
}
...
 
 

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

 

And the RT214 automatically detects and reads bar codes.

Output:

 

Introduction of the serial port commands protocol for RT214

The often-used serial port commands are as below (HEX):

Trigger mode:1B 31

Stop scanning:1B 30

Auto mode:1B 32

Continuous read mode:1B 33

For more details, please refer to 《RTscan Serial Programming Command Manual.PDF》

 

 

2. USB CDC Communication

In this solution, we connect the OEM barcode scanner to Arduino via USB host shield, and firstly we need to set the scanner to USB Virtual Com emulation mode, and the Arduino recognizes the scanner as a USB CDC device. Follow the steps as below:

 

Step 1: Hardware connection

Connect the RT214 scanner to the USB port of the Arduino USB host shield through a USB data cable.

 

Step 2: RT214 settings

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

Enter setup

Set to USB-CDC mode:

Recognized as a COM port device on the computer:

 

Step 3: Include the library

Arduino Library Manager

First, install Arduino IDE version 1.6.2 or newer, then simply use the Arduino Library Manager to install the library.

Please see the following page for instructions:

http://www.arduino.cc/en/Guide/Libraries#toc3

 

Manual installation

First download the library by clicking on the following link:

https://github.com/felis/USB_Host_Shield_2.0

Then uncompress the zip folder and rename the directory to “USB_Host_Shield_20”, as any special characters are not supported by the Arduino IDE.

Now open up the Arduino IDE and open “File>Preferences”. There you will see the location of your sketchbook. Open that directory and create a directory called “libraries” inside that directory. Now move the “USB_Host_Shield_20” directory to the “libraries” directory.

The final structure should look like this:

  • Arduino/
    • libraries/
      • USB_Host_Shield_20/

Now quit the Arduino IDE and reopen it.

Now you should be able to open all the examples codes by navigating to “File>Examples>USB_Host_Shield_20” and then select the example you will like to open.

For more information please visit the following sites:

http://arduino.cc/en/Guide/Libraries

https://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use.

 

Step 4: Run the sample code

Run:

acm_terminal. ino

 
#include <cdcacm.h>
#include <usbhub.h>

#include "pgmstrings.h"

// Satisfy the IDE, which needs to see the include statment in the ino too.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
#include <SPI.h>

class ACMAsyncOper : public CDCAsyncOper
{
public:
    uint8_t OnInit(ACM *pacm);
};

uint8_t ACMAsyncOper::OnInit(ACM *pacm)
{
    uint8_t rcode;
    // Set DTR = 1 RTS=1
    rcode = pacm->SetControlLineState(3);

    if (rcode)
    {
        ErrorMessage<uint8_t>(PSTR("SetControlLineState"), rcode);
        return rcode;
    }

    LINE_CODING	lc;
    lc.dwDTERate	= 115200;
    lc.bCharFormat	= 0;
    lc.bParityType	= 0;
    lc.bDataBits	= 8;

    rcode = pacm->SetLineCoding(&lc);

    if (rcode)
        ErrorMessage<uint8_t>(PSTR("SetLineCoding"), rcode);

    return rcode;
}

USB     Usb;
//USBHub     Hub(&Usb);
ACMAsyncOper  AsyncOper;
ACM           Acm(&Usb, &AsyncOper);

void setup()
{
  Serial.begin( 115200 );
#if !defined(__MIPSEL__)
  while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
#endif
  Serial.println("Start");
  Serial.println("Please set the scanner to USB CDC mode");

  if (Usb.Init() == -1)
      Serial.println("OSCOKIRQ failed to assert");

  delay( 200 );
}
...
 



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


 

Open the serial port for debugging:

 

Scan any barcode and it will be shown as below:

 

 

3. USB-HID Communication

In this solution, the scanner is set to USB HID KBW mode, and the Arduino recognizes the scanner as a USB keyboard simulation device.

 

Step 1: Hardware connection

Connect the RT214 scanner to the USB port of the Arduino USB host shield through a USB data cable.

 

Step 2: RT214 settings

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

Enter setup:

Set to USB-HID mode:

Recognized as  on the computer:

 

Step 3: Include the library

Arduino Library Manager

First, install Arduino IDE version 1.6.2 or newer, then simply use the Arduino Library Manager to install the library.

Please see the following page for instructions:

http://www.arduino.cc/en/Guide/Libraries#toc3

 

Manual installation

First download the library by clicking on the following link:

https://github.com/felis/USB_Host_Shield_2.0

Then uncompress the zip folder and rename the directory to “USB_Host_Shield_20”, as any special characters are not supported by the Arduino IDE.

Now open up the Arduino IDE and open “File>Preferences”. There you will see the location of your sketchbook. Open that directory and create a directory called “libraries” inside that directory. Now move the “USB_Host_Shield_20” directory to the “libraries” directory.

The final structure should look like this:

  • Arduino/
    • libraries/
      • USB_Host_Shield_20/

Now quit the Arduino IDE and reopen it.

Now you should be able to open all the examples codes by navigating to “File>Examples>USB_Host_Shield_20” and then selecting the example you would like to open.

For more information please visit the following sites:

http://arduino.cc/en/Guide/Libraries

https://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use.

 

Step 4: Run the sample code

Run: Scanner_USBHIDUniversalKbd. ino

#include <hidboot.h>
#include <usbhid.h>
#include <hiduniversal.h>

#include <SPI.h>

class KbdRptParser : public KeyboardReportParser
{
  public:
    void PrintKey(uint8_t mod, uint8_t key);

    bool isScanEnd();
    void PrintScanCode();

  protected:
    void OnControlKeysChanged(uint8_t before, uint8_t after);

    void OnKeyDown  (uint8_t mod, uint8_t key);
    void OnKeyUp    (uint8_t mod, uint8_t key);
    void OnKeyPressed(uint8_t key);

    String ScanCode = "";
    uint32_t FreeTime = 0;
    bool StartScan = false;
};

void KbdRptParser::PrintKey(uint8_t m, uint8_t key)
{
  MODIFIERKEYS mod;
  *((uint8_t*)&mod) = m;
  Serial.print((mod.bmLeftCtrl   == 1) ? "C" : " ");
  Serial.print((mod.bmLeftShift  == 1) ? "S" : " ");
  Serial.print((mod.bmLeftAlt    == 1) ? "A" : " ");
  Serial.print((mod.bmLeftGUI    == 1) ? "G" : " ");

  Serial.print(" >");
  PrintHex<uint8_t>(key, 0x80);
  Serial.print("< ");

  Serial.print((mod.bmRightCtrl   == 1) ? "C" : " ");
  Serial.print((mod.bmRightShift  == 1) ? "S" : " ");
  Serial.print((mod.bmRightAlt    == 1) ? "A" : " ");
  Serial.println((mod.bmRightGUI    == 1) ? "G" : " ");
};

void KbdRptParser::OnControlKeysChanged(uint8_t before, uint8_t after) {

  MODIFIERKEYS beforeMod;
  *((uint8_t*)&beforeMod) = before;

  MODIFIERKEYS afterMod;
  *((uint8_t*)&afterMod) = after;

  if (beforeMod.bmLeftCtrl != afterMod.bmLeftCtrl) {
    Serial.println("LeftCtrl changed");
  }
  if (beforeMod.bmLeftShift != afterMod.bmLeftShift) {
    Serial.println("LeftShift changed");
  }
  if (beforeMod.bmLeftAlt != afterMod.bmLeftAlt) {
    Serial.println("LeftAlt changed");
  }
  if (beforeMod.bmLeftGUI != afterMod.bmLeftGUI) {
    Serial.println("LeftGUI changed");
  }

  if (beforeMod.bmRightCtrl != afterMod.bmRightCtrl) {
    Serial.println("RightCtrl changed");
  }
  if (beforeMod.bmRightShift != afterMod.bmRightShift) {
    Serial.println("RightShift changed");
  }
  if (beforeMod.bmRightAlt != afterMod.bmRightAlt) {
    Serial.println("RightAlt changed");
  }
  if (beforeMod.bmRightGUI != afterMod.bmRightGUI) {
    Serial.println("RightGUI changed");
  }

}

void KbdRptParser::OnKeyDown(uint8_t mod, uint8_t key)
{
  // Serial.print("DN ");
  // PrintKey(mod, key);
  uint8_t c = OemToAscii(mod, key);

  if (c)
    OnKeyPressed(c);
}

void KbdRptParser::OnKeyUp(uint8_t mod, uint8_t key)
{
  // Serial.print("UP ");
  // PrintKey(mod, key);
  
  FreeTime = millis();
  StartScan = true;
}

void KbdRptParser::OnKeyPressed(uint8_t key)
{
  // Serial.print("ASCII: ");
  // Serial.println((char)key);
  ScanCode = ScanCode + String((char)key);
};

bool KbdRptParser::isScanEnd()
{
  if(millis() - FreeTime > 200 && StartScan){
      StartScan = false;
      return true;
  }

  return false;
};

void KbdRptParser::PrintScanCode()
{
  Serial.print("ScanCode: ");
  Serial.println(ScanCode);
  ScanCode = "";
};

USB          Usb;
HIDUniversal Hid(&Usb);
KbdRptParser Prs;

void setup()
{
  Serial.begin( 115200 );
#if !defined(__MIPSEL__)
  while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
#endif
  Serial.println("Start");
  Serial.println("Please set the scanner to USB HID mode");

  if (Usb.Init() == -1)
    Serial.println("OSC did not start.");

  delay( 200 );

  Hid.SetReportParser(0, &Prs);
}
 ...



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

 

 

Open the serial port for debugging:

Scan any barcode and it will be shown as below:

 

This article is a solution introduction for Arduino barcode scanners, if you are using Raspberry Pi and need an OEM barcode scanner, please read: Raspberry Pi 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

We developed an Arduino solution for most of our OEM barcode scanners, includes RT203 RT206 RT207 RT208 RT209 RT211 RT830B, if you want to learn more about them, please view below: https://www.rtscan.net/barcode-readers/oem-barcode-scanners/

Read More



Upgrade of the 2d scanner module: RT200


 

Recently, we released new version(Version 2) of the 2d scanner module: RT200, this new version has been improved in terms of  structure, illumination and decode performance, below in details:

2d scanner module

Version 1                                                                                 Version 2 (new)

 

1.   Different in the PIN position:

new RT200 imager

Version 1                                                                                 Version 2 (new)

2.   Improved the brightness and uniformity of the aiming lights;  improved the illumination light so as to improve the decode performance for reading barcode in dark environment and for reading bar code from long distance away.

 

Note:

After upgrade, the PIN definition and all of the protocol are exactly keep the same with before. So if you use the version 1 before then you can use the Version 2 directly and without change any protocol of your software.

 

2D-Lector-de-codigo-barras-OEM-RT200 2D-Lector-de-codigo-OEM-RT200 OEM-2D-Lector-de-codigo-RT200

Read More