Raspberry Pi Barcode Scanner in Python: Steps and Products
Today I will introduce the best Raspberry Pi barcode scanners available in the market and also explain how you can setup Python barcode reader on your device.
First, let’s start with a how-to guide for setting up a USB barcode scanner with a camera for Raspberry Pi.
DIY Raspberry Pi USB Barcode Scanner
Step-1: Gather Accessories
Before starting with this beginner-friendly Raspberry Pi project, collect all the parts and accessories required. You should also have some prior knowledge of Raspberry Pi Coding in Python, or you can directly get the source code online.
Check the list of parts below:
1) Raspberry Pi board (Pi 3 recommended)
2) Micro SD card (16GB will be enough)
3) USB/Wireless Barcode Scanner
4) Power supply for Raspberry Pi setup
5) Jumper cables
Step-2: Connection and Setup
Connect the barcode scanner with the Raspberry Pi. If you are using the Pi 3 model, then you can make the wireless connection or can directly connect it to the USB.
Now boot up Raspberry Pi and open the command terminal.
- Enter the below command in terminal:
- The configuration window will open. In that, go to ‘Advanced Options.’
- You will see a ‘Serial’ interface option in that menu. Enable it.
- Enter the below command which will install the dependencies
pip install requests
- Now, download the Dynamsoft Barcode Reader SDK and extract it on your device:
sudo ln –s <path of your library> /lib.DynamsoftBarcodeReader.so /usr/lib/libDynamsoftBarcodeReader.so
- Create or modify (if already created) setup.py file, build the extension and include/modify like below:
Include_dirs=[“/usr/lib/<latest-python-version>/dist-packages/numpy/core/include/numpy”, “<your dbr path>/include”],
library_dirs= [‘<Your dbr path>/lib’],
python setup.py build
sudo python setup.py install
- Now, create a dbr.c file in which you will add the Dynamsoft Barcode Reader SDKs to the native Python code. (You will find the full source code on online blogs if you don’t know the coding. One is here)
- If you get an error message of invalid file or directory like “fatal error: Python.h: No such file or directory”, then insert the line as shown below:
sudo apt-get install python-dev
Step-3: OpenCV on Jessie
Now, it is the time to install OpenCV on Raspbian Jessie. Check the full guide to do that in case you need by clicking here.
Step-4: Make the Raspberry Pi Barcode Scanner in Python
Create file cam_reader.py and place the below command lines in that:
vc = cv2.VideoCapture(0)
cache = “”
results = None
rval, frame = vc.read()
rval = False
rval, frame = vc.read()
key = cv2.waitKey(20)
if key == ord(‘c’):
cache = getImageName()
results = decodeFile(cache)
print “Total count: ” + str(len(results))
for result in results:
print “barcode format: ” + formats[result]
print “barcode value: ” + result + “\n*************************”
elif key == 27:
Now run the script by entering the line as below:
Your Raspberry Pi is ready to scan and read the barcode now. Press ‘C’ on your Raspberry Pi keyboard and your barcode scanner with camera will start working.
After getting the information about how to make Python barcode reader on Raspberry Pi, let’s see some of the most sought barcode scanners for Raspberry Pi.
Raspberry Pi Barcode Scanner
1) Inateck BCST-70 Wireless Barcode Scanner
This automatic, precise, and Bluetooth enabled barcode scanner & reader from Inateck works perfectly with your Raspberry Pi model. It can lock the upper and lower cases of the barcode and has the ability to hide some of that barcode part.
Features of Inateck Wireless Raspberry Pi Barcode Scanner are:
- It comes as ready-to-use out of the box and supports multi-language keyboard of German, English, Italian, French, and Spanish.
- It is compatible with Raspberry Pi Operating Systems as well as iOS, Windows, Mac OS, Android, Mac OS, and other Linux distros.
- This barcode scanner can read the codes from a far distance and has minimal downtime.
- You can edit the prefix or suffix up to 32 digits. This scanner has the ability to scan broken barcodes even under low lights.
- It can read different types of 1D barcodes and can work longtime (approx. 15 days constantly) after a full charge due to its good battery life.
2) WoneNice Raspberry Pi USB Barcode Scanner
Easy to install and use functionality of this USB barcode scanner makes it favorite for the Raspberry Pi beginners. It has a stylish design and newbie-friendly operation help to use it in wide range of applications.
Features of WoneNice USB Barcode Scanner for Raspberry Pi are:
- The USB cable has a length of 2 meters which is enough for any workplace.
- It comes with LED indicators and buzzers to let you know for the scanning and reading processes.
- The handheld, stylish design of this USB barcode scanner makes you enjoy the working with it.
- It can scan up to 200 barcodes and has laser visibility of 650-670nm.
- This Raspberry Pi compatible USB barcode scanner has the capability of decoding different types of codes like Code11, Code32, Code39, UPC-A, EAN-13, Telepen postal code, Industrial 2 of 5, and many more.
3) Takihoo USB & Wireless Barcode Scanner
Takihoo manufactured this dual mode barcode scanner for Raspberry Pi and other devices. You can use it either wirelessly using Bluetooth or can connect it to your machine with the help of the USB cable.
Features of Wireless / USB Raspberry Pi Barcode Scanner from Takihoo are:
- This barcode reader has a wireless operating range of 20 to 200 meters.
- Its 850mAH rechargeable battery makes it durable for longer time and protects it against low voltages.
- Stylish yet comfortable handle design helps the user to operate it easily and conveniently.
- It can decode up to 300 barcodes per second, thanks to its 32-bit ARM microprocessor.
- It supports all Raspberry Pi Operating Systems and can read barcodes of different standard types.
- A built-in memory chip will store all the data decoded by maintaining data integrity.
So, here I have listed the top Raspberry Pi barcode scanners and also provided a quick how-to guide for setting up the Python barcode scanner on Raspberry Pi.
What do you think about it? Will you make a DIY Raspberry Pi 3 barcode scanner at your home? For which purpose (experiment/commercial) you will do it? Let people know about it through the comment section below.