Raspberry Pi Barcode Reader HAT Review


When the clerk scans our groceries or when we visit the self-scan kiosk, barcodes have been part of our daily routine for decades. Developed as a form of machine-readable input, barcodes are loosely based on Morse code, using thick and thin bars of alternating black and white to represent values. We take them for granted in the 21st century, but the humble barcode revolutionized 20th century commerce.

(Image credit: Tom’s Hardware)

SB Components’ latest HAT, the $50 RPI Barcode Reader, is exactly that, a Raspberry Pi HAT with a built-in DE2120 barcode reader. The HAT features a 1.14 inch TFT display and GPIO passthrough for HATs and breadboard projects.

Armed with a stack of barcodes to test, including some retro PlayStation 1 games, we tested RPI Barcode Reader HAT on our Raspberry Pi 4 and on our Windows 10 PC.

HAT Barcode Reader Specifications

Barcode reader DE2120 2D Scan Engine [pdf]
To display 1.14 inch TFT
Communication 40 pin GPIO and Micro USB
Barcode compatibility 1D
UPC-A, UPC-E, EAN-8, EAN-13, Code 128, GS1-128, Code 39, Code 93, Code 11, Interleaved 2 of 5, Matrix 2 of 5, Industrial 2 of 5, Codabar, MSI , GS1 DataBar, Datalogic 2 out of 5
QR Code, Datamatrix, PDF 417, Micro PDF 417, Aztec Code
Dimensions 65 x 56mm

Using the HAT barcode reader

As it is a HAT, it fits directly on the 40 GPIO pins and is powered via the GPIO. The GPIO is distributed on top of the HAT and that means we could stack another board on top, something we’ll test later.

We tested the Barcode Reader HAT with an early version of the Python library and provided SB Components with feedback on the issues we encountered. Suffice it to say that the Python library is functional and easy to use, but a number of typos have slowed our progress. With typos identified, overcome and reported we were finally able to use the board and it works pretty well.

(Image credit: Tom’s Hardware)

The basis of the Python library is to interact with the DE2120 scanner module which can spit out data over a serial/UART connection. The scanner can be reprogrammed to act as a keyboard, outputting data as if it were a keyboard through the micro USB port, meaning it can be used with another computer.

We tested the Barcode Scanner HAT away from the Raspberry Pi. Using a special barcode to configure the reader as a USB keyboard, we connected the HAT to our Windows 10 PC and started scanning random barcodes, all of which appeared in our text editor window.

We chose to use the scanner as a serial device and after going through the sample applications we understood how it worked. The data is output as bytes, essentially a string of text starting with b tracking barcode data contained in the final character /r is a carriage return.

After grabbing a bunch of PlayStation 1 games from our attic, we set about creating a demo to learn more about the Barcode Reader HAT. We used the barcode of two games as a test. A conditional test would check the data read by the barcode reader and compare it to the two known barcodes. If there was a match, the game name is printed to the Python Shell. We added a few extra lines to display a screenshot of the game on the 280 x 135 resolution screen. We had to manually edit the image to match the screen resolution exactly, if it there is even a pixel difference, the code will be wrong. We created three images, two for games and one with our logo. Our logo is displayed while the scanner waits for input. We ran the code and lined up our first game, pressed the scan button and our barcode was read, printing the game name to the shell and displaying the screenshot on screen. After a while, the screenshot is replaced by the Tom’s Hardware logo, waiting for another barcode to be scanned.

We extended our test and used an HC-SR04+ ultrasonic sensor, connected to the GPIO via the breakout. The purpose of the HC-SR04+ was to trigger the barcode reader without touching the device. The Python library includes an ultrasound module that abstracts the code, making the sensor easier to use. We successfully integrated the sensor into the project and were able to scan our games hands-free and view screenshots on screen.

Image 1 of 2

Raspberry Pi Barcode Reader Hat

(Image credit: Tom’s Hardware)
Picture 2 of 2

Raspberry Pi Barcode Reader Hat

(Image credit: Tom’s Hardware)

Building on our GPIO success, we connected our favorite Raspberry Pi HAT, the Pimoroni Explorer HAT Pro to the GPIO header, and can confirm that the Explorer HAT is accessible. There is a but however, the tall header pins are simply not tall enough to provide clearance on the barcode scanner. We added another GPIO header, giving us a few extra millimeters of clearance. We went through Pimoroni’s test.py file and all functions were available. We then mixed some Explorer HAT code into our game scanner test code so that a certain color of LEDs light up and a motor spins while we scan a game. With just four lines of code, It worked as expected, meaning we can add the HAT barcode reader to our projects, using it as a new means of input and control.

Barcode reading

Barcodes are available in all kinds of formats. We are mostly used to barcodes on groceries, books, and magazines. But over the past decade, QR (Quick Response) codes have been used to encode a lot more data into an easily digestible format.

In a recent episode of Tom’s Hardware: The Pi Cast, a viewer asked if the HAT barcode scanner could be used with QR codes, so we created our own QR code containing Tom’s hardware URL and we can confirm that SB Components’ HAT barcode reader can be used with QR codes, either as a Raspberry Pi HAT or via keyboard emulation.

HAT project ideas for barcode reader

Barcodes aren’t just for shopping. There are many ways to generate your own barcodes, so the HAT barcode scanner can be used to control projects with the wave of a card. At conferences or in the workplace, Barcode Reader HAT can be used to scan QR code business cards and save them to a database. In the classroom, learners can use QR codes to register attendance or control interactive displays.


(Image credit: Tom’s Hardware)

It’s a fun little hat, even if it’s a little niche. For just over $50, it’s not a HAT for everyone, but the form factor and ease of use will benefit those looking to add a barcode input to their Pi project. Barcode Reader HAT comes into its own when used with other HATs.


About Author

Comments are closed.