In this tutorial, the Basic v2.7 core is paired with the Module13.2 QRCode to implement 1-D/2-D code recognition. Before use, please refer to the figure below and set the DIP switches to the specified positions.
This example pairs the Basic v2.7 core with the Module13.2 QRCode and uses G34 (RX) and G12 (TX) as communication pins. The specific DIP-switch settings are shown below.
This example sets the Module13.2 QRCode to key-triggered scan mode. Clicking Button A sends the start/stop scan commands via UART. Holding down Button B controls scanning through the module’s TRIG pin (low level to start scanning, high level to stop). After a successful scan, the decoded result is displayed on the screen.
/* (code block remains unchanged) */
The module supports multiple scan-trigger modes.
enum TriggerMode_t {
TRIGGER_MODE_KEY = 0,
TRIGGER_MODE_CONTINUOUS = 1,
TRIGGER_MODE_AUTO = 2,
TRIGGER_MODE_PULSE = 4,
TRIGGER_MODE_MOTION_SENSING = 5
};
TRIGGER_MODE_KEY
:TRIGGER_MODE_CONTINUOUS
:TRIGGER_MODE_AUTO
:TRIGGER_MODE_PULSE
:TRIGGER_MODE_MOTION_SENSING
:TRIGGER_MODE_AUTO
, the other modes can be controlled via UART commands during operation. 2. Mode settings are stored in the device and remain after power-off.Configure the trigger mode with setTriggerMode
:
module_qrcode.setTriggerMode(QRCodeM14::TRIGGER_MODE_KEY);
// module_qrcode.setTriggerMode(QRCodeM14::TRIGGER_MODE_CONTINUOUS);
// module_qrcode.setTriggerMode(QRCodeM14::TRIGGER_MODE_AUTO);
// module_qrcode.setTriggerMode(QRCodeM14::TRIGGER_MODE_PULSE);
// module_qrcode.setTriggerMode(QRCodeM14::TRIGGER_MODE_MOTION_SENSING);
Module13.2 QRCode supports two ways to start scanning:
startDecode()
(software trigger via UART command).setTriggerLevel(false)
(hardware trigger by pulling TRIG low).Control scanning with startDecode
:
module_qrcode.startDecode();
delay(1000);
module_qrcode.stopDecode();
delay(1000);
Control scanning with setTriggerLevel
:
module_qrcode.setTriggerLevel(false);
delay(1000);
module_qrcode.setTriggerLevel(true);
delay(1000);
Set the fill-light mode with setFillLightMode()
; the enum is defined as:
enum FillLightMode_t {
FILL_LIGHT_OFF = 0, // Light off
FILL_LIGHT_ON_DECODE = 2, // Light on during decoding
FILL_LIGHT_ON = 3 // Light on
};
FILL_LIGHT_OFF
: Fill light always offFILL_LIGHT_ON_DECODE
: Fill light stays on during decodingFILL_LIGHT_ON
: Fill light always onConfigure with setFillLightMode
:
module_qrcode.setFillLightMode(QRCodeM14::FILL_LIGHT_ON_DECODE);
// module_qrcode.setFillLightMode(QRCodeM14::FILL_LIGHT_ON);
// module_qrcode.setFillLightMode(QRCodeM14::FILL_LIGHT_OFF);
Set the position-light mode with setPosLightMode()
; the enum is defined as:
enum PosLightMode_t {
POS_LIGHT_OFF = 0, // Light off
POS_LIGHT_FLASH_ON_DECODE = 1, // Light flashing during decoding
POS_LIGHT_ON_DECODE = 2 // Light on during decoding
};
module_qrcode.setPosLightMode(QRCodeM14::POS_LIGHT_ON_DECODE);
// module_qrcode.setPosLightMode(QRCodeM14::POS_LIGHT_FLASH_ON_DECODE);
// module_qrcode.setPosLightMode(QRCodeM14::POS_LIGHT_OFF);
POS_LIGHT_OFF
: Position light always offPOS_LIGHT_FLASH_ON_DECODE
: Position light flashes during decodingPOS_LIGHT_ON_DECODE
: Position light stays on during decodingModule13.2 QRCode supports multiple USB working modes, including USB-CDC, USB HID Keyboard, and USB HID-POS.
Before use, flip the on-board interface switch to the USB side. This connects the module’s USB_D+ and USB_D- pins to PORT.C. Then use a Grove to USB-C adapter board to connect PORT.C to a PC. Refer to the example programs below to configure the desired USB mode.
Call setModeUsbSerial()
to enter USB-CDC mode. After connecting to a PC, a virtual serial port appears. Use a serial monitor or terminal tool to connect, hold Button A to scan, and view results in the terminal. UART commands are also available. To return to UART mode, send the HEX values 21 42 40 00 (serial-port configuration command). The QR module blinks briefly to indicate success, and the USB-CDC interface closes.
/* (code block remains unchanged) */
Call setModeUsbKeyboard()
to enter USB-HID mode. The device emulates a USB keyboard. Hold Button A to scan; the decoded result is output as keyboard input.
Call setModeUsbPos()
to enter USB-HID POS mode. The device emulates a standard POS barcode scanner. This mode requires a host application with the standard protocol. Currently, only a Windows host is provided; other platforms can port the source code.
Run examples\c\vs\Release\read-in-callback.exe
in the package and scan a test QR code; the result appears in the host window.
If a driver error appears in Device Manager when using USB HID-POS:
Follow these steps:
When “HID-compliant device” appears in Device Manager, USB HID-POS works correctly.
Download and open CodeBarConfigTool.exe
; the tool interface is shown below.
The example below shows how to switch from USB-CDC to UART mode:
First, click icon ①, select the corresponding USB port at ②, and click “Connect” at ③. When ④ shows “Online,” the connection is successful.
Next, tick box ①, locate item ② and double-click it. When the configuration information shown at ③ appears, UART mode is configured successfully.
For detailed instructions, refer to CodeBarConfigTool.pdf
in the software package.