2D Barcode Scanner Breakout Hookup Guide

Pages
Contributors: El Duderino, MAKIN-STUFF
Favorited Favorite 2

DE2120 Arduino Library

Note: This example assumes you are using the latest version of the Arduino IDE on your desktop. If this is your first time using Arduino, please review our tutorial on installing the Arduino IDE. If you have not previously installed an Arduino library, please check out our installation guide.

The SparkFun DE2120 Arduino Library helps to interface an Arduino microcontroller with the barcode scanner to configure common settings as well as poll the device for scanned codes. Note, the library does not cover all of the codes from the Scan Settings Manual; just the ones we found particularly useful.

Install the Arduino Library Manager by searching for "SparkFun DE2120 Arduino Library" and clicking the "Install" button to download and install the latest version. Users who prefer to manually install the library can get it from the GitHub Repository or you can download the repo by clicking the button below:

Library Functions

The list below goes over all the available functions in the DE2120 Library along with short descriptions of what they do. The examples use many of the functions so refer to them for demonstrations of how to use the common functions in your own code.

Class

In the global scope, construct the DE2120 object (scanner is used in the examples) without arguments:

language:c
DE2120 scanner;

Sketches should also create a character for the serial buffer and define its length for the scan data from the DE2120:

language:c
#define BUFFER_LEN 40
char scanBuffer[BUFFER_LEN];

Device Settings and Setup

The following functions control most of the settings for the DE2120 over TTL serial.

  • bool begin(HardwareSerial &serialPort); - Initialize communication over the hardware serial port.
  • bool begin(SoftwareSerial &serialPort); - Initialize communication using the Software Serial library.
  • bool isConnected(); - Returns true if device's ID is what it should be.
  • uint8_t getVersion(); - Queries device for its version number.
  • bool factoryDefault(); - Sets the DE2120 to factory default settings.
  • bool sendCommand(const char *cmd, const char *arg = "", uint32_t maxWaitInms = 3000); - Send a specific command to the DE2120. The function takes two strings as arguments, links them, adds the command prefix "^^" and the command suffix "." and then transmits the command to the module. For example, to enable Matrix 2 of 5 scanning, which is done using the command '^^M25ENA1.' you would make the call 'scanner.sendCommand("M25ENA", "1")'
  • bool readBarcode(char *resultBuffer, uint8_t size); - Check the receive buffer for serial data. If data is present, check the result for a Carriage Return (CR). CR marks a completed scan so if found, the function overwrites the result buffer until it is full or a CR is reached in the receive buffer. Refer to Example 1 for a demonstration of this function.
  • bool available(); - Returns the number of characters in the serial buffer ready to be read.
  • int read(); - Read the data present in the serial buffer.
  • bool changeBaudRate(uint32_t baud); - Adjust the baud rate. Default is 115200.
  • bool changeBuzzerTone(uint8_t tone); - Adjust the buzzer's frequency between LOW, MED and HIGH.
  • bool enableDecodeBeep(); - Enable the buzzer to beep on a barcode decode.
  • bool disableDecodeBeep(); - Disable the buzzer on barcode decode.
  • bool enableBootBeep(); - Enable the buzzer to beep on startup.
  • bool disableBootBeep(); - Disable the startup buzzer beep.
  • bool lightOn(); - Turn the illuminating LED on.
  • bool lightOff(); - Turn the illuminating LED off.
  • bool reticleOn(); - Turn the red "scanner" LED on.
  • bool reticleOff(); - Turn the red "scanner" LED off.
  • bool changeReadingArea(uint8_t percent); - Adjust the percentage of the frame area of the DE2120 to scan for barcodes. Valid options are 100%, 80%, 60%, 40% and 20%.
  • bool enableImageFlipping(); - Enable mirror image reading.
  • bool disableImageFlipping(); - Disable mirror image reading.
  • bool USBMode(char *mode); - Enable USB communication and set the mode. Note, the DE2120 no longer communicates via TTL when this is enabled.
  • bool enableContinuousRead(uint8_t repeatInterval = 2); - Enable continuous read mode and set the interval between scans. Default value is .
  • bool disableContinuousRead(); - Disable continuous read mode.
  • bool enableMotionSense(uint8_t sensitivity = 50); - Enable motion sensitive read mode and set the sensitivity level. Available sensitivity values are 15, 20, 30, 50 and 100.
  • bool disableMotionSense(); - Disable motion sensitive read mode.
  • bool enableAll1D(); - Enable decoding of all 1D symbologies.
  • bool disableAll1D(); - Disable decoding of all 1D symbologies.
  • bool enableAll2D(); - Enable decoding of all 2D symbologies.
  • bool disableAll2D(); - Disable decoding of all 2D symbologies.

Polling Scan Data

These two functions are pretty straightforward and control whether or not the DE2120 is scanning for barcodes in its view area.

  • bool startScan(); - Start scanning for barcodes.
  • bool stopScan(); - Stop scanning for barcodes.